2016-11-02 4 views
0

Ich versuche, Datenpunkte mit eine Leistung von 3 Format, d. H. 24^3. Zum BeispielKennzeichnung Datenpunkte

A = [1,2,3,4,5] 
B = [100,200,300,400,500] 

fig = plt.figure() 
ax = fig.add_subplot(111) 
plt.plot(A,B) 
n=[24,48,96,192] 
for i, txt in enumerate(n): 
    ax.annotate(txt, (A[i],B[i])) 
plt.show() 

enter image description here

Anstatt also n=[24,48,96,192], würde Ich mag 24^3,48^3,96^3 ... oder noch besser sehen, ob ich eine verbesserte Darstellung für die Macht der 3.

nutzen könnte

Wie könnte ich das tun?

Antwort

0

Sie brauchen nur eine kleine Änderung in Ihrem annotate Anruf:

for i, txt in enumerate(n): 
    ax.annotate(str(txt) + '$^3$', (A[i],B[i])) 

Mit ‚$ ... $ "Sie können einen mathematischen Modus eingeben. mehr Details hier: http://matplotlib.org/users/mathtext.html

Das Ergebnis aussehen soll: enter image description here

1

See: http://matplotlib.org/users/mathtext.html

Beispiel:

import matplotlib.pylab as plt 

A = [1,2,3,4,5] 
B = [100,200,300,400,500] 

fig = plt.figure() 
ax = fig.add_subplot(111) 
plt.plot(A,B) 
n=[24,48,96,192] 
for i, txt in enumerate(n): 
    ax.annotate(r'${}^3$'.format(txt), (A[i],B[i])) 
plt.show() 

enter image description here

Verwandte Themen