使用自定义刻度和LogNorm()时,仅显示10个标签的功率,而不是所有标签。
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
from numpy.random import random
# Make plot with horizontal colorbar
fig, ax = plt.subplots()
data = random((250,250)) + 3.5
norm = matplotlib.colors.LogNorm(vmin=0.1,vmax=10)
cax = ax.imshow(data, interpolation='nearest', cmap=cm.afmhot, norm=norm)
ax.set_title('Gaussian noise with horizontal colorbar')
cbar = fig.colorbar(cax, ticks=[0.1,0.2,0.5,1,2,5,10], orientation='horizontal')
plt.savefig("example.png")
答案 0 :(得分:2)
您必须使用format
选项:
cbar = fig.colorbar(cax, ticks=[0.1,0.2,0.5,1,2,5,10],
orientation='horizontal', format='%.1f')
这远离表示为10^n
(例如与0.5
斗争)到浮点数: