2

I have a Python script myscript.py which looks like this:

$ cat myscript.py
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 3, 2])

When running IPython in pylab mode:

$ ipython --pylab

Executing the following command (line 2 in my script) will result in the graphics popping up in a new window:

In []: plt.plot([1, 2, 3], [1, 3, 2])

On the other hand, when running myscript.py, the image will not be shown:

In []: %run myscript.py

Is there any way to change this behaviour and force IPython to show the images generated within the script?

1 Answer 1

2

When executing external scripts within IPython's console with the %run command, those scripts will be executed in not interactive mode. Therefore,

plt.show()

must be added in the script in order to show the generated graphics.

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

Comments

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.