2010-10-13 10 views
5

Sto tentando di aggiungere mi o km (miglia, chilometri) dopo il valore sugli yax di un grafico a barre matplotlib.Aggiungere unità alle etichette Yaxis in MatPlotLib

In questo momento sto solo fornendo a matplotlib i valori e sta rendendo automaticamente le etichette di yaxis. Non riesco a capire come aggiungere mi alla fine di un valore.

24> 24 mi

C'è un'opzione per ax.set_7ticklabels(), ma poi mi avrebbe bisogno di impostarle in modo statico.

risposta

7

Vuoi qualcosa di simile?

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

Problemi correlati