0

I have trying to center the ticklabes in the axis using ax[].set_xticks([], minor=True) and ax1.set_xticklabels(, minor=True), but I got to hide the minor ticks, Anyone knows how to center without remove the minor ticks? or other way to center ticklabels? Thanks

fecha1 = pd.to_datetime(aca_nivel.loc[:,"Fecha"]) # Se extrae la fecha
nivel1 = aca_nivel.loc[:,"Nivel"]*100 # Se extrae el nivel 
nivel1 = nivel1-np.mean(nivel1) # bajar a cero
nivel1[nivel1<=-150] = np.nan

# Gráfica
fig, ax = plt.subplots(2, 1, figsize=(10, 5), sharey=False)

years = mdates.YearLocator()   # Cada año
months = mdates.MonthLocator()  # Cada mes
yearsFmt = mdates.DateFormatter('%Y')

ax[0].set_xlim([dt.date(2018,1,1),dt.date(2022,5,30)])
ax[0].plot(fecha1,nivel1,color="#0000FF",linewidth=0.4)
ax[0].xaxis.set_major_locator(years)
ax[0].xaxis.set_major_formatter(yearsFmt)
ax[0].xaxis.set_minor_locator(months)
ax[0].yaxis.set_minor_locator(plt.MultipleLocator(10))
ax[0].tick_params(which='major',direction="in", width=1.3, length=4.9,labelsize=7,color="k")
ax[0].tick_params(which='minor',direction="in", width=0.3, length=3.4,color="k" )
ax[0].tick_params(axis="both", colors="k")
ax[0].set_title("ACP",y=0.90,pad=-5,fontsize=10)
ax[0].set_ylabel('Heigth (cm)',fontsize=9,color="k")


ax[1].set_xlim([dt.date(2018,1,1),dt.date(2022,5,30)])
ax[1].plot(fecha1,nivel1,color="#0000FF",linewidth=0.4)
ax[1].xaxis.set_major_locator(years)
ax[1].xaxis.set_major_formatter(yearsFmt)
ax[1].xaxis.set_minor_locator(months)
ax[1].yaxis.set_minor_locator(plt.MultipleLocator(10))
ax[1].tick_params(which='major',direction="in", width=1.3, length=4.9,labelsize=7,color="k")
ax[1].tick_params(which='minor',direction="in", width=0.3, length=3.4,color="k" )
ax[1].tick_params(axis="both", colors="k")
ax[1].set_title("ACP",y=0.90,pad=-5,fontsize=10)
ax[1].set_ylabel('Heigth (cm)',fontsize=9,color="k")set_xticklabelsset_xticklabels

# Hide major tick labels
ax[1].set_xticklabels('')

    # Customize minor tick labels
    ax[1].set_xticks([dt.date(2019,6,15)], minor=True)
    ax[1].set_xticklabels(['2019'], minor=True)

enter image description here

[1]: https://i.stack.imgur.com/0XDzM.png

Miguel
  • 55
  • 6
  • See if this helps - https://matplotlib.org/stable/gallery/ticks/centered_ticklabels.html – Redox Sep 29 '22 at 03:35

0 Answers0