子图中的DataFrame条形图不显示x标签

时间:2015-12-01 01:56:02

标签: python pandas matplotlib

我正在尝试使用DataFrame .plot()函数绘制多个子图。似乎xlabel仅出现在最后一行。

xlabel not appearing - example

import pandas as pd
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2,1)
for ax in axs:
    df = pd.DataFrame(np.random.rand(1, 4), columns=['a', 'b', 'c', 'd'])
    df.index.name = 'Xlabel'
    df.plot(kind='bar', ax=ax)    
plt.tight_layout()
fig.show()

是否有解决方法让每行xlabel

1 个答案:

答案 0 :(得分:0)

你的代码看起来很好,它在我运行它时显示了我的标签(在ipython中,pandas 0.17.1,matplotlib 1.5.0)。这表明matplotlib配置有所不同。