Antje Janosch
Antje Janosch

Reputation: 1196

save python plot with matplotlib fails under windows

I would like to save a python plot. With MacOS everything runs smoothly but it fails under Windows7.

The python-command looks like this:

savefig('C:\Users\xyz\AppData\Local\Temp\pyplot1468046843481608342.png')

The error messge is this one:

Traceback (most recent call last):
File "C:\Users\xyz\AppData\Local\Temp\analyze3744796441786382480.py", line 340, in <module>
savefig('C:\Users\xyz\AppData\Local\Temp\pyplot1468046843481608342.png')
File "C:\Anaconda\lib\site-packages\matplotlib\pyplot.py", line 577, in savefig
res = fig.savefig(*args, **kwargs)
File "C:\Anaconda\lib\site-packages\matplotlib\figure.py", line 1470, in savefig
self.canvas.print_figure(*args, **kwargs)
File "C:\Anaconda\lib\site-packages\matplotlib\backend_bases.py", line 2194, in print_figure
**kwargs)
File "C:\Anaconda\lib\site-packages\matplotlib\backends\backend_agg.py", line 526, in print_png
filename_or_obj = open(filename_or_obj, 'wb')
IOError: [Errno 22] invalid mode ('wb') or filename: 'C:\\Users\xyz\\AppData\\Local\\Temp\\pyplot1468046843481608342.png'

This is the Python I'm using:

Python 2.7.8 :: Anaconda 2.1.0 (32-bit)

Can anybody explain the cause of the problem?

Upvotes: 2

Views: 4131

Answers (1)

GioR
GioR

Reputation: 636

I think you have to add r before your directory to convert your string into raw string. See this post

Unknown python expression filename=r'/path/to/file'

Upvotes: 3

Related Questions