0

I couldn't find any answer to this specific case. Say I want to create a scatter plot from the following data:

y = np.array([[1,2,3,6,5,3,4,2],[1,2,4,5,5,3,3,2]])
X = np.array([[86],[82]])

Where all the values of y[0] are the correseponding values of X[0] (86) and so on. I know I can just use numpy repeat function but I thought maybe there's any other more feasilbe option? I've tried to reshape the any of the arrays but it didn't help. Any ideas?

1
  • Transpose the y data Commented Jul 12, 2020 at 15:14

2 Answers 2

1

I really like the tile function from numpy. I dont think there is a way around of "enlarging" X[i] to make it match the length of y[i]

import numpy as np
import matplotlib.pyplot as plt

y = np.array([[1,2,3,6,5,3,4,2],[1,2,4,5,5,3,3,2]])
X = np.array([[86],[82]])

for i in range(len(X)):
    plt.plot(np.tile(X[i], len(y[i])), y[i], '.')
Sign up to request clarification or add additional context in comments.

Comments

1

You don't need to do much. Matplotlib treats each column of your data as a separate, broadcastable dataset. So all you need to do is transpose your inputs and let it do its magic.

plt.scatter(x.T, y.T)

1 Comment

Thank you. Although i have tried it already. I get an error x and y must be the same size :(

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.