简体   繁体   English

Python:以矩阵形式存储的数据散点图

[英]Python: Scatter plot of data stored in matrix form

I have a row vector showing x coordinates 我有一个显示x坐标的行向量

x=[1,5,7,3]

and I have a matrix 我有一个矩阵

y=[[1,2,3,4],[2,3,1,4],[1,2,2,1],[2,3,1,1]]

whose rows represent the scatter of a variable at the corresponding x coordinate. 其行代表变量在相应x坐标处的分散。

I want to make a scatter plot of this, ie for each x, there are 4 different y values, which I want to plot. 我要对此进行散点图绘制,即对于每个x,我要绘制4个不同的y值。 Is there a way? 有办法吗?

Thanks @User3100115 谢谢@ User3100115

Fidgeting around I also found another solution, maybe not as efficient as @User3100115 闲逛的我也找到了另一种解决方案,也许不如@ User3100115高效

x=[1,5,7,3]
y=[[1,2,3,4],[2,3,1,4],[1,2,2,1],[2,3,1,1]]

er=np.ones(4)
k=0
while k<4:
     e=x[k]*er
     plt.scatter(e,y[k])
     plt.draw()
     k+=1
plt.show()  
import matplotlib.pyplot as plt

x=[1,5,7,3]
y=[[1,2,3,4],[2,3,1,4],[1,2,2,1],[2,3,1,1]]

for yy in y:
    plt.scatter(x,yy)

plt.show()

You can do this using itertools.cycle and zip 您可以使用itertools.cyclezip执行此操作

from itertools import cycle

import matplotlib.pyplot as plt

x = [1,5,7,3]
y = [[1,2,3,4], [2,3,1,4], [1,2,2,1], [2,3,1,1]]
for i in zip(x, y):
    b = zip(*(zip(cycle([i[0]]), i[1])))
    plt.scatter(*b)

plt.show()

Then your plot looks like this: 然后您的情节看起来像这样: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM