如何更改循环/if 语句中散点图的颜色? (Python)
我试图做到这一点,如果事件的散点图位于硅藻土散点图之上,则图的颜色从蓝色变为红色。 (如果不是的话,同样从蓝色到黄色)。
我已经环顾四周很长一段时间了,但似乎不起作用。
代码如下:
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)
任何帮助将不胜感激! (请注意,我取出了文件的路径。)
I'm trying to make it so that if the scatterplot for Events is above the Diatomite scatterplot, then the color of the plot changes from blue to red. (Similarly from blue to yellow if otherwise).
I've looked around for quite some time, but it doesn't seem to be working.
Here's the code 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!
(Please note that I took out the path to the file.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来你几乎已经拥有它了。首先定义颜色,然后绘制散点图。因此,在
print Tave
之后,构建一个包含颜色的列表;我使用列表理解来执行此操作:然后,当您创建“事件”时,设置
color=y0colors
,如下所示:当然,根据您使用的要求,所有点都不会是蓝色的。 y0 值要么大于 Tave(“红色”),要么大于 Tave(“黄色”)。在定义散点图“事件”之后可能有一种方法可以做到这一点,但这种方法似乎更直接。
It looks like you almost have it. First define the colors, then make the scatter plot. So after
print Tave
, build a list containing the colors; I used a list comprehension to do this:Then when you make 'Events', set
color=y0colors
, like so:Of course with the requirement that you're using, none of the points will be blue. The y0 values are either greater than Tave ('red') or not ('yellow'). There might be a way to do this after defining the scatter plot 'Events', but this way seems more direct.