1

I don’t know why my matplotlib didn’t show plots, and no errors too. I thinks I missing something on its installation because when in IPython notebooks an QtIpython using %mayplotlib inline directive have no problems but when running from terminal or script didn’t show anything. Any ideas ??

for example, in QtIPython and Ipython notebook I run

%matplotlib inline
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
ax.plot([1,2,3,4,5,6,7,8,9,0],[2,3,4,5,6,7,8,9,0,11], '-r')
ax.grid()
plt.show()

and the plot shows Ok!

but in a simple script with

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
ax.plot([1,2,3,4,5,6,7,8,9,0],[2,3,4,5,6,7,8,9,0,11], '-r')
ax.grid()
plt.show()

didn’t show anything

efirvida
  • 4,592
  • 3
  • 42
  • 68

1 Answers1

5

If you use matplotlib inline in IPython notebook, the plots are shown automatically. If you plot things in a script you have to put a plt.show() at the end to actually show the figure. In the terminal you can also use plt.ion() to switch on intreactive mode.

thomas
  • 1,773
  • 10
  • 14
  • I, know, but the figure did not appear, and in the terminal needier, so maybe is something with the figure window – efirvida Nov 26 '15 at 19:27
  • Then it may be a problem with the backend. Have you tried different ones? [This](http://stackoverflow.com/questions/5091993/list-of-all-available-matplotlib-backends) shows you how to find out your options, and [here](http://stackoverflow.com/questions/3285193/how-to-switch-backends-in-matplotlib-python) it is described how to change it. Maybe you have to try a few. – thomas Nov 26 '15 at 19:32
  • I'm running the script in my computer and that exact code works, I'm getting a plot with a (ugly) red line with grid on. Python 2.7 @ Windows 8.1. – tglaria Nov 26 '15 at 19:46
  • Thanks!!! it was a backend problem, who can I setup the default backend? it always start with 'agg' – efirvida Nov 26 '15 at 20:04
  • There should be a text file with the default rcParams somewhere. The details depend on your OS. – thomas Nov 26 '15 at 20:08
  • 1
    @efirvida: The backend can be set in [the matplotlibrc file](http://matplotlib.org/users/customizing.html). – unutbu Nov 26 '15 at 20:38