-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualizing COVID data.py
105 lines (72 loc) · 2.59 KB
/
Visualizing COVID data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import matplotlib.pyplot as plt
#Opening the .csv file
Covid_Data = pd.read_csv('owid-covid-data.csv')
#Selecting the neccessary columns
Newcases = Covid_Data.loc[:,['location','date','new_cases']]
# Selecting 6 countries
Countries = ['India', 'Argentina', 'Brazil', 'Denmark', 'Japan', 'Phillipines']
# Subsetting the new cases for the selected 6 countries
Countrywise = Newcases[Newcases['location'].isin(Countries)]
# Creating a figure and axes
fig, ax = plt.subplots(figsize=(10, 6))
# Loop through the selected countries and plotting their data
for i in Countries:
A = Countrywise[Countrywise['location'] == i]
ax.plot(A['date'], A['new_cases'], label=i)
#Label for x-axis
ax.set_xlabel('Date')
#Setting the number of points in x-axis
ax.xaxis.set_major_locator(plt.MaxNLocator(15))
#Label for y-axis
ax.set_ylabel('New Cases')
#Title for the graph
ax.set_title('COVID Cases by Country')
#Legend for the graph
ax.legend()
plt.tight_layout()
plt.show()
# In[2]:
import plotly.express as px
# Filtering the data for the date range on 21 September 20203
Newcases_2023 = Covid_Data[Covid_Data['date'] == '2023-09-21']
# Filtering the data for the date range on 21 November 20200
Newcases_2020 = Covid_Data[Covid_Data['date'] == '2020-11-21']
# Create the world map for 2023
fig_2023 = px.choropleth(Newcases_2023,
locations="location",
locationmode="country names",
color="total_cases",
color_continuous_scale='Jet',
# Specifying a custom color range for comparison between 2020 and 2023
range_color=(0, 10000000),
hover_name="location",
title="COVID cases as on 21 Sep 2023")
#Setting the title at the middle
fig_2023.update_layout(
title={
'y':0.9,
'x':0.5})
#Plotting the graph for 2023
fig_2023.show()
# Create the world map for the 2023
fig_2020 = px.choropleth(Newcases_2020,
locations="location",
locationmode="country names",
color="total_cases",
color_continuous_scale='Jet',
# Specifying a custom color range for comparison between 2020 and 2023
range_color=(0, 10000000),
hover_name="location",
title="COVID cases as on 21 Nov 2020")
#Setting the title at the middle
fig_2020.update_layout(
title={
'y':0.9,
'x':0.5})
#Plotting the graph for 2020
fig_2020.show()
# In[ ]: