【问题标题】:Add unit to yaxis labels in MatPlotLib将单位添加到 MatPlotLib 中的 yaxis 标签
【发布时间】:2011-04-25 01:14:52
【问题描述】:

我正在尝试在 matplotlib 条形图的 y 轴上的值之后添加 mi 或 km(英里、公里)。

现在我只是为 matplotlib 提供值,它会自动制作 yaxis 标签。我不知道如何将 mi 附加到值的末尾。

24 > 24 英里

ax.set_7ticklabels() 有一个选项,但是我需要静态设置它们。

【问题讨论】:

    标签: python django graph charts matplotlib


    【解决方案1】:

    你想要这样的东西吗?

    import matplotlib.pyplot as plt
    from matplotlib.ticker import FormatStrFormatter
    
    x = range(10)
    plt.plot(x)
    
    plt.gca().xaxis.set_major_formatter(FormatStrFormatter('%d km'))
    
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-20
      • 2014-07-29
      • 2017-11-24
      • 1970-01-01
      相关资源
      最近更新 更多