python - 将单位添加到 MatPlotLib 中的 yaxis 标签

标签 python django graph charts matplotlib

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

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

24 > 24 英里

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

最佳答案

你想要这样的东西吗?

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()

X-axis ticks labeled with units

关于python - 将单位添加到 MatPlotLib 中的 yaxis 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3927389/

相关文章:

graph - highcharts 折线图中的缺失值导致没有线,只有点

python - 我是否理解 Python 中实例属性和类属性之间的区别?

python - 僵尸进程,我们又来了

python - 即使在 Linux 中崩溃时也会自动重启 python 脚本

python - 如何在已部署的项目中禁用 Django 的管理员,但将其保留用于本地开发?

mysql - django/innodb -- 旧 session 和事务的问题

Python defaultdict(dict) 中一个键有多个值

python - PyCharm控制台如何导入自己的模块

javascript - Ajax、jQuery、Django。这是如何设置的?

algorithm - 使用 FGL 寻找最短路径