开发者

Add unit to yaxis labels in MatPlotLib

开发者 https://www.devze.com 2023-01-19 18:01 出处:网络
I am trying to add mi or km (miles, kilometers) after the value on the yaxis of a matplotlib bar chart.

I am trying to add mi or km (miles, kilometers) after the value on the yaxis of a matplotlib bar chart.

Right now I am just supplying matplotlib the values and it is making the yaxis labels automatically. I can't figure out how to append mi to the end of a value.

开发者_如何学C

24 > 24 mi

There is an option for ax.set_7ticklabels(), but then I would need to set them statically.


Are you wanting something like this?

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

Add unit to yaxis labels in MatPlotLib

0

精彩评论

暂无评论...
验证码 换一张
取 消