Python: matplotlib - Black and White Scatter

matplotlib, python

Solution

if you simply want to specify the color arbitrarily, do

color="k"

for black, and do

color="0.x"

for greyscale, `x` could be any number as long as 0.x is between 0 and 1.

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

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

so 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

Problem

I feel like I'm missing something very obvious here, but I can't get a scatter plot in pylab to print in black and white. Any and all help would be greatly appreciated. Here's 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() ``` Thanks, Adam

Original source