【问题标题】:Check axes scale in matplotlib检查 matplotlib 中的坐标轴比例
【发布时间】:2013-04-30 07:45:44
【问题描述】:

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

如果我输入ax.transData.__dict__(ax 是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}

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

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

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

    scale_str = ax.get_yaxis().get_scale()
    

    返回一个字符串。

    【讨论】:

      【解决方案2】:

      原来刻度隐藏在ax.yaxis._scale

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

      这会返回True,这正是我所需要的。

      【讨论】:

        猜你喜欢
        • 2015-01-20
        • 1970-01-01
        • 2022-07-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多