2016-11-02 16 views
0

の力を3の度数{の形式、つまり24^3}を使用してラベル付けしようとしています。例えば 、データポイントにラベルを付ける

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

ので、代わりにn=[24,48,96,192]の、私は3

の電源ための改善された表現を使うことができれば 24^3,48^3,96^3 ...またはより良いを見たいのですが

どうすればいいですか?

答えて

0

あなたの注釈コールで唯一の小さな変更を必要とします'あなたは何らかの数学的モードを入力することができます。 ここで詳細を参照してください:http://matplotlib.org/users/mathtext.html

結果を次のようになります。 enter image description here

1

参照:http://matplotlib.org/users/mathtext.html

例:「$ ... $で

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

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

関連する問題