Skip to content Skip to sidebar Skip to footer

How To Plot Gray Level Image By Matplotlib.pyplot.imshow?

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.

Solution 1:

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

cmap : Colormap, optional, default: None
    If None, defaultto 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 mplfig= plt.figure()
ax = fig.add_subplot(111)
ax.imshow(visu_base, cmap=mpl.cm.gray)
plt.show()

Post a Comment for "How To Plot Gray Level Image By Matplotlib.pyplot.imshow?"