我想在我的轴实例(ax1)坐标系中的任意位置绘制一个矩形,从左到右填充渐变色。
我的第一个想法是创建一个路径补丁,并以某种方式将其填充为颜色渐变。但根据此帖子,没有一种方法可以做到这一点。
接下来我尝试使用颜色条。我使用fig.add_axes([left, bottom, width, height])
创建了第二个轴实例ax2,并向其中添加了一个颜色条。
ax2 = fig.add_axes([0, 0, width, height/8])
colors = [grad_start_color, grad_end_color]
index = [0.0, 1.0]
cm = LinearSegmentedColormap.from_list('my_colormap', zip(index, colors))
colorbar.ColorbarBase(ax2, cmap=cm, orientation='horizontal')
但是传递给 fig.add_axes()
的位置参数是在 fig 坐标系中的,与 ax1 的坐标系不匹配。
我该怎么做呢?