2
votes

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

1 Answers

2
votes

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.