Search code examples
pythonpython-2.7numpymatplotlibarcpy

Raster to Numpy Array - how to change a default color-scheme of a matplotlib plot


I am trying to change the default color scheme of a matplotlib plot.

So far I have the following code:

import arcpy
import matplotlib.pyplot as plt    
import matplotlib.cm 
input_Raster = arcpy.Raster( 'G:\\WetnessIndex' )
arr = arcpy.RasterToNumPyArray( input_Raster )
cm = plt.set_cmap( 'Blues' )
plt.imshow( arr )
plt.title( 'Wetness Index' )
plt.colorbar( orientation = 'vertical' )
plt.show()

The line cm = plt.get_cmap( 'blues' ) doesn't seem to make a difference like I thought it would, based on the matplotlib color_maps reference.


Solution

  • You need to pass the colour scheme you want as an argument to imshow.

    e.g.

    im = plt.imshow(arr,cmap="hot")
    

    or in your case:

    plt.imshow(arr,cmap=cm)
    

    Alternatively, you can use the set_cmap command to set the default cmap for the current figure:

    plt.set_cmap('hot')
    plt.imshow(arr)