1

I have a row vector showing x coordinates

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.

I want to make a scatter plot of this, i.e. for each x, there are 4 different y values, which I want to plot. Is there a way?

3 Answers 3

1

Thanks @User3100115

Fidgeting around I also found another solution, maybe not as efficient as @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()  
Sign up to request clarification or add additional context in comments.

Comments

0

You can do this using itertools.cycle and zip

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: enter image description here

Comments

0
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()

1 Comment

May be I wasn't clear, but each row contains the scatter, so for x=1 the scatter values are [1,2,3,4], for x=5 the scatter values are [2,3,1,4] and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.