Python Matplotlib:打印离散值

Python Matplotlib:打印离散值,python,matplotlib,data-visualization,Python,Matplotlib,Data Visualization,我正试图策划以下内容 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)对正在生成,但没有绘图,我一直得到一个空白图

我正试图策划以下内容

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)对正在生成,但没有绘图,我一直得到一个空白图


有什么帮助吗

首先,我有时通过做一些事情来获得更好的成功

from matplotlib import pyplot
而不是使用pylab,尽管在这种情况下这不会有什么不同

我认为您的实际问题可能是正在绘制点,但不可见。使用列表一次绘制所有点可能效果更好:

xPoints = []
yPoints = []
for x in range(1,500):
    y = random.randint(1,25000)
    xPoints.append(x)
    yPoints.append(y)
pyplot.plot(xPoints, yPoints)
pyplot.show()
要使其更加整洁,可以使用生成器表达式:

xPoints = range(1,500)
yPoints = [random.randint(1,25000) for _ in range(1,500)]
pyplot.plot(xPoints, yPoints)
pyplot.show()

阿卡帕拉沃,我对公认的答案没有问题;我只想提到这个五行模板:从matplotlib导入pyplot作为PLT;图=PLT.figure();ax1=图add_子批次(111);ax1.绘图(x,y);PLT.show()是一种在98%的时间内获得工作x-y图的快速方法。('x','y'是列表或1D Numpy数组,顺便说一句)。@doug:你可以用一种更简单的方法做同样的事情:
从matplotlib导入plt的pyplot;plt.图(x,y);plt.show()
@doug:谢谢。。。我接受了Daniel G的回答,因为它立即解决了我所有的问题!…:)。。太糟糕了,无法选择2个答案+1对于“导入pyplot”——显然对于那些以前的Matlab用户来说,pylab是一个巨大的便利,但是在文档、示例等中这两种方言几乎可以互换使用,这使得Matplotlib非常出色,对我来说更难学习。非常感谢各位!我想我上一次接触matplotlib是在2009年10月,当时我需要在2010年4月再次接触matplotlib。yPoints=list(map(lambda:random.randint(125000),xPoints))并且不需要跟踪额外的变量。