2013-04-29 66 views
1

是否有一個簡單的方法來檢查,如果在matplotlib軸是對數/線性?檢查軸縮放matplotlib

如果鍵入ax.transData.__dict__(斧子semilogy),我得到:

{'_a': TransformWrapper(BlendedGenericTransform(IdentityTransform(),<matplotlib.scale.Log10Transform object at 0x10ffb3650>)), 
'_b': CompositeGenericTransform(BboxTransformFrom(TransformedBbox(Bbox('array([[ 0.00000000e+00, 1.00000000e+00],\n  [ 2.00000000e+03, 1.00000000e+08]])'), TransformWrapper(BlendedGenericTransform(IdentityTransform(),<matplotlib.scale.Log10Transform object at 0x10ffb3650>)))), BboxTransformTo(TransformedBbox(Bbox('array([[ 0.05482517, 0.05046296],\n  [ 0.96250543, 0.95810185]])'), BboxTransformTo(TransformedBbox(Bbox('array([[ 0., 0.],\n  [ 8., 6.]])'), Affine2D(array([[ 80., 0., 0.], 
     [ 0., 80., 0.], 
     [ 0., 0., 1.]]))))))), 
'_invalid': 2, 
'_parents': <WeakValueDictionary at 4572332904>, 
'_shorthand_name': '', 
'input_dims': 2, 
'output_dims': 2} 

我可以寫一個方法來檢查subtransforms ax.transData._a._child是對數級,但我不喜歡它的訪問私有變量而且這看起來相當難以持續,因爲變量名稱可能會改變。

回答

4

也有(不良記錄)功能axis.get_scale()

scale_str = ax.get_yaxis().get_scale() 

返回字符串。

+0

+1因爲它不依賴於私有變量。 – fgb 2013-04-30 02:30:57

1

原來的規模是隱藏在ax.yaxis._scale

import matplotlib as mpl 
type(ax.yaxis._scale) == mpl.scale.LogScale 

這將返回True,這正是我需要的。