在颜色条中裁剪扩展标记
Crop extended marker in colorbar
我不得不在使用 contourf
时使用 extend='min'
来为低于我给定范围的值(负值)着色。请问如何裁剪这个扩展标记(箭头所指)
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(5,5))
ax = plt.contourf(x, y, z, cmap='Spectral', vmin=0, vmax=60, norm=norm, extend='min')
# colorbar
cax = fig.add_axes([.918, 0.175, 0.045, 0.6])
cb = fig.colorbar(ax, cax=cax)
然后变成这样
谢谢
您可以使用此代码:
bounds = [5*i for i in range(13)]
cax = fig.add_axes([.918, 0.175, 0.045, 0.6])
fig.colorbar(mpl.cm.ScalarMappable(cmap = 'Spectral', norm = norm),
cax = cax,
ticks = bounds,
boundaries = [0] + bounds[1:-1] + [60])
我不得不在使用 contourf
时使用 extend='min'
来为低于我给定范围的值(负值)着色。请问如何裁剪这个扩展标记(箭头所指)
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(5,5))
ax = plt.contourf(x, y, z, cmap='Spectral', vmin=0, vmax=60, norm=norm, extend='min')
# colorbar
cax = fig.add_axes([.918, 0.175, 0.045, 0.6])
cb = fig.colorbar(ax, cax=cax)
然后变成这样
谢谢
您可以使用此代码:
bounds = [5*i for i in range(13)]
cax = fig.add_axes([.918, 0.175, 0.045, 0.6])
fig.colorbar(mpl.cm.ScalarMappable(cmap = 'Spectral', norm = norm),
cax = cax,
ticks = bounds,
boundaries = [0] + bounds[1:-1] + [60])