【问题标题】:pandas matplotlib resizing and removing labelspandas matplotlib 调整大小和删除标签
【发布时间】:2014-04-17 09:06:57
【问题描述】:

我正在使用 pandas matplotlib 绘制来自 dataFrame 的数据。 我就是这样做的:

df = pd.DataFrame({'type': dataFrame['Country'], labelName: 'Infant mort. rate'})
ax = df.plot(kind='bar',x= dataFrame['Country'])
ax.set_ylabel('Infant mort. rate')
ax.set_xlabel('Country')
plt.show()

我正在尝试去掉右上角的标签(“蓝色”婴儿死亡率) 我想调整整个窗口的大小,这样我就可以看到 xlabel(现在它隐藏在底部的白线下) 我该怎么做?

【问题讨论】:

    标签: python python-3.x matplotlib pandas


    【解决方案1】:

    首先显式创建您的图形和轴对象,将一些附加选项传递给df.plot(...),并在显示图形之前调用fig.tight_layout()

    import matplotlib.pyplot as plt
    import pandas as pd
    fig, ax = plt.subplots(figsize=(8,5))
    df = pd.DataFrame({'type': dataFrame['Country'], labelName: 'Infant mort. rate'})
    ax = df.plot(kind='bar', x=dataFrame['Country'], legend=False, ax=ax)
    ax.set_ylabel('Infant mort. rate')
    ax.set_xlabel('Country')
    fig.tight_layout()
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-03
      • 2021-11-29
      • 1970-01-01
      • 2021-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多