You can show it as many times as you want. Plt.show() #Does not show anything, because there is nothing in the "current" stack.įig.show() # Shows figure 1 again. In matplotlib 1.4.2 and using IPython 2.4.1 with Qt4Agg backend, I can do the following: import matplotlib.pyplot as pltįig, ax = plt.subplots(1) # Creates figure fig and add an axes, ax.įig2, ax2 = plt.subplots(1) # Another figureĪx.plot(range(20)) #Add a straight line to the axes of the first figure.Īx2.plot(range(100)) #Add a straight line to the axes of the first figure.įig.show() #Only shows figure 1 and removes it from the "current" stack.įig2.show() #Only shows figure 2 and removes it from the "current" stack. In my opinion, what you need is the object oriented API of matplotlib. I think I am a bit late to the party but. PS: now, with Matplotlib version 1.0.1+, show() can be called multiple times (with most backends). The above code should be sufficient most of the time. I believe that this is essentially what IPython does. The most robust approach would be to launch each figure drawing in a separate thread, with a final show() in each thread. But, as far as I understand, they do not have to be nice. Some backends are nice enough to let you interact with the first figure even though you have not called show(). Now, the above solution might be sufficient in simple cases, and for some Matplotlib backends. If you only need to sequentially display separate figures (either in the same window or not), you can do like in the above code. I don't think that Matplotlib offers a mechanism for creating a figure and optionally displaying it this means that all figures created with figure() will be displayed. Note that in principle, the calls to draw() are optional if you call matplotlib.ion() at the beginning of your script (I have seen this fail on some platforms and backends, though). It is important to recognize that show() is an infinite loop, designed to handle events in the various figures (resize, etc.). # raw_input() # If you need to wait here too. No need to save it, as pyplot uses the concept of current figure Raw_input() # This shows the first figure "separately" (by waiting for "enter"). The relevant drawing function is actually draw(): import matplotlib.pyplot as plt While creating Python visualizations, you will often encounter situations where your subplots have axis labels that overlap one another.With Matplotlib prior to version 1.0.1, show() should only be called once per program, even if it seems to work within certain environments (some backends, on some platforms, etc.). title ( 'Citric Acid plotted against Fixed Acidity' ) title ( 'Total Sulfur Dioxide plotted against Fixed Acidity' ) title ( 'Density plotted against Fixed Acidity' ) title ( 'Alcohol plotted against Fixed Acidity' ) title ( 'Quality plotted against Fixed Acidity' ) title ( 'Chlorides plotted against Fixed Acidity' ) When it reaches the end of a row, it will move down to the first entry of the next row.Ī few examples of selecting specific subplots within a plot grid are shown below: It starts at 1 and moves through each row of the plot grid one-by-one. The nrows and ncols arguments are relatively straightforward, but the index argument may require some explanation.
0 Comments
Leave a Reply. |