6

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.

5
  • 1
    Post your screenshot to an image hosting service, and someone will add it to your question for you. Commented Apr 30, 2015 at 1:00
  • 1
    What backend are you using? Commented Apr 30, 2015 at 3:32
  • I have the same problem. Do you know any solution by now? Commented May 13, 2016 at 9:05
  • @HighwayJohn Still no. Save as figure1 each time Commented Jun 22, 2016 at 12:54
  • Darn, I do it the same way.. Commented Jun 27, 2016 at 22:03

4 Answers 4

7

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

Try this. I don't know if you're using pyplot, but it's pretty common. Make sure you don't show() the figure anywhere in the code--it prevents the savefig() function from working. This worked for me, and saved myfigure.png in the directory I ran the code in.

import matplotlib.pyplot as plt

# make a figure with 1 row and 1 column
fig, myplot = plt.subplots( nrows=1, ncols =1)

# simple plot
t = arange(0.0,2.0,0.01)
s = sin(2*pi*t)
myplot = plot(t,s)

# save figure with specified filename
plt.savefig('myfigure.png')

# close figure
plt.close(fig)

1 Comment

Thank you. I know that. But I aim to show the picture, before saving (manually), instead for some specific reason.
0

For some, this discussion might answer the issue: https://matplotlib.org/faq/osx_framework.html

Without a framework build of Python, matplotlib doesn't function properly on OS X. Anaconda doesn't provide a framework build, hence the problem... although I don't remember this being a problem until fairly recently!

Despite using Python 3, I can't actually make the virtual environment fix suggested in the link work for me, however.

1 Comment

An answer should stand on its own. If your answer is a link, post it as a comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.