Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: figure with subfigures cannot be pickled #28464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PerfectNewbie opened this issue Jun 26, 2024 · 1 comment · Fixed by #28465
Closed

[Bug]: figure with subfigures cannot be pickled #28464

PerfectNewbie opened this issue Jun 26, 2024 · 1 comment · Fixed by #28465
Milestone

Comments

@PerfectNewbie
Copy link

PerfectNewbie commented Jun 26, 2024

Bug summary

I tried to pickle figures with subfigures nested.
Returns error with the following code.

Code for reproduction

#!/usr/bin/env python3
import pickle
import matplotlib.pyplot as plt

fig = plt.figure()
subfigs = fig.subfigures(2,2)
with open('fig.p', 'wb') as file:
    pickle.dump(fig, file)

Actual outcome

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 8
      6 subfigs = fig.subfigures(2,2)
      7 with open('fig.p', 'wb') as file:
----> 8     pickle.dump(fig, file)

TypeError: cannot pickle 'FigureCanvasQTAgg' object

Expected outcome

A pickle file should be saved to the working directory.

Additional information

I know the API is still provisional but I couldn't find other reports so I decided to post.
I believe this is caused by the "subfigures" API, as skipping that line makes the script work.
It's my first time to report a issue, so I'm a bit worried if I'm doing things right.

Operating system

Windows 10

Matplotlib Version

3.9.0

Matplotlib Backend

qtagg

Python version

3.12.1

Jupyter version

No response

Installation

pip

@tacaswell tacaswell added this to the v3.9.1 milestone Jun 26, 2024
@tacaswell
Copy link
Member

Thank you @PerfectNewbie ! This is just about an ideal bug report (includes a minimal reproducer, all the version information, and the traceback).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants