Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have multiple PyPlot windows? Or am I limited to subplots?

I'm not sure how to word my question more clearly. Basically, is PyPlot limited to one instance/window? Any hack or workaround I try either causes my program to freeze or for the second pyplot window to be queued until the first one is closed.

like image 824
wnewport Avatar asked May 13 '11 14:05

wnewport


People also ask

Can there be multiple subplots?

Unless you're a master writer, you shouldn't use more than 2 subplots to your main one.

How do you plot in different windows in Python?

Sample Matplotlib Code for Plotting Multiple Figures in Separate Windows. One way to do this is to use the plt. figure() command for each figure that you want to plot separately. Optionally, you can use plt.

How do I make multiple subplots in Matplotlib?

To create multiple plots use matplotlib. pyplot. subplots method which returns the figure along with Axes object or array of Axes object. nrows, ncols attributes of subplots() method determine the number of rows and columns of the subplot grid.


1 Answers

Sure, just open a new figure:

import matplotlib.pyplot as plt  plt.plot(range(10))  plt.figure() plt.plot(range(10), 'ro-')  plt.figure(), plt.plot(...)  plt.show() # only do this once, at the end 

If you're running this in the default python interpreter, this won't work, as each figure needs to enter the gui's mainloop. If you want to run things in an interactive shell, look into IPython. If you just run this normally (i.e. put it into a file and call python filename.py) it will work fine, though.

like image 198
Joe Kington Avatar answered Sep 18 '22 00:09

Joe Kington