我有一堆我想用matplotlib绘制的点.对于每个点(a,b),我想在[0,b]中绘制X = a的线.知道怎么做吗?
Ser*_*ndt 13
stem绘图最不麻烦的解决方案采用 matplotlib.pyplot.stem
import matplotlib.pyplot as plt
x = [1. , 2., 3.5]
y = [2.3, 4., 6.]
plt.xlim(0,4)
plt.stem(x,y)
plt.show()
Run Code Online (Sandbox Code Playgroud)
mat*_*fee 10
您只需使用两个端点绘制每一行.[0,b]中的Y的垂直线X = a具有端点(x,y)=(a,0)和(a,b).所以:
# 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()
Run Code Online (Sandbox Code Playgroud)
给出如下内容:

| 归档时间: |
|
| 查看次数: |
8902 次 |
| 最近记录: |