You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AttributeError: 'Figure' object has no attribute '_cachedRenderer' #17627
I was trying to follow the first suggestion of this post, and copy a figure using pickle. In my example however, this results in an AttributeError: '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 in tight_layout.get_renderer
if fig._cachedRenderer:
to this line:
if hasattr(fig, '_cachedRenderer') and fig._cachedRenderer:
Activity
d-o0o-b commentedon May 21, 2021
The crux of the matter is that you used "pickle"
mapfiable commentedon May 21, 2021
I don't understand. What do you mean?