【问题标题】:Major and minor grid lines and ticks using matplotlib使用 matplotlib 的主要和次要网格线和刻度
【发布时间】:2014-08-18 08:42:17
【问题描述】:

我有两个大整数

min=round(raw_min,-5) # a negative number
max=round(raw_max,-5)

从中我得到了一系列有趣的滴答声:

xticks=np.arange(min,max,500000)

在 x 轴上,我希望在 xticks 范围内有小刻度(包括标签)。此外,我希望在值0 处有一个主要的刻度线和网格线。我尝试添加:

minorLocator = FixedLocator(xticks)
majorLocator = FixedLocator([0])

ax.xaxis.set_major_locator(majorLocator)
ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
ax.xaxis.set_minor_locator(minorLocator)
plt.tick_params(which='both', width=1)
plt.tick_params(which='major', length=7, color='b')
plt.tick_params(which='minor', length=4, color='r')
ax.yaxis.grid(True)
ax.xaxis.grid(b=True,which='major', color='b', linestyle='-')

但它不起作用......

次要没有刻度,主要没有网格线。

有什么想法吗?

【问题讨论】:

  • “不起作用”意味着根本没有图表?没有蜱虫?蜱虫在错误的地方?没有网格线?

标签: python matplotlib


【解决方案1】:

好像我错过了以下行:

plt.grid(b=True,which='both')

【讨论】:

    猜你喜欢
    • 2018-06-03
    • 2020-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-27
    • 1970-01-01
    相关资源
    最近更新 更多