0

I have an array of data points of dimension n by 2, where the second dimension $2$ corresponds to the real part and imaginary part of a complex number.

Now I know the data points will intersect the unit circle on the plane for a couple of times. What I want to implement is: suppose the path starts will some color, it changes to another color when it touches the unit circle on the plane and changes color again if it intersects the unit circle again. I am not sure whether there is an easy to implement this.

Mr. T
  • 11,960
  • 10
  • 32
  • 54
user1101010
  • 187
  • 5

3 Answers3

1

You may want to try

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm

X = [1,2,3,4]
Y1 = [4,8,12,16]
Y2 = [1,4,9,16]

plt.scatter(X,Y1,color='red')
plt.scatter(X,Y2,color='blue')

plt.show()

Scatter plot 1

or try

x = np.arange(10)
ys = [i+x+(i*x)**2 for i in range(10)]

colors = cm.rainbow(np.linspace(0, 1, len(ys)))

for y, c in zip(ys, colors):
    plt.scatter(x, y, color=c)

plt.show()

Scatter Plot 2

You may also want to check out this thread as well: Setting different color for each series in scatter plot on matplotlib

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
Pam
  • 26
  • 2
0

The simplest way to do this is probably to implement the logic outside the plot, by assigning a different group to each point defined by your circle-crossing concept.
Once you have these group-indexes it's a simple plt.scatter, using the c (stands for "color") input.

Good luck!

ShlomiF
  • 2,686
  • 1
  • 14
  • 19
0

Try something along the lines of

# Import matplotlib module as plt
import matplotlib.pyplot as plt
import math

x = [3,7,1,9,5,3,5,8,math.sqrt(3)/2]
y = [4,7,8,2,3,4,5,1,1/2]
# Plot scatter Plot
for i in range(len(x)):
    if (round(x[i]**2+y[i]**2,2)) == 1: # equation of unit circle is x^2+y^2=1
        plt.scatter(x[i],y[i], color ='g',marker ='.')
    else:
        plt.scatter(x[i],y[i], color ='r',marker ='*')

plt.xlabel('x')
plt.ylabel('y')
plt.xlim([0,10])
plt.ylim([0,10])
plt.title('Scatter Plot')
plt.legend()
plt.show()

enter image description here

csg
  • 8,096
  • 3
  • 14
  • 38