尝试使用 matplotlib 写入 iostream,然后在另一个 matplotlib 图中显示该数据(从以下开始:将 Matplotlib savefig 写入 html)。为了提高效率,我想避免将图像写入磁盘。
这是代码:
import cStringIO
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt2
import matplotlib.image as mpimg
sio = cStringIO.StringIO()
plt.savefig(sio, format='png')
# I should mention at this point here that the sio object is sent through a
# pipe between two processes (so it has been pickled)
imgplt = plt2.imshow(mpimg.imread(sio.getvalue().encode("base64").strip()))
# this line generates the following error. As well as several variations
# including specifying 'png'
返回的错误是:IOError: [Errno 22] invalid mode ('rb') or filename: 'iVBORw...followed by a long string with the data from the image'
我查看了 image.py 文件,它似乎正在寻找文件名。
谢谢参观。