【发布时间】:2020-04-29 14:24:46
【问题描述】:
我有一个索引为datetime 的熊猫系列,我试图将其可视化, 使用条形图。我的代码如下。但我得到的图表似乎不太准确(下图)。我该如何解决?
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(100)
dti = pd.date_range('2012-12-31', periods=30, freq='Q')
s2 = pd.Series(np.random.randint(100,1000,size=(30)),index=dti)
df4 = s2.to_frame(name='count')
print('\ndf4:')
print(df4)
print(type(df4))
f2 = plt.figure("Quarterly",figsize=(10,5))
ax = plt.subplot(1,1,1)
ax.bar(df4.index,df4['count'])
plt.tight_layout()
plt.show()
【问题讨论】:
-
使条形宽度大于一天。
-
我不确定我是否理解要进行哪些更改 @ImportanceOfBeingErnest
标签: python pandas matplotlib time-series timeserieschart