Last active
January 26, 2022 15:30
-
-
Save rk76feWF/665af3de7c818d8ac8cfc191a88cfe54 to your computer and use it in GitHub Desktop.
1328_assignment11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 学生番号: 1328 | |
# 氏名: 福本 悠貴 | |
# レベル: 3 | |
!pip install japanize-matplotlib | |
import pandas as pd | |
import japanize_matplotlib | |
import matplotlib.pyplot as plt | |
import matplotlib.dates as mdates | |
prefix = "https://covid19.mhlw.go.jp/public/opendata/" | |
input_csv = prefix + "newly_confirmed_cases_daily.csv" | |
df = pd.read_csv(input_csv, parse_dates=["Date"]) | |
fig, ax = plt.subplots(figsize=(15, 8)) | |
locator = mdates.AutoDateLocator() | |
formatter = mdates.ConciseDateFormatter(locator) | |
ax.xaxis.set_major_locator(locator) | |
ax.xaxis.set_major_formatter(formatter) | |
ax.set_title("COVID-19 新規陽性者数の推移(日別)") | |
ax.set_xlabel("日付") | |
ax.set_ylabel("新規陽性者数(人)") | |
ax.plot(df["Date"], df["ALL"], color="orange", label="全国") | |
print("表示したい都市をスペースで区切って入力 ex)Tokyo Osaka Okinawa") | |
cities = input().split() # 入力された都市をスペースで分けて配列に保存。 | |
for city in cities: | |
if city in df.columns.values[2:]: # 入力された都市が存在するかチェック。 | |
ax.plot(df["Date"], df[city], label=city) | |
else: | |
print(city, "という都市はありません。") | |
ax.legend() # 凡例を表示する | |
fig.show() # グラフを表示する |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment