我有一个清单:
xvalues = [1,2,3,4,5,6,7,8,9,10]
和列表:
yvalues = [n1,n2,n3,n4,n5,n6,n7,n8,n9,n10]
y值是随机的,这就是为什么它们被标记为原样。
我想将这两个列表合并为一个列表,如下所示:
xyvalues = [(1,n1),(2,n2),(3,n3),(4,n4),(5,n5),(6,n6),(7,n7),(8,n8),(9,n9),(10,n10)]
然后将它们绘制在:
之上x = numpy.linspace(0,15,100)
y = 1
plt.plot(x,y,'g')
可以这样做吗?
答案 0 :(得分:1)
你需要压缩:
xvalues = [1,2,3,4,5,6,7,8,9,10]
yvalues = ["n1","n2","n3","n4","n5","n6","n7","n8","n9","n10"]
print(zip(xvalues,yvalues))
输出:
[(1, 'n1'), (2, 'n2'), (3, 'n3'), (4, 'n4'), (5, 'n5'), (6, 'n6'), (7, 'n7'), (8, 'n8'), (9, 'n9'), (10, 'n10')]