3

I want to add minor ticks on the y axis. I tried several methods but they all seem to not work. The minor ticks just won't show up. Here is my code.

 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)

I would like to get both the major and minor y ticks at the end of the plot

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
moinabyssinia
  • 163
  • 1
  • 2
  • 9

1 Answers1

6

You can try this

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

If you want to disable the minor ticks on the x-axis, you can do

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

Based on @spinup's answer: how to turn on minor ticks only on y axis matplotlib