3

When I run my code from the shell command line, it opens the figure window and displays the plot but as soon as the code is completed it closes it. I do not have any close() statements.

How can I prevent figures from closing when running a python script from the command line with ipython?

I could add a statement at the end to quit only after pressing any key, but that feels too much like a hack.

2
  • Are you running within ipython, as in In [n]: run script or on the shell command line using ipython, as in $ ipython script.py? Commented Nov 14, 2013 at 0:28
  • In the shell. I will clarify in the question. Commented Nov 14, 2013 at 0:52

2 Answers 2

4

I discovered that I needed to use plt.show() rather than plt.draw().

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

Comments

0

I like to use

plt.draw()
plt.pause(0.01)
input("<Hit Enter To Close>")

so that I can close the plot from the command line, rather than having to click.

1 Comment

I didn't expect to find you here, Mr Tumnus.

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.