【发布时间】:2014-07-26 23:33:30
【问题描述】:
我想在我的坐标区实例 (ax1) 坐标系中任意尺寸的任意位置绘制一个矩形,从左到右填充渐变颜色。
我的第一个想法是创建一个路径补丁并以某种方式将其填充设置为颜色渐变。但根据THIS POST 的说法,没有办法做到这一点。
接下来我尝试使用颜色条。我使用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的坐标系不匹配。
我该怎么做?
【问题讨论】:
-
我从不使用它,但也许这可以帮助您重新计算从 ax1 到 fig 的坐标:Transformations Tutorial — Matplotlib 1.3.1 documentation
标签: python matplotlib