我正在尝试在 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()
关于python - 将单位添加到 MatPlotLib 中的 yaxis 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3927389/