I am using a matplotlib figure embedded in a WxPython GUI to present some data. The content of the figure (data displayed) changes constantly in function of the buttons clicked, ...
The data are of two types.
1) contour lines
self.axes.contour(x_scale_map,y_scale_map,matrix,cl,cmap=my_cmap,extent=0,matrix.shape[1]-1,0,matrix.shape[0]-1))
This is relatively slow to load (~1s), but does not change very often.
2) On top of this contour, I plot for instance some lines
self.axes.axhline(y,color='black')
These lines are obviously drawn instantly and change often in function of what the user clicks. In these situations, previously drawn lines need to disappear and new ones need to appear, while the contour map stays unchanged.
Now, my problem is as follows. I have not found a way to remove only the lines and not the contour. The only way to obtain the desired result seems to be doing:
self.axes.clear()
and then replot both the contour and the new lines. But as mentioned, reloading the contour each time is slow and thus annoying.
Is there a way to clear only the lines from the figure? I have tried to use superimposed subplots by doing something like:
self.axes1 = self.fig.add_subplot(111)
self.axes2 = self.fig.add_subplot(111)
self.axes1.contour(...)
self.axes2.axhline(y,color='black')
self.axes2.clear()
but this last line clears the entire figure.
Does anyone know how to achieve the desired functionality? Thanks