Collection of axvspan

currently I create multiple (hundreds) axvspans in an axes by using a loop. Now I thought this would be more efficient using a collection. I searched the internet and found this topic
here from 2007 where someone tried to do the exact same. Unfortunately, I don’t understand the given answeres or I am not able to reproduce it. Also, as this topic is now already 15 years old, there may be a better way to achieve this collection of axvspans.

Can anyone please give me an example of how to do this?

Thanks and best regards,

You would do what is in the source of axvspan (matplotlib/ at dc0328fb9c1c8817b07a5121a106a06be3571433 · matplotlib/matplotlib · GitHub) and instead of adding the patch to the axes, you’d add it to a patch collection.