Matplotlib:绘制离散值
我正在尝试绘制以下内容!
from numpy import *
from pylab import *
import random
for x in range(1,500):
y = random.randint(1,25000)
print(x,y)
plot(x,y)
show()
但是,我不断得到一个空白图表(?)。为了确保程序逻辑正确,我添加了代码 print(x,y)
,只是确认正在生成 (x,y) 对。
正在生成 (x,y) 对,但没有绘图,我一直得到空白图。
有什么帮助吗?
I am trying to plot the following !
from numpy import *
from pylab import *
import random
for x in range(1,500):
y = random.randint(1,25000)
print(x,y)
plot(x,y)
show()
However, I keep getting a blank graph (?). Just to make sure that the program logic is correct I added the code print(x,y)
, just the confirm that (x,y) pairs are being generated.
(x,y) pairs are being generated, but there is no plot, I keep getting a blank graph.
Any help ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,有时我通过这样做
而不是使用 pylab 取得了更好的成功,尽管在这种情况下这应该不会产生影响。
我认为您的实际问题可能是正在绘制点但不可见。使用列表一次绘制所有点可能会更好:
为了使这更简洁,您可以使用生成器表达式:
First of all, I have sometimes had better success by doing
instead of using pylab, although this shouldn't make a difference in this case.
I think your actual issue might be that points are being plotted but aren't visible. It may work better to plot all points at once by using a list:
To make this even neater, you can use generator expressions: