【问题标题】:In matplotlib.pyplot, how to create label in x and y coordinate?在 matplotlib.pyplot 中,如何在 x 和 y 坐标中创建标签?
【发布时间】:2013-09-22 12:10:19
【问题描述】:

我有名为 df 的数据框,并且通过发出以下命令成功绘制了条形图:

df.plot(kind="bar")

图表已显示,但是我不知道如何设置 x 标签、y 标签及其标题?对此有任何想法吗?是否有任何完整的文档可用于此?

感谢您的友好建议!

【问题讨论】:

    标签: python matplotlib bar-chart


    【解决方案1】:

    我假设您使用的是熊猫。数据框绘图方法返回一个 matplotlib 坐标区对象。可以调用axes方法自定义——http://matplotlib.org/api/axes_api.html

    ax = df.plot(kind='bar')
    ax.set_xlabel('fred')
    ax.set_ylabel('barney')
    ax.set_title('wilma')
    

    【讨论】:

    • 太棒了!非常感谢=)
    猜你喜欢
    • 1970-01-01
    • 2019-10-20
    • 2020-05-16
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    • 2019-05-14
    • 1970-01-01
    • 2020-10-30
    相关资源
    最近更新 更多