![]() Example: import matplotlib.pyplot as pltįig1, ax1 = plt.subplots(1) # Creates figure fig1 and add an axes, ax1įig2, ax2 = plt.subplots(1) # Another figure fig2 and add an axes, ax2Īx1.plot(range(20),c='red') #Add a red straight line to the axes of fig1.Īx2.plot(range(100),c='blue') #Add a blue straight line to the axes of fig2. ginput(n=-1,show_clicks=False) will wait until we close the window, but it releases an error :. waitforbuttonpress(timeout=-1) will close the figure window when clicking on the figure, so we cannot use some window functions like zooming. We do not have to close the figure - closing the figure deletes it. In my solution I get to prevent the figure for instantly closing by using click events. However, I do not find any another way to show only a figure. ![]() show() in a figure, e.g., figure.show(), is not recommended, because this method does not manage a GUI event loop and therefore the figure is just shown briefly. ![]() They are very useful for sequential programing, but you will find blocking walls very soon if you plan to use them in a more complex way.Īs the solutions above do not work for me ( matplotlib 3.0.3, python 3.5.2). Remember that most (all?) plt.* functions are just shortcuts and aliases for figure and axes methods. Otherwise, I think you will need to really dig down into the guts of matplotlib to monkeypatch a solution. You can specify figure.show() ONLY if you are using a GUI backend (e.g. In this case plt.show() shows anything in the "current" stack. 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 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.).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |