FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Pickled Figure Loses sharedx Properties · Issue #4827 · matplotlib/matplotlib · GitHub

Repository navigation

Pickled Figure Loses sharedx Properties #4827

Closed

Description

I am storing pickled Figures for plotting at later time but for some reason the sharedx property keeps getting lost on the 2nd (unpickled) figure. Execute the code below for a quick example. Is there a way to reset the shared x property? There is PR 1312 that talks about a potential unshare_x_axes function but there doesn't really appear to be a setting function either. This may actually be two problems though since the pickle should also maintain the sharedx property.

#!/usr/bin/env python
import cPickle as pickle
import matplotlib.pyplot as plt
import numpy as np

# Simple data to display in various forms
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)

f, axarr = plt.subplots(2, sharex=True)
axarr[0].plot(x, y)
axarr[0].set_title('Sharing X axis')
axarr[1].scatter(x, y)

pickle.dump(f,open('test.pickle','wb'))

new_plot = pickle.load(open('test.pickle','rb'))
new_plot.canvas.draw()

plt.show()

Activity

  1. changed the title [-]Pickled Figure Loses sharedx and sharedy Properties[/-] [+]Pickled Figure Loses sharedx Properties[/+] on Jul 30, 2015
  2. freidrichen commented on Mar 2, 2016

    I'm also affected by this issue. Any progress or good workarounds?

  3. added this to the milestone on Mar 2, 2016
  4. tacaswell commented on Mar 2, 2016

    Member

    Sharex is implemented by holding a reference to the other Axes/Axis objects (I do not recall which off the top of my head). There obviously do not survive round tripping. The way to fix this would be to work on__setstate__ / __getstate__ of the Axes object to replace the Grouper data structure with a list of uids, to make sure that all of the Axes objects have those uids assigned to them, and then at the end of __getstate__ in Figure replace the uids back. To make this more fun, the Grouper objects are actually class-level attributes.

    We do not officially encourage using pickle objects to serialize figures, the 'official' way is the function that you used to generate the figure.

  5. spaceluigi commented on Apr 12, 2016

    Author

    I implemented a work around by pickling a custom python dictionary stuffed
    with the plotting data and other plot info, e.g. title,xLabel,yLabel,
    etc,. Then used custom plotting function that accepted the dictionary
    object and re-created the plot.

    On Wed, Mar 2, 2016, 2:19 PM Thomas A Caswell notifications@github.com
    wrote:

    Sharex is implemented by holding a reference to the other Axes/Axis
    objects (I do not recall which off the top of my head). There obviously do
    not survive round tripping. The way to fix this would be to work on
    setstate / getstate of the Axes object to replace the Grouper
    data structure with a list of uids, to make sure that all of the Axes
    objects have those uids assigned to them, and then at the end of
    getstate in Figure replace the uids back. To make this more fun,
    the Grouper objects are actually class-level attributes.

    We do not officially encourage using pickle objects to serialize figures,
    the 'official' way is the function that you used to generate the figure.

    —
    Reply to this email directly or view it on GitHub
    #4827 (comment)
    .

  6. tacaswell commented on Apr 12, 2016

    Member

    @lugi5720 That is a preferred way

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


      Back | FazBrowse Home | New Git URL