【发布时间】:2021-11-11 04:58:15
【问题描述】:
我不明白为什么我的代码不起作用。我想要一个间隔为 1 的 x 轴。
df['Dates'] = pd.to_datetime(df.Dates)
fig, ax = plt.subplots(figsize=(16, 9))
ax.bar(df['Dates'],
df['Score'],
color='blue',
width=2)
date_form = DateFormatter("%d/%m/%Y")
ax.xaxis.set_major_formatter(date_form)
ax.xaxis.set_major_locator(mdates.DayLocator(interval=1))
ax2=ax.twinx()
ax2.plot(df['Dates'],
df['Price'],
color = 'black')
plt.show()
【问题讨论】:
标签: python pandas dataframe matplotlib pycharm