0

I want to draw a scattered plot using python. I have these two 2D arrays and I want to show them in same scattered plot.

[[69, 72], [72, 80], [74, 81], [70, 75], [78, 87], [71, 73], [69, 70], [71, 77]]
[[78, 139], [80, 158], [85, 154], [72, 105], [84, 148], [74, 87], [73, 106], [71, 109]]

How can I do this? I want points of different arrays to be of different colors. I'm using python 3.x

1 Answer 1

1

You can use Matplotlib scatter tool to graph your points. Here is how you'll do it, applying their example:

import matplotlib.pyplot as plt
import matplotlib    

array1 = [[69, 72], [72, 80], [74, 81], [70, 75], [78, 87], [71, 73], [69, 70], [71, 77]]
array2 = [[78, 139], [80, 158], [85, 154], [72, 105], [84, 148], [74, 87], [73, 106], [71, 109]]

x1 = [point[0] for point in array1]
y1 = [point[1] for point in array1]
x2 = [point[0] for point in array2]
y2 = [point[1] for point in array2]
s = 20

plt.scatter(x1, y1, s, c="r", alpha=0.5, marker=r'o',
            label="Array 1")
plt.scatter(x2, y2, s, c="b", alpha=0.5, marker=r'o',
            label="Array 2")
plt.xlabel("X")
plt.ylabel("Y")
plt.legend(loc=0)
plt.show()

This will give you this nice looking graph:

Scatter Plot

Sign up to request clarification or add additional context in comments.

Comments

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.