Setting matplotlib image display to add copy / paste

I would like to adjust the display of the matplotlib image so that I can type control-c and it will copy the image to the clipboard so that I can then copy it to the openoffice spreadsheet to organize all of my original data and image results. Is there any way to do this? Thank!

+3
source share
2 answers

If you use a wx server, it FigureCanvasWxAgghas a method Copy_to_Clipboardthat you can use. You can bind the CTRL + C key event to call this method. For example, see this sample code .

+4
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

tk, , . xclip, ! - wx- ubuntu...

+2

Source: https://habr.com/ru/post/1761624/