【问题标题】:Matplotlib. Setting title an x and y label [duplicate]Matplotlib。设置标题一个x和y标签[重复]
【发布时间】:2023-04-04 02:25:01
【问题描述】:

我正在尝试设置我的情节标题以及 x 和 y 标签。总计都是 float64 的数字。 我正在尝试以尽可能简单的方式做到这一点。

这是我的代码的一部分:

plt.close('all')
cand_all =pd.DataFrame({'Bachmann':[total15],
                        'Romney':[total2],
                        'Obama':[total3],
                        'Roemer': [total4],
                       'Pawlenty':[total5],
                       'Johnson':[total6],
                       'Paul':[total7],
                       'Santorum':[total8],
                       'Cain':[total9],
                       'Gingrich':[total10],
                       'McCotter':[total12],
                       'Huntsman':[total13],
                       'Perry':[total14]}) 



cand_all.plot.bar()

【问题讨论】:

    标签: python pandas matplotlib


    【解决方案1】:

    您需要提供一个轴 (ax) 参数。

    ax=plt.subplot(111)
    cand_all.plot.bar(ax=ax)
    ax.set_xlabel('xlabel')
    ax.set_ylabel('ylabel')
    ax.set_title('title')
    

    请注意,对于pandas 数据帧,索引的名称(如果存在)将自动变为 x 标签。

    【讨论】:

      猜你喜欢
      • 2018-09-07
      • 2018-08-01
      • 2022-01-11
      • 2012-03-14
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 2020-09-14
      相关资源
      最近更新 更多