matplotlib 在 y 轴上缺少小刻度,因为对数范围 >10 个十年

Til*_*uss 3 python matplotlib python-3.x jupyter-notebook

首先,这个问题与Matplotlib 半对数图直接相关:当 range 大时,小刻度线消失了
对于 1E-15 到 1E-4 范围内的值,我试图在 y 轴上获得相同的结果。
我还没有足够的声誉在引用的问题中发表评论 - 抱歉加倍!

测试设置:我将 Jupyter 4.3.0 与 matplotlib 2.0.2 和 numpy 1.13.1 一起使用

下面的代码(来自参考问题)在我的 Jupyter 安装中没有在x 轴上显示小刻度。我需要 y 轴,但应该是相同的程序。

感谢您的任何投入,推动我朝着正确的方向前进。

import matplotlib.pyplot as plt
import matplotlib.ticker
import numpy as np

#Used this to reset any changes to the rc params
#plt.rcParams.update(plt.rcParamsDefault)

x = np.arange(10) # np.arange(9) is working as expected - well documented issue with >10 range for ticker.LocLocator
y = 10.0**x

fig, ax=plt.subplots()
ax.plot(y,x)
ax.set_xscale("log")

locmaj = matplotlib.ticker.LogLocator(base=10.0, subs=(0.1,1.0, ))
ax.xaxis.set_major_locator(locmaj)

locmin = matplotlib.ticker.LogLocator(base=10.0, subs=(0.1,0.2,0.4,0.6,0.8,1,2,4,6,8,10 )) 
ax.xaxis.set_minor_locator(locmin)
ax.xaxis.set_minor_formatter(matplotlib.ticker.NullFormatter())

plt.show()
Run Code Online (Sandbox Code Playgroud)

结果图 -

在此处输入图片说明

tac*_*ell 5

需要更改的参数,numticks用于限制将发出的滴答数。

import matplotlib.pyplot as plt
import matplotlib.ticker
import numpy as np

#Used this to reset any changes to the rc params
#plt.rcParams.update(plt.rcParamsDefault)

x = np.arange(10) 
y = 10.0**x

fig, ax=plt.subplots()
ax.plot(y,x)
ax.set_xscale("log")

locmaj = matplotlib.ticker.LogLocator(base=10.0, subs=(1.0, ), numticks=100)
ax.xaxis.set_major_locator(locmaj)

locmin = matplotlib.ticker.LogLocator(base=10.0, subs=np.arange(2, 10) * .1,
                                      numticks=100)
ax.xaxis.set_minor_locator(locmin)
ax.xaxis.set_minor_formatter(matplotlib.ticker.NullFormatter())

plt.show()
Run Code Online (Sandbox Code Playgroud)

密集的蜱虫

一旦定位器决定开始跳过几十年,如果subs不是(1,)所有刻度都被抑制以防止一些非常混乱的刻度标签。

也不是说刻度会[s * base ** i for s in subs for i in range(min_decade, max_decade, decade_stride]如此放置值不同,只是basesubs重新刻度相同的点。