首页 > 解决方案 > pandas bar plots x 轴的行为与直接校准 Axes.bar 不同

问题描述

我正在绘制一些时间序列数据,同时使用线图和条形图,并且在共享 X 轴时,我观察到 pandas 条形图上的古怪或烦人的行为。

在这种情况下,有没有办法让熊猫条形图表现得像原始 matplotlib 条形图?

代码:

# close100 and volume100 are time series with the same date index
fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(12, 6))

close100.plot(ax=ax[0, 0])

ax[1, 0].bar(volume100.index, volume100.values)  # Using Axes.bar

close100.plot(ax=ax[1, 0])

volume100.plot.bar(ax=ax[1, 1])  # Using Series.plot.bar
ax[1, 1].xaxis.set_major_locator(mdates.MonthLocator())

条形图

标签: pythonpandasmatplotlibplot

解决方案


推荐阅读