简体   繁体   English

酸洗Matplotlib情节提升PicklingError:不能腌制'RendererAgg'对象

[英]Pickling Matplotlib plot raising PicklingError: Can't pickle 'RendererAgg' object

I have a program that creates plots - sometimes line plots, sometimes NonUniformImages - using matplotlib. 我有一个程序,使用matplotlib创建绘图 - 有时是线图,有时是NonUniformImages。 I'd like to be able to pickle the plots to reopen them at a later time without going through the whole creation process again. 我希望能够在以后重新打开这些情节,而无需再次完成整个创作过程。 For whatever reason, it keeps throwing a PicklingError: Can't pickle 'RendererAgg' object . 无论出于何种原因,它不断抛出一个PicklingError: Can't pickle 'RendererAgg' object I've tried using both import dill as pickle and import pickle , as well as all 4 different pickling options but no change. 我尝试使用import dill as pickleimport pickle ,以及所有4种不同的酸洗选项,但没有变化。

The axes are defined here: 轴在此处定义:

class Imaging:
    def function:
        ax1 = plt.subplot(2,1,1)
        ax2 = plt.subplot(2,1,2)

And set here: (Imaging.figureProperties is a list and is meant to hold multiple [ax1,ax2] objects. Also in the same function as where ax1 and ax2 are defined.) 并在此处设置:( Imaging.figureProperties是一个列表,用于保存多个[ax1,ax2]对象。也与定义ax1ax2函数相同。)

Imaging.figureProperties.append([ax1,ax2])

Finally, data is pickled here ( i is chosen by the user, but it will be within the list): 最后,数据在这里被腌制( i是由用户选择的,但它将在列表中):

class2:
    with open(filename, 'wb') as f:
        pickle.dump(Imaging.figureProperties[i-1],f)

I have no problem running the sample code from this question (with some slight changes such as opening in 'wb' instead of just 'w' ), as long as I use import dill as pickle . 只要我使用import dill as pickle ,我就可以从这个问题中运行示例代码没有问题(只有一些细微的变化,比如在'wb'而不是'w'打开)。 If I use the standard import pickle it throws the same PicklingError . 如果我使用标准的import pickle它会抛出相同的PicklingError What is going on here? 这里发生了什么?

I'm the dill author. 我是dill作者。 If you edit your question to provide code that can be tested, I could better test your code. 如果您编辑问题以提供可以测试的代码,我可以更好地测试您的代码。 I think it might be that you just have typos in your code above -- it should be def function(self): . 我想可能是你上面的代码中只有错别字 - 它应该是def function(self): Also what is class2: ? 什么是class2: I'll just cut to the chase and serialize the thing you are trying to serialize. 我只是切入追逐并序列化你要序列化的东西。 Your code as posted doesn't really make sense. 您发布的代码实际上没有意义。

>>> import matplotlib.pyplot as plt
>>> 
>>> class Imaging:
...   def function(self):
...     ax1 = plt.subplot(2,1,1)
...     ax2 = plt.subplot(2,1,2)
... 
>>> Imaging.figureProperties = []
>>> 
>>> import dill
>>>                                     
>>> ax1 = plt.subplot(2,1,1)
>>> ax2 = plt.subplot(2,1,2)
>>> Imaging.figureProperties.append([ax1, ax2])
>>> fp = dill.loads(dill.dumps(Imaging.figureProperties[0]))
>>> fp   
[<matplotlib.axes._subplots.AxesSubplot object at 0x113085320>, <matplotlib.axes._subplots.AxesSubplot object at 0x113471eb8>]

The class you are using is pretty pointless as you are using it, however the code you are asking to serialize does serialize. 当您使用它时,您正在使用的类是毫无意义的,但是您要求序列化的代码会进行序列化。

将Matplotlib更新为1.4.2解决了这些问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 pickle.PicklingError: Can't pickle: 它与 object 不同 - pickle.PicklingError: Can't pickle: it's not the same object as 多处理酸洗错误:_pickle.PicklingError:不能酸洗<function myProcess at 0x02B2D420> :它与 __main__.myProcess 不是同一个对象 - multiprocessing pickling error: _pickle.PicklingError: Can't pickle <function myProcess at 0x02B2D420>: it's not the same object as __main__.myProcess _pickle.PicklingError:无法序列化对象:TypeError:无法腌制_thread.RLock对象 - _pickle.PicklingError: Could not serialize object: TypeError: can't pickle _thread.RLock objects pickle.PicklingError:使用mapPartitions登录闭包(函数)时,无法腌制“锁定”对象 - pickle.PicklingError: Can't pickle 'lock' object while logging in closure(function) with mapPartitions 酸洗错误:不能泡菜<type 'function'> - Pickling error: Can't pickle <type 'function'> pickle.PicklingError:无法腌制&#39;_subprocess_handle&#39;对象:&lt;_subprocess_han dle对象位于0x00AAAAAAA&gt; - pickle.PicklingError: Can't pickle '_subprocess_handle' object: <_subprocess_han dle object at 0x00AAAAAAA> PySpark:PicklingError:无法序列化对象:TypeError:无法pickle CompiledFFI对象 - PySpark: PicklingError: Could not serialize object: TypeError: can't pickle CompiledFFI objects PicklingError: 不能腌制<class 'decimal.decimal'> :它与十进制的 object 不同。十进制</class> - PicklingError: Can't pickle <class 'decimal.Decimal'>: it's not the same object as decimal.Decimal PicklingError:不能泡菜 <type 'function'> 与python进程池执行程序 - PicklingError: Can't pickle <type 'function'> with python process pool executor Python 多处理酸洗错误:无法酸洗<type 'function'></type> - Python multiprocessing PicklingError: Can't pickle <type 'function'>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM