如何在matplotlib图上添加小刻度线

时间:2019-07-30 19:32:47

标签: python matplotlib plot seaborn

我想在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滴答声

1 个答案:

答案 0 :(得分:0)

您可以尝试

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