| 1 | [Bug]: Unable to pickle figure with draggable legend |
| 2 | ### Bug summary |
| 3 | |
| 4 | I am unable to pickle figure with draggable legend. Same error comes for draggable annotations. |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | ### Code for reproduction |
| 11 | |
| 12 | ```python |
| 13 | import matplotlib.pyplot as plt |
| 14 | import pickle |
| 15 | |
| 16 | fig = plt.figure() |
| 17 | ax = fig.add_subplot(111) |
| 18 | |
| 19 | time=[0,1,2,3,4] |
| 20 | speed=[40,43,45,47,48] |
| 21 | |
| 22 | ax.plot(time,speed,label="speed") |
| 23 | |
| 24 | leg=ax.legend() |
| 25 | leg.set_draggable(True) #pickling works after removing this line |
| 26 | |
| 27 | pickle.dumps(fig) |
| 28 | plt.show() |
| 29 | ``` |
| 30 | |
| 31 | |
| 32 | ### Actual outcome |
| 33 | |
| 34 | `TypeError: cannot pickle 'FigureCanvasQTAgg' object` |
| 35 | |
| 36 | ### Expected outcome |
| 37 | |
| 38 | Pickling successful |
| 39 | |
| 40 | ### Additional information |
| 41 | |
| 42 | _No response_ |
| 43 | |
| 44 | ### Operating system |
| 45 | |
| 46 | Windows 10 |
| 47 | |
| 48 | ### Matplotlib Version |
| 49 | |
| 50 | 3.7.0 |
| 51 | |
| 52 | ### Matplotlib Backend |
| 53 | |
| 54 | _No response_ |
| 55 | |
| 56 | ### Python version |
| 57 | |
| 58 | 3.10 |
| 59 | |
| 60 | ### Jupyter version |
| 61 | |
| 62 | _No response_ |
| 63 | |
| 64 | ### Installation |
| 65 | |
| 66 | pip |