【问题标题】:saving plt subplot in google drive [duplicate]在谷歌驱动器中保存 plt 子图 [重复]
【发布时间】:2021-05-15 08:51:14
【问题描述】:

我正在 Google Colab 上运行我的代码,我已将我的文件上传到我的 Google 驱动器上。有关更多信息,我通过以下方式连接到我的 Google Drive:

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()

现在,我想将这三张图片保存在我的谷歌驱动器上。我该怎么做?

【问题讨论】:

  • 希望这个资源能澄清colab.research.google.com/notebooks/…
  • 将它们存储为 3 个单独的文件 还是作为包含所有 3 个子图的 一个文件 是否重要?
  • @MikeXydas 无论我们将它们存储为单独的文件还是子图。

标签: python matplotlib


【解决方案1】:

之前plt.show添加:

plt.savefig("gdrive/MyDrive/name_of_plot.png")

这会将您的绘图以 png 格式存储在您的 Google Drive 的根目录中。


如果您愿意,可以指定另一个目录,例如:

plt.savefig("gdrive/MyDrive/path/to/dir/name_of_plot.png")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-30
    • 2021-07-07
    • 2021-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多