1

I have to make the following scatterplot in python. The code for this plot is :

n = 1024
X = np.random.normal(0,1,n)
Y = np.random.normal(0,1,n)

plt.scatter(X,Y)

Scatterplot

But as espected, this wont give the colours. I've tried a lot, but can't find the solution. I know it has something to do with the angle of X/Y in the plot, but can't find out how to do this.

3
  • 1
    What is the logic behind the coloring? Commented Feb 1, 2018 at 15:12
  • @alec_djinn It is from an exercise I have to do... Don't know the logic either, just have to find out on how to do this Commented Feb 1, 2018 at 15:14
  • So, are you asking how to use color gradients with scatter plots on maptplotlib or what? Commented Feb 1, 2018 at 15:27

1 Answer 1

4

The logic is most likely angle from origo to point. This can be calculated easily with np.arctan2(X, Y). I don't know which colormap that is used in your example but you can probably find it here: https://matplotlib.org/examples/color/colormaps_reference.html

Use the angles of the points to the c keyword in plt.scatter

To get something similar to your example: plt.scatter(X,Y, c=np.arctan2(X, Y), cmap='rainbow', s=50, alpha=0.8)

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.