control-c と入力して画像をクリップボードにコピーできるように、matplotlib の画像表示をカスタマイズしたいと考えています。これを行う方法はありますか?ありがとう!
2783 次
2 に答える
5
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.
于 2010-08-26T00:46:53.483 に答える
2
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 でうまく機能しません...
于 2010-08-26T02:47:59.260 に答える