Python 在google drive中保存plt子地块

Python 在google drive中保存plt子地块,python,matplotlib,Python,Matplotlib,我正在谷歌Colab上运行我的代码,我已经将我的文件上传到我的谷歌硬盘上。有关更多信息,我连接到我的google drive by: from google.colab import drive drive.mount('/content/gdrive') 我有一段代码用于显示任何时代的无花果。它很好地展示了无花果。我写的是: img_plt=imgs.cpu().numpy() true_masks_plt=true_masks.detach().cpu().numpy() masks_

我正在谷歌Colab上运行我的代码,我已经将我的文件上传到我的谷歌硬盘上。有关更多信息,我连接到我的google drive by:

from google.colab import drive
drive.mount('/content/gdrive')
我有一段代码用于显示任何时代的无花果。它很好地展示了无花果。我写的是:

img_plt=imgs.cpu().numpy()
true_masks_plt=true_masks.detach().cpu().numpy()  
masks_pred_plt=masks_pred.detach().cpu().numpy()  
input=np.squeeze(np.moveaxis(img_plt,1,-1))
gt=np.squeeze(np.moveaxis(true_masks_plt,1,-1))
pd=np.squeeze(np.moveaxis(masks_pred_plt,1,-1))
_,figs=plt.subplots(1,3,figsize=[15,5])
figs[0].imshow(input[0])
figs[1].imshow(pd[0])
figs[2].imshow(gt[0])

figs[0].set_title(f'input image ')
figs[1].set_title(f'mask prediction')
figs[2].set_title(f'true mask')
plt.show()

现在,我想把这三张图片保存在我的谷歌硬盘上。我应该怎么做?

在plt.show之前添加:

plt.savefig(“gdrive/MyDrive/name\u of\u plot.png”)

这将在Google驱动器的根目录中以png格式存储绘图


如果需要,可以指定另一个目录,如:


plt.savefig(“gdrive/MyDrive/path/to/dir/name\u of_plot.png”)

希望此资源能够澄清,如果将它们存储为3个单独的文件,或者存储为包含所有3个子包的一个文件,这有什么关系?@MikeXydas,无论我们将它们存储为单独的文件还是子包。