I have several plt.plot instances and I wanted to only plt.show() certain objects. To illustrate here is some code:
import matplotlib.pyplot as plt
ax1 = plt.plot(range(5),range(5))
ax2 = plt.plot([x+1 for x in range(5)],[x+1 for x in range(5)])
ax3 = plt.plot([x+2 for x in range(5)],[x+2 for x in range(5)])
#plt.show([ax1,ax2])
plt.show()
So I would like something like the commented out statement, to display only ax1 & ax2 in the example figure.
You can remove some of the plotted lines from the set of lines of the current axes:
If you want to put it back, you can similarly do
You could alternatively save the current graph lines, if you need to put them back later:
The key point is that each
plot()command adds a line to the current axes and draws it (in interactive mode). So you can either remove already plotted lines (like in this answer).As Yann pointed out, you can also make some lines invisible. However, the method from this answer is probably faster, since there are fewer lines to be drawn (if this matters).