python-3.x - 仅在某些图表上缺少次要刻度
问题描述
我的代码提取 csv 文件,对数据进行子集化,然后对每个数据框进行交互以生成输出和一些图表。该代码适用于我的所有测试数据,但一个 csv 文件的两个子集数据帧除外。问题是从 0 到 100 的次要刻度没有显示在两个输出图上。我查看了数据,我不明白为什么小刻度不会显示。
我尝试使用此代码设置主轴,
locmaj = matplotlib.ticker.LogLocator(base=10.0, numticks = 6)
ax.yaxis.set_major_locator(locmaj)
但即使我在次要 loglocator 行中将 numticks 设置为相等,这也无济于事。它确实产生了一个有趣的行为,其中 0 和 1 根本不显示在 y 轴上。
fig, ax = plt.subplots()
ax.scatter(df['cunnanes'],df['turbidity'], s = 4)
ax.scatter(exceed['exceedance'], exceed['turbidity'])
ax.set_title(names[i] + ' Exceedance graph')
ax.set_xlabel('Exceedance Probability (%)')
ax.set_ylabel('Turbidity (FNU)')
ax.set_yscale('symlog')
ax.set_ylim([-0.5, 10000])
ax.minorticks_on
ax.tick_params(axis = 'x', which = 'both', direction = 'in', top = True, bottom = True)
ax.tick_params(axis = 'y', which = 'both', direction = 'in', left = True, right = True)
locmin = matplotlib.ticker.LogLocator(base=10.0, subs=(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9))
ax.yaxis.set_minor_locator(locmin)
ax.yaxis.set_minor_formatter(matplotlib.ticker.NullFormatter())
plt.show()
有什么想法可以触发这种行为吗?
不工作图:
工作图:
更新:这是有问题的 csv 文件和重现问题的最小代码。
更新 2 Jody Klymak 指出 matplotlib.ticker.SymmetricalLogLocator() 而不是 LogLocator()。
改变了
locmin = matplotlib.ticker.LogLocator(base=10, subs=(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9), numticks = 10)
至
locmin = matplotlib.ticker.SymmetricalLogLocator(linthresh=1, base=10, subs = (0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9))
解决方案
推荐阅读
- html - 根据权限向用户显示/隐藏 django 应用程序中的选项
- excel - 突出显示单元格取决于其他单元格内容
- reactjs - react-beautiful-dnd:颠倒堆叠顺序?
- gnuplot - 在 gnuplot 中自动计算误差线
- asp.net - 如何将 Radiobuttonlist 放在 asp.net 上的一行下?
- r - 从事件指示器变量计算事件时间
- python - 测量两个长文本之间的相似性
- javascript - 在具有完整结构完整性的 JSON 树中搜索
- azure - Azure blob 存储,如何使用访问令牌访问所有文件内容
- sql - SQL Server - 如何使用循环来控制选择表中声明变量的值