2012-05-17 117 views
3

我觉得我在这里丢失了一些非常明显的东西,但我无法在pylab中得到散点图以黑白打印。任何和所有的帮助将不胜感激。这里是我的代码:Python:matplotlib - 黑白分解

from pylab import * 
from random import random 
ioff() 

r = range(10) 
x = [3 + i + random() for i in r] 
y = [50*i + random() for i in r] 
x2 = [5 + i + random() for i in r] 
y2 = [5*i + random() for i in r] 

scatter(x,y, marker = 'o', hold = True, label = 'collected underwear',cmap=cm.Greys) 
scatter(x2,y2, marker = 's', hold = True, label = 'Profit!',cmap=cm.Greys) 
legend(loc='upper left') 

show() 

感谢,

亚当

+1

你的意思是你想标记的黑色? – deinonychusaur

+0

谢谢@deinonychusaur;是的,这就是我正在寻找的,或者如果可能的话,这是灰度。 –

回答

4

,如果你只是想随意指定颜色,做

color="k" 

黑色,并做

color="0.x" 

为灰度,x可以是任何数量,只要0.X之间0和1.

但是,如果您想让标记颜色由另一个阵列z确定,请执行

scatter(x,y,c=z, cmap=cm.Greys) 

所以

from pylab import * 
from random import random 
r = range(10) 
x = [3 + i + random() for i in r] 
y = [50*i + random() for i in r] 
x2 = [5 + i + random() for i in r] 
y2 = [5*i + random() for i in r] 
z2 = [i + random() for i in r] 
scatter(x,y, c="0.1", marker = 'o', hold = True, label = 'collected underwear') 
scatter(x2,y2, c=z2,marker = 's', hold = True, label = 'Profit!',cmap=cm.Greys) 
legend(loc='upper left') 
show() 

,你将有

enter image description here

+0

不错的例子,但图例颜色不匹配Profit上的标记! – deinonychusaur

+0

我想在第二个分散陈述中加入一个'color =“0.5”',但担心它会混淆OP,所以我将它剥离并保留原样。你可以明确地加入,以获得更好的插图(我刚刚做过)。 – nye17

+0

明白了!多谢你们! –

3

如果只想曲线是黑色,只需添加:

color='k' 

每个散射线,他们将黑色。不需要cmap。

编辑:

如果你想灰度图,你可以随时使用colortuples代替:直接S:

color = (0.1,0.1,0.1,1) #(r,g,b,a) 

我不知道,如果你可以用厘米。

+0

谢谢!有没有办法做一个灰度? –

+0

是的,我编辑了一个设置灰度值的方法。 – deinonychusaur