Home > Back-end >  How to get a list of all objects present on the matplotlib axes
How to get a list of all objects present on the matplotlib axes

Time:05-08

How can I get a list of all objects (ploted data, vertical lines, horizontal lines, points, etc.) that are present on matplotlib axes? If there's no easy way of getting all of them inside a single list then how can I get this kind of list containing only vertical lines?

CodePudding user response:

You can get all artists (plotted objects) with ax.get_children(). If you only care about lines, you can use ax.get_lines(). This good answer has more details.

To select vertical lines only you can just just check their x coordinates.

vertical_lines = [l for l in ax.get_lines() if l.get_xdata()[0] == l.get_xdata()[1]]
  • Related