Matplotlib:从x轴到点画线 [英] Matplotlib: Draw lines from x axis to points
本文介绍了Matplotlib:从x轴到点画线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想尝试使用matplotlib绘制很多点.对于每个点 (a,b),我想在 [0,b] 中为 Y 绘制线 X = a.任何想法如何做到这一点?
I have a bunch of points that I am trying to plot using matplotlib. For each point (a,b) I want to draw the line X = a for Y in [0,b]. Any idea how to do this?
推荐答案
您只需使用两个端点绘制每条线.[0,b]中Y的垂直线X = a具有端点(x,y)=(a,0)和(a,b).所以:
You just draw each line using the two endpoints. A vertical line X=a for Y in [0,b] has endpoints (x,y) = (a,0) and (a,b). So:
# make up some sample (a,b): format might be different to yours but you get the point.
import matplotlib.pyplot as plt
points = [ (1.,2.3), (2.,4.), (3.5,6.) ] # (a1,b1), (a2,b2), ...
plt.hold(True)
plt.xlim(0,4) # set up the plot limits
for pt in points:
# plot (x,y) pairs.
# vertical line: 2 x,y pairs: (a,0) and (a,b)
plt.plot( [pt[0],pt[0]], [0,pt[1]] )
plt.show()
给出以下内容:
这篇关于Matplotlib:从x轴到点画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文