Python: matplotlib - Black and White Scattering

I feel like I'm missing something very obvious here, but I can't get the scatter chart in pylab to print in black and white. Any help would be greatly appreciated. Here is my code:

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()

Thank,

Adam

+3
source share
2 answers

if you just want to specify the color arbitrarily, do

color="k"

for black, and do

color="0.x"

for shades of gray, xcan be any number if 0.x is between 0 and 1.

But if you want the marker color to be determined by another array z, do

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

therefore for

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()

you will have

enter image description here

+4
source

If you want the curves to be black just add:

color='k'

each scatter line, and they will be black. No need for cmap.

Edit:

, :

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

, cm: s.

+3

All Articles