matplotlib 如何添加次要ticks

9fkzdhlc  于 2023-10-24  发布在  其他
关注(0)|答案(1)|浏览(106)

我想在y轴上添加次要刻度。我尝试了几种方法,但它们似乎都不起作用。次要刻度就是不显示。下面是我的代码。

sns.set_style('whitegrid')
    dd.plot(x='Date', y='Min', lw = 4, figsize=(50,30), color = 'red')
    plt.grid(color = 'grey')
    dd['P05'].plot(lw = 2)
    dd['P10'].plot(lw = 2)
    dd['P25'].plot(lw = 2)
    dd['P50'].plot(lw = 2)
    dd['P75'].plot(lw = 2)
    dd['P90'].plot(lw = 2)
    dd['P95'].plot(lw = 2)
    dd['Max'].plot(lw = 4, color = 'black')
    plt.xticks(np.arange(0,366, step=31), list(monthDict.values()),\
               fontsize = 35, fontname = 'Consolas')
    plt.yticks(fontsize = 35)
    plt.ylabel('Daily Average Stage (ft NGVD29)', fontsize = 35, \
               labelpad = 25,fontname = 'Consolas', color = 'black')
    plt.xlabel('') #remove xlabel
    plt.legend(prop={'family':'Consolas', 'size':35})
    # plt.legend(['5th Pecrentile', '10th percentile', '25th percentile', \
    #             '50th percentile', '75th percentile', '90th percentile', \
    #             '95th percentile', '99th percentile'])
    plt.title('Cyclic Analysis at {}-H'.format(x),\
              fontsize = 55, fontname='Consolas', color = 'black')
    ax.minorticks_on()
    ax.tick_params(axis='y', which='minor', bottom=False)

我想在图的最后得到大调和小调的y刻度

hfwmuf9z

hfwmuf9z1#

你可以试试这个

ax.yaxis.get_ticklocs(minor=True)
ax.minorticks_on()

如果要禁用x轴上的次要刻度,

ax.xaxis.set_tick_params(which='minor', bottom=False)

基于@spinup的回答:how to turn on minor ticks only on y axis matplotlib

相关问题