0

My data is 2D image in format of numpy.array. By the following code:

fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(visu_base)
plt.show()

I get a color image from Python. But, how can I show it in gray level?

1 Answers1

2

The answer is in the api docs of the imshow command[1]

cmap : Colormap, optional, default: None
    If None, default to rc image.cmap value. cmap is ignored when X has RGB(A) information

imshow takes an optional parameter cmap, which controls the color mapping.

Here can find an overview of the available color mappings defined in matplotlib[2]

You could do something like that:

import matplotlib as mpl
fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(visu_base, cmap=mpl.cm.gray)
plt.show()
cel
  • 24,830
  • 16
  • 80
  • 107