1

is there any other way to change the fontsize of the scientific notation value next to the colorbar (the 10^...) other than ax.yaxis.get_offset_text().set_fontsize(24) and ax.yaxis.offsetText.set_fontsize(24) (from How to change font size of the scientific notation in matplotlib?)?

I do not know why those are not working, maybe because I created a colorbar and the colorbar axes. That is the code for the colorbar axis (my whole code is too long to post).

Thanks so much!

    fig.subplots_adjust(bottom=0.25, top=0.9, wspace=0.05)
    cbar_ax = fig.add_axes([0.2, 0.2, 0.6, 0.02])
    fmt = mpl.ticker.ScalarFormatter(useMathText=True)
    fmt.set_powerlimits((0, 0))
    cbar = fig.colorbar(cs, cax=cbar_ax, orientation='horizontal', extend="both", format=fmt)

    ## not working
    # ax.yaxis.offsetText.set_fontsize(24)
    # ax.yaxis.get_offset_text().set_fontsize(24)
random__human
  • 99
  • 2
  • 9

1 Answers1

0

ax.yaxis.offsetText.set_fontsize(24) doesn't work because ax refers to the figure axes. Something like below should work:

cbar = plt.colorbar(cs)
cbar.ax.tick_params(labelsize=24)
cbar.ax.yaxis.get_offset_text().set_fontsize(24)
math
  • 11
  • 4