Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8898941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:44:22+00:00 2026-06-15T00:44:22+00:00

You may already know, that in matplotlib 1.2.0 there is a new experimental feature,

  • 0

You may already know, that in matplotlib 1.2.0 there is a new experimental feature, that figures are pickable (they can be saved with pickle module).

However, it doesn’t work when one uses logscale, eg.

import matplotlib.pyplot as plt
import numpy as np
import pickle
ax = plt.subplot(111)
x = np.linspace(0, 10)
y = np.exp(x)
plt.plot(x, y)
ax.set_yscale('log')
pickle.dump(ax, file('myplot.pickle', 'w'))

results in:

PicklingError: Can't pickle <class 'matplotlib.scale.Log10Transform'>: attribute lookup matplotlib.scale.Log10Transform failed

Anybody knows any solution/workaround to this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:44:22+00:00Added an answer on June 15, 2026 at 12:44 am

    I’ve opened this as a bug report on matplotlib’s github issue tracker. Its a fairly easy fix to implement on the matplotlib repository side (simply don’t nest the Log10Transform class inside the LogScale class), but that doesn’t really help you in being able to use this with mpl 1.2.0…

    There is a solution to getting this to work for you in 1.2.0, but I warn you – its not pretty!

    Based on my answer to a pickling question it is possible to pickle nested classes (as Log10Transform is). All we need to do is to tell Log10Transform how to “reduce” itself:

    import matplotlib.scale
    
    class _NestedClassGetter(object):
        """
        When called with the containing class as the first argument, 
        the name of the nested class as the second argument,
        and the state of the object as the third argument,
        returns an instance of the nested class.
    
        """
        def __call__(self, containing_class, class_name, state):
            nested_class = getattr(containing_class, class_name)
            # return an instance of a nested_class. Some more intelligence could be
            # applied for class construction if necessary.
            c = nested_class.__new__(nested_class)
            c.__setstate__(state)
            return c
    
    def _reduce(self):
        # return a class which can return this class when called with the 
        # appropriate tuple of arguments
        cls_name = matplotlib.scale.LogScale.Log10Transform.__name__
        call_args = (matplotlib.scale.LogScale, cls_name, self.__getstate__())
        return (_NestedClassGetter(), call_args)
    
    matplotlib.scale.LogScale.Log10Transform.__reduce__ = _reduce 
    

    You might also decide to do this for other Log based transforms/classes, but for your example, you can now pickle (and successfully unpickle) your example figure:

    import matplotlib.pyplot as plt
    import numpy as np
    import pickle
    
    
    ax = plt.subplot(111)
    x = np.linspace(0, 10)
    y = np.exp(x)
    plt.plot(x, y)
    ax.set_yscale('log')
    
    pickle.dump(ax, file('myplot.pickle', 'w'))
    plt.savefig('pickle_log.pre.png')
    plt.close()
    
    pickle.load(file('myplot.pickle', 'r'))
    plt.savefig('pickle_log.post.png')
    

    I’m going to get on and fix this for mpl 1.3.x so that this nasty workaround isn’t needed in the future 🙂 .

    HTH,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that there are similar questions which are already answered, but I am
As some of you may already know, there are some caching issues in Firefox/Chrome
Good afternoon, Many of you may already know that it is possible, for instance,
I know that this may seem as a question that was already asked, but
As many of you may already know I have been having issues with another
those of you who read my previous questions may already know this: I'm currently
What I would like to take ownership of a hid device that may already
I already know that mktime returns the number of seconds since the epoch (Jan
So as many of you may already know, CommonCrypto isn't included in the iPhone
I know that when you're first instantiating a fragment you can pass arguments using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.