垂直& matplotlib中的水平线 [英] vertical & horizontal lines in matplotlib

查看:127
本文介绍了垂直& matplotlib中的水平线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太明白为什么我无法在指定的限制范围内创建水平和垂直线.我想通过此框绑定数据.但是,双方似乎都不符合我的指示.为什么是这样?

I do not quite understand why I am unable to create horizontal and vertical lines at specified limits. I would like to bound the data by this box. However, the sides do not seem to comply with my instructions. Why is this?

# CREATING A BOUNDING BOX
# BOTTOM HORIZONTAL
plt.axhline(y=.4, xmin=0.25, xmax=0.402, linewidth=2, color = 'k')
# RIGHT VERTICAL
plt.axvline(x=0.402, ymin=0.4, ymax = 0.615, linewidth=2, color='k')
# LEFT VERTICAL
plt.axvline(x=0.1, ymin=0.58, ymax = 0.79, linewidth=2, color='k')
plt.show()

推荐答案

您正在调用的pyplot函数, axhline() axvline() 绘制跨越轴的一部分的线范围,无论坐标如何.参数xminymin使用值0.0作为轴的最小值,并使用1.0作为轴的最大值.

The pyplot functions you are calling, axhline() and axvline() draw lines that span a portion of the axis range, regardless of coordinates. The parameters xmin or ymin use value 0.0 as the minimum of the axis and 1.0 as the maximum of the axis.

相反,使用plt.plot((x1, x2), (y1, y2), 'k-')在颜色k中从点(x1,y1)到点(x2,y2)画一条线.参见 pyplot.plot .

Instead, use plt.plot((x1, x2), (y1, y2), 'k-') to draw a line from the point (x1, y1) to the point (x2, y2) in color k. See pyplot.plot.

这篇关于垂直& matplotlib中的水平线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆