Skip to content

Unable to interact with pickled 3D plot #10843

Closed

Description

@spokeydokeys

Bug report

A 3D line plot is created and pickled for reloading later. Loading the plot later results in a plot that cannot be interacted with.

Code for reproduction

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import pickle as pk
import numpy as np

plt.ioff()

t = np.linspace(0, 6*np.pi, 1000)
x = np.sin(t)
y = np.cos(t)
z = t/100

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(x, y, z, label='3d plot')

fo = open('test_file.pkl', 'wb')
pk.dump(fig, fo)
fo.close()

In a different python instance

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import pickle as pk

plt.ioff()

fi = open('test_file.pkl', 'rb')
fig = pk.load(fi)
fi.close()

fig.show()

The figure is shown, but cannot be interacted with.

Expected outcome
The figure would be shown and the plot could be interacted with to show a different view.

Matplotlib version

  • Operating system: Win7
  • Matplotlib version: 2.1.2
  • Matplotlib backend: Qt5Agg
  • Python version: 3.6.4
  • Jupyter version (if applicable): N/A
  • Other libraries: iPython 6.2.1, Spyder 3.2.6

matplotlib installed by Anaconda from default channel.

Activity

  1. jklymak commented on Mar 19, 2018

    @jklymak
    Member

    Pickling throws out lots of stuff - it can only do so much....

  2. WeatherGod commented on Mar 19, 2018

    @WeatherGod
    Member
  3. modified the milestones: , on Mar 19, 2018
  4. tacaswell commented on Mar 19, 2018

    @tacaswell
    Member

    picking throws away the event callbacks (because we can not in general pickle functions). I suspect the restore method just needs to be smart enough to also restore those.

  5. vikranthjv commented on Aug 5, 2019

    @vikranthjv

    Is there a solution to this issue? Can I save and restore interactive 3d plots in a different format other than pickle?

  6. tacaswell commented on Aug 5, 2019

    @tacaswell
    Member

    @vikranth94 No, I do not believe so, would you be interested it taking a look at how to restore the mouse events?

    Another route is to instead of saving a pickle, write a function that generates the figure you want and re-call it with your data to restore the figure.

  7. anntzer commented on Nov 17, 2019

    @anntzer
    Contributor

    I looked a bit into this and this is actually quite annoying to fix, basically because when the Axes3D is unpickled its parent figure does not have a manager and a canvas set yet (indeed, they are set later in the unpickling process depending on the current backend...), so we can't just have Axes3D.__setstate__ recreate the callbacks...

  8. removed this from the future releases milestone on Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions