I am trying to handle a list of figures with an object. Unfortunately there seems to be a problem with plotting from a list of figures.
Please comment out the line in the example below and you see how the plotting breaks:
import matplotlib as mpl
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, FigureManagerQT
class Test:
def __init__(self):
self.figs = [mpl.figure.Figure(),mpl.figure.Figure()]
self.fig = mpl.figure.Figure()
ax = self.fig.subplots()
ax.plot([1,2],[3,4])
def show(self):
fig = self.fig # works
# fig = self.figs[0] # does not work
canvas = FigureCanvasQTAgg(fig)
figManager = FigureManagerQT(canvas, 0)
a=Test()
a.show()
In some other tests I found it might be connected with destructing the object. As a list is a mutable object, this might be the connection.
I also tried (unsuccessfully) several workarounds to copy the figure object for plotting:
I used something like fig = myCopy(self.figs[0])
in combination with a pickle-copy.
Can you please give me some explanation of what is happening and what might be a workaround?