自定义matplotlib图像显示以添加复制/粘贴

我想自定义matplotlib图像显示,以便我可以键入control-c,它会将图像复制到剪贴板,然后我可以将其复制到openoffice电子表格来组织我所有的原始数据和图像结果。 有没有办法做到这一点? 谢谢!

如果您使用wx后端, FigureCanvasWxAgg可以使用FigureCanvasWxAggCopy_to_Clipboard方法。 您可以绑定CTRL + C键事件来调用此方法。 有关示例,请参阅此示例代码 。

 import matplotlib import matplotlib.pyplot as plt if not globals().has_key('__figure'): __figure = matplotlib.pyplot.figure def on_key(event): print event if event.key=='c': #print event.canvas.__dict__#.Copy_to_Clipboard(event=event) # print event.canvas._tkphoto.__dict__ plt.savefig("/tmp/fig.png") def my_figure(): fig = __figure() fig.canvas.mpl_connect('key_press_event',on_key) return fig matplotlib.pyplot.figure = my_figure 

这适用于后端,但我不知道如何将图像复制到剪贴板。 对于文本,我可以使用xclip,但图像不工作! 由于某种原因,wx后端在ubuntu上工作得不好