Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Milestone
Description
Bug report
Bug summary
I was trying to follow the first suggestion ofthis post, and copy a figure using pickle. In my example however, this results in anAttributeError: 'Figure' object has no attribute '_cachedRenderer'
.
Code for reproduction
importioimportpickleimportnumpyasnpfromcopyimportcopy,deepcopyfromcontextlibimportcontextmanagerimportmatplotlib.pyplotasplt@contextmanagerdefcopy_figure(fig:plt.Figure):buf=io.BytesIO()pickle.dump(fig,buf)buf.seek(0)fig_copy=pickle.load(buf)# fig_copy = copy(fig) # you get the same error when using copy instead# fig_copy = deepcopy(fig) # this results in an "NotImplementedError:# TransformNode instances can not be copied. Consider using frozen()# instead." which I have no idea what that means either.yieldfig_copyplt.close(fig_copy)defexample():image=np.random.uniform(0,1, (100,100))fig,ax=plt.subplots()image_artist=ax.imshow(image)fig.colorbar(image_artist)withcopy_figure(fig)ascopy_fig:copy_fig.show()fig.show()example()
I am not sure if this is wanted behaviour, and why this even happens, but if it is not supposed to happen, I guess it would be a simple fix to change this line intight_layout.get_renderer
if fig._cachedRenderer:
to this line:
if hasattr(fig, '_cachedRenderer') and fig._cachedRenderer:
Matplotlib version
- Operating system: Windows 10 Home 64bit
- Matplotlib version: 3.1.3 (via Anaconda)
- Matplotlib backend: backend_interagg
- Python version: 3.7.7
Metadata
Metadata
Assignees
Labels
No labels