Search code examples
pythonmatplotlibcolorbarimshow

Disabling scientific notation of imshow colorbar


For some reason, I can't find a way to turn off the scientific notation of the colorbar for the following plot:

enter image description here

I've tried using powerlimits:

ylabels = ['0:00', '03:00', '06:00', '09:00', '12:00', '15:00', '18:00', '21:00']

fig, ax = plt.subplots(figsize=(27, 7))

cax1 = ax.imshow(df7, origin='lower', cmap='viridis', interpolation='none', aspect=4)
ax.set_xticklabels(label, fontsize = 12)
plt.xticks(np.arange(len(df7.columns)))

major_ticks = np.arange(0, 24, 3)
ax.set_yticks(major_ticks)
ax.set_yticklabels(ylabels, fontsize = 12)


fig.autofmt_xdate()


cb = plt.colorbar(cax1,fraction=0.046, pad=0.04)
cb.formatter.set_powerlimits((0, 8))
cb.update_ticks

plt.tight_layout()

ax.set_aspect(0.5)
fig.suptitle('November 2016 Normalized Pressure Data $[mbar]$',fontsize=15)
fig.tight_layout(pad = 1)

plt.show()

I've seen the similar question about formatting the colorbar, but here the question is how to format it for disabling the scientific notation!


Solution

  • Found the solution myself:

    using these lines:

    fmt = '%1.2f'
    cb = plt.colorbar(cax1,fraction=0.046, pad=0.04, format = fmt)
    

    and removing the line:

    cb.formatter.set_powerlimits((0, 8))