Skip to content
Advertisement

Matplotlib plots aren’t shown when running file from bash terminal

Plots are normally shown when I run files from the ipython shell or from an ipython notebook, but they don’t show up when I run the file from a bash terminal — everything else works fine when is run from a bash terminal.

Sample python script (trial.py):

JavaScript

This is what I get (plot doesn’t show up):

JavaScript

If I do

JavaScript

before importing pyplot, then a window opens and closes immediately when I run it from the terminal.

I’ve tried different ways of importing modules without success:

JavaScript

I have the plt.show() function in my file.

Do you know how I can fix it?

Some info about versions and installation:

I’m on a mac OSX 10.11.3.

JavaScript

Advertisement

Answer

You need to add matplotlib.pyplot.show() in your code to show plots in non-interactive mode. See docs at http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show

EDIT:

After further info from OP, blocking had to be enabled explicitly using plt.show(block=True).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement