如何将Matplotlib中的子图复制到系统剪贴板?
如何在Matplotlib中将指定子图复制到剪贴板?
在Matplotlib中,我们可以通过以下代码将整个图像复制到系统剪贴板:
def Copy_to_Clipboard(self, event=None): """Copy bitmap of canvas to system clipboard.""" bmp_obj = wx.BitmapDataObject() bmp_obj.SetBitmap(self.bitmap) if not wx.TheClipboard.IsOpened(): open_success = wx.TheClipboard.Open() if open_success: wx.TheClipboard.SetData(bmp_obj) wx.TheClipboard.Flush() wx.TheClipboard.Close()
但目前我需要实现复制指定子图到剪贴板的功能,比如复制示例代码中ax2对应的子图。我已经查看了Axes类的相关方法,也做了搜索,但没找到有效解决方案,想请教实现方法。
示例代码:
fig = plt.figure() gs0 = fig.add_gridspec(3, 1) ax1 = fig.add_subplot(gs0[0]) ax2 = fig.add_subplot(gs0[1]) ax3 = fig.add_subplot(gs0[2]) ...
内容的提问来源于stack exchange,提问作者Tianzhu
相关产品推荐
相关产品推荐

