|
|
|||||||||||||||||||||||||||||
|
matplotlib Overview of axisartist toolkit. |
H.Kamifuji . |
AxisArtist モジュールの背後にある動機は、曲線のグリッドとダニをサポートすることです。![]() Demo Parasite Axes2 |
AxisArtist は、外軸が浮動軸として定義されている浮動軸もサポートしています。![]() Demo Floating Axes |
AxisArtist は、ダニ、ラベルなどを描画する次の属性を持つコンテナアーティストとして考えることができます。
|
既定では、軸のアーティストの次のものが定義されています。ax.axis["left"], ax.axis["bottom"], ax.axis["right"], ax.axis["top"]上軸と右軸の目盛りと軸ラベルは表示されないように設定されています。 たとえば、下のx軸のmajor_ticklabelsの色属性を変更する場合は、
ax.axis["bottom"].major_ticklabels.set_color("b")
同様に、ティックラベルを見えなくするにはax.axis["bottom"].major_ticklabels.set_visible(False)AxisAritst は、ティック、ティッカーラベル、およびラベルの可視性を制御するヘルパーメソッドを提供します。 ティッカーラベルを見えないようにするには、 ax.axis["bottom"].toggle(ticklabels=False)ティック、ティックラベル、(軸)ラベルをすべて非表示にするには ax.axis["bottom"].toggle(all=False)すべてオフにするが、オンにする ax.axis["bottom"].toggle(all=False, ticks=True)すべてのオン(軸)ラベルをオフにするには ax.axis["bottom"].toggle(all=True, label=False))ax.axis の __getitem__ メソッドは、複数の軸名を取ります。 たとえば、「上」軸と「右」軸のティックラベルをオンにするには、 ax.axis["top","right"].toggle(ticklabels=True))'ax.axis["top"、 "right"]' は、上記のコードを以下のように変換する単純なプロキシオブジェクトを返します。 for n in ["top","right"]: ax.axis[n].toggle(ticklabels=True))したがって、for ループ内の戻り値はすべて無視されます。 そして、あなたはそれを単純な方法以上に使うべきではありません。 リストのインデックス付けと同様に、「:」はすべてのアイテム、すなわち、
ax.axis[:].major_ticks.set_color("r")
すべての軸でティックカラーを変更します。 |
|
ティックとティックラベルの間でパッドを変更するには![]() Demo Ticklabel Alignment |
ティックとティックラベルの間でパッドを変更するにはax.axis["left"].major_ticklabels.set_pad(10)またはティックラベルと軸ラベル ax.axis["left"].label.set_pad(10) ![]() Simple Axis Pad |
実際に曲線座標を定義するには、独自のグリッドヘルパーを使用する必要があります。 グリッドヘルパークラスの一般化されたバージョンが提供され、このクラスではほとんどの場合十分です。 ユーザは、曲線座標から(直線)画像座標への変換(およびその逆対)を定義する 2 つの関数を提供することができる。 ティックとグリッドは曲線座標のために描画されますが、軸自体( ax.transData )のデータ変換はまだ直線(画像)座標です。
from mpl_toolkits.axisartist.grid_helper_curvelinear \
import GridHelperCurveLinear
from mpl_toolkits.axisartist import Subplot
# from curved coordinate to rectlinear coordinate.
def tr(x, y):
x, y = np.asarray(x), np.asarray(y)
return x, y-x
# from rectlinear coordinate to curved coordinate.
def inv_tr(x,y):
x, y = np.asarray(x), np.asarray(y)
return x, y+x
grid_helper = GridHelperCurveLinear((tr, inv_tr))
ax1 = Subplot(fig, 1, 1, 1, grid_helper=grid_helper)
fig.add_subplot(ax1)
代わりに matplotlibのTransform インスタンスを使用することもできます(逆変換を定義する必要があります)。 しばしば、湾曲した座標系の座標範囲は限られた範囲を有するか、または周期を有することがある。 そのような場合、グリッドヘルパーのよりカスタマイズされたバージョンが必要です。
import mpl_toolkits.axisartist.angle_helper as angle_helper
# PolarAxes.PolarTransform takes radian. However, we want our coordinate
# system in degree
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()
# extreme finder : find a range of coordinate.
# 20, 20 : number of sampling points along x, y direction
# The first coordinate (longitude, but theta in polar)
# has a cycle of 360 degree.
# The second coordinate (latitude, but radius in polar) has a minimum of 0
extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
lon_cycle = 360,
lat_cycle = None,
lon_minmax = None,
lat_minmax = (0, np.inf),
)
# Find a grid values appropriate for the coordinate (degree,
# minute, second). The argument is a approximate number of grids.
grid_locator1 = angle_helper.LocatorDMS(12)
# And also uses an appropriate formatter. Note that,the
# acceptable Locator and Formatter class is a bit different than
# that of mpl's, and you cannot directly use mpl's Locator and
# Formatter here (but may be possible in the future).
tick_formatter1 = angle_helper.FormatterDMS()
grid_helper = GridHelperCurveLinear(tr,
extreme_finder=extreme_finder,
grid_locator1=grid_locator1,
tick_formatter1=tick_formatter1
)
ここでも、軸の transDataは 依然として直線座標(画像座標)です。 2つの座標の間で手動で変換を行うこともできますし、便宜上 Parasite Axes を使用することもできます。ax1 = SubplotHost(fig, 1, 2, 2, grid_helper=grid_helper) # A parasite axes with given transform ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal") # note that ax2.transData == tr + ax1.transData # Anthing you draw in ax2 will match the ticks and grids of ax1. ax1.parasites.append(ax2) ![]() Demo Curvelinear Grid |
浮動軸は、データ座標が固定されている軸であり、その位置は軸座標で固定されていないが、軸データの変更によって変化する。 浮動軸は、 new_floating_axis メソッドを使用して作成できます。 しかし、AxisArtistがAxes に正しく追加されることは、あなたの責任です。 Axes の軸属性の項目として追加することをお勧めします。
# floating axis whose first (index starts from 0) coordinate
# (theta) is fixed at 60
ax1.axis["lat"] = axis = ax1.new_floating_axis(0, 60)
axis.label.set_text(r"$\theta = 60^{\circ}$")
axis.label.set_visible(True)
このページの最初の例を参照してください。 |
コードはより洗練されたものが必要です。 ここには不完全な問題のリストとTODOの
|
| Overview of axisartist toolkit |
|