【发布时间】:2020-07-12 22:12:53
【问题描述】:
我试图使用 matplotlib 和 pandas 创建一个条形图,显示美国 COVID-19 病例的每日变化。
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv')
display(data.head(10))
df = data.groupby('date').sum()
df['index'] = range(len(df))
df['IsChanged'] = df['cases'].diff()
df.at['2020-01-21', 'IsChanged'] = 0.0
x = df['index']
z = df['IsChanged']
plt.figure(figsize=(20,10))
plt.grid(linestyle='--')
plt.bar(x,z)
plt.show()
我得到的图表如下所示:
。
图表条的宽度不均匀。我尝试设置一个特定的宽度,但没有奏效。有没有办法解决这个问题?
【问题讨论】:
-
对于这么窄的酒吧,我会使用
Axes.stem
标签: python pandas matplotlib