English 中文(简体)
与Memcache(Wont Pickle)相配
原标题:Caching Matplotlib with Memcache (Wont Pickle)

我的图表为3秒,然后从上述图表中添加内容。 我想从主要图表中收集轴心,以便我能够检索,并在提交分图时加以修改。 我怎么能够接过这一错误?

这里的样本测试代码:

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)

造成以下错误:

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

我能否做到这一点?

最佳回答

会上讨论了能否将校正数据编成序列的问题。 我看不出任何报道都提到这个问题,甚至被接纳为目标。 因此,如果你试图将电线上电离层,显然会失败。 我在搜索时发现的讨论表明,目前使用的配对物设计很容易满足这一目标,这就要求内部进行重组。 参考:rel=“nofollow”http://old.nabble.com/matplotlib-figure-serialization-td28016714.html

为了大幅缩短执行时间,你可以做的是,将你的数据重新整理成数据集,只读到ax.bar(<>)。 然后,数据集可以按你想要的任何格式(例如,以超标方式)加以分类和储存。

这里是显示你的做法与将这种做法合并成数据集的守则实例。 如果你想要的话,你可以更容易地看到:

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()

成果:

python plot.py 
test1 - Sec: 1.592, ms: 1592
test2 - Sec: 0.358, ms: 357
问题回答

至于配对1.2,你应当能够收集数字和数据。

This is very much an "experimental" feature, but if you do find any issues, please let us know on the mpl mailing list or by raising an issue on github.com/matplotlib/matplotlib

HTH

查阅documentation,看来fig.add_axes() 取道,作为理由,请通过名单。 因此,它不退回<代码>Axes>的物体(因为其不是制造的),因此,其功能本身被分配。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签