仅在某些图形上缺少小刻度

时间:2019-04-30 14:41:13

标签: python-3.x dataframe matplotlib

我的代码提取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()

有什么想法可以触发这种行为?

无效图形:
Not working graph

工作图:
The working graph

更新:这是有问题的csv文件和用于重现此问题的分钟代码。

Data

Script

更新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))

0 个答案:

没有答案
相关问题