Customizing matplotlib image display to add copy/paste
I would like to customize matplotlib image display so that i can type control-c and it will copy the image to the cli开发者_运维问答pboard so then i can copy it to openoffice spreadsheet to organize all of my raw data and image results. Is there any way to do this? Thanks!
If you're using the wx backend, FigureCanvasWxAgg
has a Copy_to_Clipboard
method you can use. You could bind the CTRL+C key event to call this method. For an example, see this sample code.
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
This works for tk backend, but i have no clue how to copy an image to a clipboard. For text, i can use xclip, but images dont work! And for some reason the wx backend doesnt work too well on ubuntu...
精彩评论