【发布时间】:2016-10-24 20:47:49
【问题描述】:
我有一个补丁集合,我想为其显示一个颜色图。由于我在颜色图之上进行了一些操作,因此我无法使用 matplotlib.colorbar 实例来定义它。至少据我所知不是;这样做会消除我对颜色所做的一些操作,这些操作会消除缺少数据的补丁:
cmap = matplotlib.cm.YlOrRd
colors = [cmap(n) if pd.notnull(n) else [1,1,1,1]
for n in plt.Normalize(0, 1)([nullity for _, nullity in squares])]
# Now we draw.
for i, ((min_x, max_x, min_y, max_y), _) in enumerate(squares):
square = shapely.geometry.Polygon([[min_x, min_y], [max_x, min_y],
[max_x, max_y], [min_x, max_y]])
ax0.add_patch(descartes.PolygonPatch(square, fc=colors[i],
ec='white', alpha=1, zorder=4))
所以我定义了一个 matplotlib.colorbar.ColorbarBase 实例,它可以工作:
matplotlib.colorbar.ColorbarBase(ax1, cmap=cmap, orientation='vertical',
norm=matplotlib.colors.Normalize(vmin=0, vmax=1))
这会导致例如:
我遇到的问题是我想减小此颜色条的大小(具体而言,将其缩小到特定的垂直大小,例如 500 像素),但我没有看到任何明显的方法。如果我有一个colorbar 实例,我可以使用它的axis property arguments 轻松调整它,但ColorbarBase 缺少这些。
进一步参考:
【问题讨论】:
标签: python matplotlib colorbar color-mapping