In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Matplotlib to draw a dynamic map of the epidemic, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know it.
Use matplotlib to map the daily death toll of COVID-19 in four countries in the past six months. The API interface for obtaining data is:
Https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv
The logic of data processing is as follows. Refer to the processing logic pushed a few days ago:
Df = pd.read_csv ('a.csvents, delimiter=',', header='infer')
Df_interest = df.loc [df ['Country/Region'] .isin ([' United Kingdom', 'US',' Italy', 'Germany']) & df [' Province/State'] .isna ()]
Df_interest.rename (index=lambda x: df_interest.at [x, 'Country/Region'], inplace=True)
Df1 = df_interest.transpose ()
Df1 = df1.drop (['Province/State',' Country/Region', 'Lat',' Long'])
Df1 = df1.loc [(df1! = 0) .any (1)]
Df1.index = pd.to_datetime (df1.index)
To make it easier for you to understand, show some of the data from df_interest:
Some of the data of the collated df1:
It can be seen that as of yesterday, the number of COVID-19 deaths in the United States had reached 219286.
The logic of drawing a line chart animation is as follows:
Color = ['red',' green', 'blue',' orange']
Fig = plt.figure ()
Plt.xticks (rotation=45, ha= "right", rotation_mode= "anchor")
Plt.subplots_adjust (bottom = 0.2, top = 0.9)
Plt.ylabel ('No of Deaths')
Plt.xlabel ('Dates')
# this function is a callback function for drawing animation
# there is one and only one parameter I, which indicates the number of frames and the line of the df1
Def showLine (I):
Plt.legend (df1.columns)
P = plt.plot (df1 [: I] .index, df1 [: I] .values)
For i in range (0pr 4):
P [I] .set _ color (Color [I])
This is the only line for drawing the animation. Call FuncAnimation, whose second argument is the function showLine defined above:
Animator = ani.FuncAnimation (fig, showLine, interval = 10)
Plt.show ()
The drawn line chart animation is as follows:
Thank you for reading this article carefully. I hope the article "how to draw an epidemic Map using Matplotlib" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.