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

Skip to content

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

Closed
@PerfectNewbie

Description

@PerfectNewbie

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

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