Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AttributeError: 'Figure' object has no attribute '_cachedRenderer' #17627

Closed
Milestone
@mapfiable

Description

@mapfiable

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp