简体   繁体   中英

Disabling scientific notation of imshow colorbar in matplotlib

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

在此处输入图片说明

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()

But it doesn't seem to work :(

Any insights?

Thanks !!!

EDIT:

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

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM