Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to modify file name when saving matplotlib figures in Mac system

After executing the show() command in Python, I can only save figures as figure_1.png I cannot change my file name. No typing is allowed next to "Save As:". How to enable typing my filename at this point?

I apologize that I need at least 10 reputations to post screenshot.

like image 721
Ka-Wa Yip Avatar asked Apr 29 '15 23:04

Ka-Wa Yip


2 Answers

I had exactly the same issue with mine, I found the answer in solving an underlying issue with the matplotlib backend (the default backend "macosx" causes this issue). The solution is to change the backend line in your matplotlibrc file, which you can find by running

import matplotlib
matplotlib.matplotlib_fname()

in a python terminal. In the matplotlibrc file, find and change the line

backend      : macosx

to (for example):

backend      : TkAgg

All of the issues should go away. It worked for me, I hope it's helpful.

like image 53
esuo Avatar answered Nov 15 '22 00:11

esuo


Just found a solution for this:

Use conda install python.app to install pythonw.

Then use pythonw instead of python in your terminal.

E.g.

pythonw my_plot.py

Hope this helps

like image 44
seralouk Avatar answered Nov 15 '22 00:11

seralouk