How to change the color of the scatterplot in the / if loop statement? (Python)

I am trying to make sure that if the scattering pattern for events is higher than the diatomite scattering pattern, then the plot color changes from blue to red. (Similarly, blue to yellow, if not).

I looked around for quite a while, but it doesn't seem to be working.

Here the code is as follows:

for line in open('C:\...'): line = line.split() y = line[9] if y == "END": break x = line[10] if x == 'END': break z = line[11] if z == 'END': break x0.append(float(x)) y0.append(float(y)) z0.append(float(z)) for line in open('C:\...'): line=line.split() c = line[0] a = line[1] b = line[2] a0.append(float(a)) b0.append(float(b)) c0.append(float(c)) ## print c0 Tave = average(c0) print Tave fig = pylab.figure() ax = p3.Axes3D(fig) Diatomite = ax.scatter(a0,b0,c0, color='green') Events = ax.scatter(x0, z0, y0, color='b') pyplot.show() for value in y0[:]: if value > Tave: ax.scatter(color = 'red') else: ax.scatter(color = 'yellow') scatter(color=colors) 

Any help would be greatly appreciated! (Note that I got the file path.)

+4
source share
1 answer

It looks like you have almost none. Define the colors first, then plot the scatter. So after print Tave create a list containing colors; To do this, I used the list:

 y0colors = ['red' if value > Tave else 'yellow' for value in y0] 

Then, when you create "Events", set color=y0colors , for example:

 Events = ax.scatter(x0, z0, y0, color=y0colors) 

Of course, with the requirement you are using, none of the dots will be blue. The y0 values ​​are either greater than Tave ('red') or not ('yellow'). Perhaps this will be the way to do this after defining the scatter plot of "Events", but this way seems more direct.

+5
source

All Articles