2017-10-17 4 views

Antwort

0

Normalerweise würden Sie die Daten vor dem Plotten skalieren. Anstatt plt.plot(x,y) verwenden Sie plt.plot(x,y/1e6).

Um die Werte mit 3 Dezimalstellen zu formatieren, verwenden Sie eine matplotlib.ticker.StrMethodFormatter und ein Format mit 3 Dezimalstellen, in diesem Fall "{x:.3f}".

import matplotlib.pyplot as plt 
import matplotlib.ticker 
import numpy as np; np.random.seed(42) 

x = np.arange(5) 
y = np.array([5e5,2e5,0,3e5,4e5]) 

plt.plot(x,y/1e6) 

plt.gca().yaxis.set_major_formatter(matplotlib.ticker.StrMethodFormatter("{x:.3f}")) 

plt.show() 
+0

Danke, ich tat mit: def numfmt (x, pos): # Ihre benutzerdefinierte Formatierer-Funktion: dividieren durch 100,0 s = '{}'. Format (x/1000000.0) zurück s; und xfmt = tkr.FuncFormatter (numfmt) plt.gca(). xaxis.set_major_formatter (xfmt) –

+0

Was ist los mit dieser Antwort? – ImportanceOfBeingErnest

Verwandte Themen