Specify savefig path with pylab or matplotlib

I am struggling to find the right way to specify the save path (or repository) when calling the savefig function in matplotlib or pylab.

I tried several syntaxes, but each time the python console returns:

FileNotFoundError: [Errno 2] There is no such file or directory: '../MyDocs/resource/frames/MyImage.png'

Currently, I have written the following:

pylab.savefig('../MyDocs/resource/frames/MyImage.png') 

Does anyone know how to do this?

Thanks in advance!

+5
source share
1 answer

The tilde operator and the $HOME variable are entered as strings and therefore do not work when saved. You must specify either a relative path (as you did) or provide a full path. For instance. pylab.savefig("/home/username/Desktop/myfig.png") .

+4
source

Source: https://habr.com/ru/post/1216621/


All Articles