2017-06-28 15 views
2

Graphmatplotlib pythonでx軸の値を設定する方法は?

matplotlibを使ってこのグラフを描きたいと思います。私はコードを書いたが、x軸の値は変更されていない。

import matplotlib.pyplot as plt 
x = [0.00001,0.001,0.01,0.1,0.5,1,5] 
y = [0.945,0.885,0.893,0.9,0.996,1.25,1.19] 
plt.xlim(0.00001,5) 
plt.ylim(0.8,1.4) 
plt.plot(x, y, marker='o', linestyle='--', color='r', 
label='Square') 
plt.xlabel('x') 
plt.ylabel('y') 
plt.title('compare') 
plt.legend() 
plt.show() 

matplotlibを使用してグラフの青い線を描く方法はありますか?

答えて

2

あなたの例のフィギュアのスケーリングは少し奇妙ですが、あなたはそれぞれのx値のインデックスをプロットし、データポイントにダニを設定することで、それを強制することができます

import matplotlib.pyplot as plt 
x = [0.00001,0.001,0.01,0.1,0.5,1,5] 
# create an index for each tick position 
xi = [i for i in range(0, len(x))] 
y = [0.945,0.885,0.893,0.9,0.996,1.25,1.19] 
plt.ylim(0.8,1.4) 
# plot the index for the x-values 
plt.plot(xi, y, marker='o', linestyle='--', color='r', label='Square') 
plt.xlabel('x') 
plt.ylabel('y') 
plt.xticks(xi, x) 
plt.title('compare') 
plt.legend() 
plt.show() 
+1

あなたは閉じ括弧を追加する必要があります「範囲」に – jacoblaw

+1

私はそれが今感謝を見る – GWW

関連する問題