Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show matplotlib plots?

I am sure the configuration of matplotlib for python is correct since I have used it to plot some figures.

But today it just stop working for some reason. I tested it with really simple code like:

import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 5, 0.1) y = np.sin(x) plt.plot(x, y) 

There's no error but just no figure shown up.

I am using python 2.6, Eclipse in Ubuntu

like image 919
manxing Avatar asked Dec 20 '11 11:12

manxing


People also ask

Why is matplotlib not showing plot?

The issue actually stems from the matplotlib backend not being properly set, or from a missing dependency when compiling and installing matplotlib.

How do I show multiple plots in matplotlib?

In Matplotlib, we can draw multiple graphs in a single plot in two ways. One is by using subplot() function and other by superimposition of second graph on the first i.e, all graphs will appear on the same plot.

Is PLT show () necessary?

Matplotlib is used in a terminal or scripts, plt. show() is a must. Matplotlib is used in a IPython shell or a notebook (ex: Kaggle), plt. show() is unnecessary.


1 Answers

In matplotlib you have two main options:

  1. Create your plots and draw them at the end:

    import matplotlib.pyplot as plt  plt.plot(x, y) plt.plot(z, t) plt.show() 
  2. Create your plots and draw them as soon as they are created:

    import matplotlib.pyplot as plt from matplotlib import interactive interactive(True)  plt.plot(x, y) raw_input('press return to continue')  plt.plot(z, t) raw_input('press return to end') 
like image 175
joaquin Avatar answered Oct 02 '22 22:10

joaquin