如何在Python中绘制我的目的图?
在Python中,我想使用:从 pylab 导入*
然后使用该模块中提供的plot
。然而,我绘制的曲线不是我想要的:
说出两个列表:x = [1, 2, 3, 4]
y = [1.4, 5.6, 6, 3.5]
我正在寻找一种可以绘制以下图表的绘图方法:
绘制一条连接点的线:(1, 0)
和 (1, 1.4)
绘制一条连接点的线:(2, 0)
和 (2, 5.6)
绘制一条连接点的线:(3, 0)
和 (3, 6)
绘制一条连接点的线:(4, 0)
和 (4, 3.5)
...
即:它应该像图形一样绘制光谱,例如R
中的plot(x, type='h')
。我想我使用的绘图方法只是通过线连接所有点。那么,就我的目的而言,请选择哪些方法?谢谢!!
in python, I would like to use:from pylab import *
Then use plot
provided in this module. However, the curves I plot were not what I want:
Say two lists:x = [1, 2, 3, 4]
y = [1.4, 5.6, 6, 3.5]
and I am after a plot method that can plot the following chart:
Plot a line that joins the points: (1, 0)
and (1, 1.4)
Plot a line that joins the points: (2, 0)
and (2, 5.6)
Plot a line that joins the points: (3, 0)
and (3, 6)
Plot a line that joins the points: (4, 0)
and (4, 3.5)
...
i.e.: it should plot a spectra like graphs, such as plot(x, type='h')
in R
. I suppose the plot method I use just joins all the points by lines. So, for my purpose, which methods to choose please? thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您只想要垂直线?您可以使用
vlines(x, [0], y)
。请参阅此 示例您还可以查看此 页面(屏幕截图)可帮助您选择正确的函数。
Maybe you want just vertical lines? You could use
vlines(x, [0], y)
. See this exampleYou could also have a look at this page (screenshots) to help you select the right function.
您是指条形图吗?如果是这样,只需使用
bar
函数:Do you mean a bar chart? If so, just use the
bar
function: