【问题标题】:How to set the range of minor ticks?如何设置次要刻度的范围?
【发布时间】:2020-10-04 21:19:09
【问题描述】:

我正在绘制条形图。我绘制的图片如下:

为了在上下轴上添加箭头,我首先将刺的颜色设置为“无”。

然后我使用axes.arrow() 函数绘制箭头。

最后,我使用axes.set_ticks() 函数重置刻度。

我想保留顶轴的小刻度。但正如您所看到的,左上角的小刻度超出了箭头的范围。如何删除超出范围的部分?

【问题讨论】:

    标签: python matplotlib xticks


    【解决方案1】:

    可以通过set_minor_locator 使用FixedLocator 设置次要刻度。

    一个例子:

    from matplotlib import pyplot as plt
    from matplotlib.ticker import FixedLocator
    
    fig, ax = plt.subplots()
    ax.set_xscale('log')
    ax.set_xlim(10**6, 1)
    ax.set_xticks([10**n for n in range(-1, 5)])
    ax.xaxis.set_minor_locator(FixedLocator(
        [k * 10**n for n in range(-1, 5) for k in range(2, 10) if k * 10**n <= 30000]))
    ax.xaxis.tick_top()
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-11
      • 1970-01-01
      • 2018-12-07
      • 2012-03-03
      • 2014-06-03
      • 2018-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多