Search code examples
google-cloud-platformgoogle-cloud-storagegoogle-cloud-datalab

Google Cloud DataLab Notebook Save PNG


I am using DataLab to create several dataframes and subsequent figures. I would like to save these figures to either my computer hard drive or to my Google Cloud Storage.

Normally, I would do the following (I am going through a loop so df.name changes for each graph):

os.chdir('C:\\Documents\\Analysis\\')
ax_plot.figure.savefig(titles[df.name] + ".png",bbox_inches='tight')

Is there a way to do something similar within DataLab?

Thanks for the help!


Solution

  • Copying to your computer:

    You can use gcloud compute copy-files to copy the files from your Datalab VM to your computer.

    Copying to GCS: The Datalab VM has gsutil installed by default, so you can do something like gsutil cp <localfile> <gs path>.

    If you would like to do this programmatically, you can take a look at this sample notebook that shows how to use the built-in GCS APIs.