【问题标题】:axhspan set limits using coordinatesaxhspan 使用坐标设置限制
【发布时间】:2014-02-06 14:50:38
【问题描述】:

是否可以使用坐标而不是值 0-1 来设置 axhspan 跨越 x 轴的距离?通常该命令需要:

axhspan(ymin, ymax, xmin=0, xmax=1, **kwargs)

我知道您可以从坐标中计算出xminxmax 的0-1 值,但这似乎是一种冗长的方法?

示例

我希望蓝色阴影范围为 0-100,白色 100-200,蓝色 200-400。

是不是通过转换为 0-1 的值或只是添加矩形形状而不是使用 axhspan() 来做到这一点的唯一方法?

【问题讨论】:

  • 您可以为 axhspan 构建一个自定义转换,将数据单位转换为图形单位。

标签: python graph colors matplotlib


【解决方案1】:

matplotlib.patches.Rectanglematplotlib.axes.Axes.add_patch 一起使用。

例如:

from pylab import *
from matplotlib.patches import Rectangle

plot(arange(0, 500), arange(0, 500))
gca().add_patch(Rectangle((100, 100), 200, 200)) # (x, y), width, height
show()

注意Rectangle构造函数的第2、3个参数分别是widthheight(不是xy位置)。

【讨论】:

    猜你喜欢
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-20
    • 2011-11-13
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多