2017-01-17 3 views
-1

とYの位置をオーバーライドします。 しかし、わかるように、y座標がy値で与えられ、y軸が各グラフで異なっているので、それらはすべての場所でジャンプします。 x軸からy位置をピクセル単位で定義する方法はありますか? %of(グラフの一番上 - チャートの一番下)に頼らなくても理想的です。ありがとう!matplotlibのは、私がMatpltlibと次のグラフをプロットしようとしていた画素位置

答えて

4

座標をデータ座標ではなく軸座標でプロットすることができます。軸座標の範囲は0〜1(左下隅から右上隅)です。

軸座標を使用するには、プロットのtransform引数にAxes.transAxesを指定する必要があります(transformation tutorialも参照)。ここで

は最小限例です、あなたがデータ座標に水平座標を指定し、軸座標における垂直方向の1にしたい場合は、blended transformationを使用することができます

import matplotlib.pyplot as plt 

plt.plot([1,5,9], [456,894,347], "r-", 
     label="plot in data coordinates") 
plt.plot([0.2,0.3,0.7], [0.2,0.2,0.5], "bo", 
     transform=plt.gca().transAxes, label="plot in axes coordinates") 
plt.legend() 
plt.show() 


matplotlib.transforms.blended_transform_factory(ax.transData, ax.transAxes) 

これは次のように使用できます。

import matplotlib.pyplot as plt 
import matplotlib.transforms as transforms 

ax = plt.gca() 
plt.plot([12,25,48], [456,894,347], "r-", 
     label="plot in data coordinates") 
plt.plot([0.2,0.3,0.7], [0.2,0.2,0.5], "bo", 
     transform=ax.transAxes, label="plot in axes coordinates") 
#blended tranformation: 
trans = transforms.blended_transform_factory(ax.transData, ax.transAxes) 
plt.plot([15,30,35], [0.75,0.25,0.5], "gs", markersize=12, 
     transform=trans, label="plot x in data-,\ny in axes-coordinates") 

plt.legend() 
plt.show() 
+0

Thats great thx!しかし、私の具体的なケースでは、x値にはデータ座標を使用し、y値には座標軸を使用する必要があります。それは可能ですか? – Radar

関連する問題