【发布时间】:2018-02-04 21:43:16
【问题描述】:
首先,这个问题与Matplotlib semi-log plot: minor tick marks are gone when range is large直接相关。
对于 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()
结果图 -
【问题讨论】:
-
好的,我看到了问题。链接问题的解决方案适用于 matplotlib 2.0.0(或更低版本?),但似乎不适用于 matplotlib 2.0.2。原因目前尚不清楚,正在调查中。
-
我打开了一个功能请求,以使 10-dec 的限制不可推翻github.com/matplotlib/matplotlib/issues/9107
-
我认为问题已经解决了,因此我将其标记为与原帖重复。
-
是的,从现在开始重复。
-
感谢 ImportanceOfBeingErnest 和 tacaswell 提供非常快速的解决方案!
标签: python python-3.x matplotlib jupyter-notebook