我正在尝试在matplotlib条形图的yaxis上添加mi或km(英里,公里)。
现在我只是提供matplotlib值,它会自动生成yaxis标签。我无法弄清楚如何将mi附加到值的末尾。
24> 24英里
ax.set_7ticklabels()有一个选项,但我需要静态设置它们。
答案 0 :(得分:9)
你想要这样的东西吗?
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()