How to keep the script run after plt.show() [duplicate]

2024/10/11 6:34:23

After the plt.show() , I just want to continue. However it is necessary to close the Pop-up Figure. how could i do to skip the action ?

there is my codes:

plt.show()
time.sleep(1)
plt.close('all')

other codes

there is other question about how to maximize the figure making by plt.show()

Answer

I did have a similar problem and found solution here on SO.I think that you need plt.ion().One example

import numpy as np
from matplotlib import pyplot as pltdef main():plt.axis([-20,20,0,10000])plt.ion()plt.show()x = np.arange(-20, 21)for pow in range(1,5):   # plot x^1, x^2, ..., x^4y = [Xi**pow for Xi in x]plt.plot(x, y)plt.draw()plt.pause(0.001)input("Press [enter] to continue.")if __name__ == '__main__':main()

Works fine,although it gives this warning

 MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implementedwarnings.warn(str, mplDeprecation)

I am not sure if that is related to 3.6 version or not.

https://en.xdnf.cn/q/69807.html

Related Q&A

python - Simulating else in dictionary switch statements

Im working on a project which used a load of If, Elif, Elif, ...Else structures, which I later changed for switch-like statements, as shown here and here.How would I go about adding a general "Hey…

Allow dynamic choice in Django ChoiceField

Im using Select2 in my application for creating tags-like select dropdowns. Users can select number of predefined tags or create a new tag.Relevant forms class part:all_tags = Tag.objects.values_list(i…

Row-wise unions in pandas groupby

I have a large data frame that looks like so (and is copy-pasteable with df=pd.read_clipboard(sep=\s\s+):user_nm month unique_ips shifted_ips halves quarters mo_pairs100118231 2 set(…

Add seaborn.palplot axes to existing figure for visualisation of different color palettes

Adding seaborn figures to subplots is usually done by passing ax when creating the figure. For instance:sns.kdeplot(x, y, cmap=cmap, shade=True, cut=5, ax=ax)This method, however, doesnt apply to seabo…

Running Django with Run can not find LESS CSS

I have a Django project that uses buildout. When running or debugging the application it runs fine by using my buildout script. I also use django-compressor to compress and compile my LESS files. I ins…

OpenCV + python -- grab frames from a video file

I cant seem to capture frames from a file using OpenCV -- Ive compiled from source on Ubuntu with all the necessary prereqs according to: http://opencv.willowgarage.com/wiki/InstallGuide%20%3A%20Debia…

python 3.1 - Creating normal distribution

I have scipy and numpy, Python v3.1I need to create a 1D array of length 3million, using random numbers between (and including) 100-60,000. It has to fit a normal distribution. Using a = numpy.random.…

Faster way to iterate all keys and values in redis db

I have a db with about 350,000 keys. Currently my code just loops through all keys and gets its value from the db.However this takes almost 2 minutes to do, which seems really slow, redis-benchmark gav…

How to store a floating point number as text without losing precision?

Like the question says. Converting to / from the (truncated) string representations can affect their precision. But storing them in other formats like pickle makes them unreadable (yes, I want this too…

Integer in python/pandas becomes BLOB (binary) in sqlite

Storing an integer in sqlite results in BLOBs (binary values) instead of INTEGER in sqlite. The problem is the INT in the "Baujahr" column. The table is created. CREATE TABLE "Objekt&quo…