在Matplotlib中检查轴刻度

问题描述:

是否有一种简便的方法来检查matplotlib中的轴是否为对数/线性轴?

Is there an easy way to check if axes in matplotlib are logarithmic/linear?

如果我输入 ax.transData.__dict__(ax 是 semilogy),我得到:

If I type ax.transData.__dict__ (ax is semilogy), I get:

{'_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}

我可以编写一种方法来检查子转换 ax.transData._a._child 是否是对数尺度的,但我不喜欢它访问私有变量,而且它似乎相当不可持续,因为变量名可以更改.

I could write a method to check if the subtransforms ax.transData._a._child are log-scale but I don't like that it accesses private variables and it seems rather unsustainable, since the variable name can change.

还有(记录不充分的)函数 axis.get_scale()

There is also the (poorly documented) function axis.get_scale()

scale_str = ax.get_yaxis().get_scale()

返回一个字符串.