[Fixed]-Add unit to yaxis labels in MatPlotLib

23👍

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

X-axis ticks labeled with units

Leave a comment