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 7908409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:55:26+00:00 2026-06-03T11:55:26+00:00

I have a chart that is rendered takes 3 seconds and then subcharts that

  • 0

I have a chart that is rendered takes 3 seconds and then subcharts that can be made from said chart where things are added to it. I want to cache the axes from the main chart so that I can retrieve it and modify it later when rendering the subcharts. How can I get past this error?

Heres a sample test code:

import pylibmc
cache = pylibmc.Client(["127.0.0.1"], binary=True, behaviors={"tcp_nodelay": True, "ketama": True})
import matplotlib.pyplot as plt


cache_name = 'test'
fig = plt.figure(figsize=(20, 7))
ax = fig.add_axes([0, 0.15, 0.98, 0.85])
cache.set(cache_name, ax, 300)

Which gives the following error:

cPickle.PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

Is there anyway I could get this to work?

  • 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-03T11:55:28+00:00Added an answer on June 3, 2026 at 11:55 am

    There are discussion out there regarding the desire for matplotlib figures to be able to be serialized. I haven’t seen anything that reports this has been addressed or even accepted as a goal. So if you try to send them over the wire to memcached, its obviously going to fail. The discussions that I have found when searching suggest that the current design of matplotlib doesn’t cater to this goal easily, and it would require a refactor of the internals. Reference: http://old.nabble.com/matplotlib-figure-serialization-td28016714.html

    What you could do, to dramatically reduce your execution time, is to reorganize your data into a dataset, and only call ax.bar() once. The dataset can then be serialized and stored in whatever format you want (into memcached for instance).

    Here is a code example showing the test between your approach, and one that combines them into a dataset. You can view it here more easily if you want: https://gist.github.com/2597804

    import matplotlib.pyplot as plt
    from random import randint 
    from time import time 
    
    DATA = [
        (i, randint(5,30), randint(5,30), randint(30,35), randint(1,5)) \
        for i in xrange(1, 401)
    ]
    
    def mapValues(group):
        ind, open_, close, high, low = group
        if open_ > close: # if open is higher then close
            height = open_ - close # heigth is drawn at bottom+height
            bottom = close
            yerr = (open_ - low, high - open_)
            color = 'r' # plot as a white barr
        else:
            height = close - open_ # heigth is drawn at bottom+height
            bottom = open_
            yerr = (close - low, high - close)
            color = 'g' # plot as a black bar
    
        return (ind, height, bottom, yerr, color)
    
    #
    # Test 1
    #
    def test1():
        fig = plt.figure()
        ax = fig.add_subplot(111)
    
        data = map(mapValues, DATA)
    
        start = time()
    
        for group in data: 
    
            ind, height, bottom, yerr, color = group
    
            ax.bar(left=ind, height=height, bottom=bottom, yerr=zip(yerr), 
                    color=color, ecolor='k', zorder=10,
                    error_kw={'barsabove': False, 'zorder': 0, 'capsize': 0}, 
                    alpha=1)
    
        return time()-start
    
    #
    # Test 2
    #
    def test2():
        fig = plt.figure()
        ax = fig.add_subplot(111)
    
        # plotData can be serialized
        plotData = zip(*map(mapValues, DATA))
    
        ind, height, bottom, yerr, color = plotData
    
        start = time()
    
        ax.bar(left=ind, height=height, bottom=bottom, yerr=zip(*yerr), 
                color=color, ecolor='k', zorder=10,
                error_kw={'barsabove': False, 'zorder': 0, 'capsize': 0}, 
                alpha=1)
    
        return time()-start
    
    
    def doTest(fn):
        end = fn()
        print "%s - Sec: %0.3f, ms: %0d" % (fn.__name__, end, end*1000)
    
    
    
    if __name__ == "__main__":
        doTest(test1)
        doTest(test2)
    
        # plt.show()
    

    Results:

    python plot.py 
    test1 - Sec: 1.592, ms: 1592
    test2 - Sec: 0.358, ms: 357
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a chart generated from Google Charts that can be found here: Chart
I have a line chart that is updated every so and so seconds, similar
I have a matplotlib code that generates a simple 2D chart. I want to
I have some chart rendering tasks that I want to cover with tests. I
I have a WPF Chart that I am dynamically binding a BarSeries to. I
I have a jqPlot pie chart that I am loading by reading an XML
I have chart.png with data in it that I would like to put a
I have a simple JSF line chart that uses PrimeFaces (via jqPlot) library: <p:lineChart
I have a chart (code to replicate will be below) that has two lines
I have a simple chart (albeit with a lot of data) that renders fine

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.