Controlling colours for NaN values with basemap

Hi,

I am trying to plot a 2D array which contains some NaN values as a map. I
would like to be able to control the colours assigned to these data points.
At the moment it seems that there are given the same colour as the highest
value in the array. Any suggestions would be appreciated. Although not using
the basemap I think this example highlights my issue

import numpy as np
import matplotlib.pyplot as plt
a = np.array([[1,2,3,np.nan,5],[4,22,np.nan,11,9]])
plt.imshow(a)
plt.show()

as you can hopefully see the NaNs are given the same colours as the highest
values in the array. Ideally I would like to give these the colour white,
regardless of what colourmap is later applied with basemap.

Many thanks

Martin

···

--
View this message in context: http://www.nabble.com/Controlling-colours-for-NaN-values-with-basemap-tp25609596p25609596.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Problem solved thanks to Jose.

For interest...

import numpy as np
import matplotlib.pyplot as plt
a = np.array([[1,2,3,np.nan,5],[4,22,np.nan,11,9]])
palette = plt.cm.jet
palette.set_bad ('w',1.0) # Bad values (i.e., masked, set to grey 0.8
A = np.ma.array ( a, mask=np.isnan(a))
plt.imshow(A,interpolation='nearest',cmap=palette)
plt.show()

mdekauwe wrote:

···

Hi,

I am trying to plot a 2D array which contains some NaN values as a map. I
would like to be able to control the colours assigned to these data
points. At the moment it seems that there are given the same colour as the
highest value in the array. Any suggestions would be appreciated. Although
not using the basemap I think this example highlights my issue

import numpy as np
import matplotlib.pyplot as plt
a = np.array([[1,2,3,np.nan,5],[4,22,np.nan,11,9]])
plt.imshow(a)
plt.show()

as you can hopefully see the NaNs are given the same colours as the
highest values in the array. Ideally I would like to give these the colour
white, regardless of what colourmap is later applied with basemap.

Many thanks

Martin

--
View this message in context: http://www.nabble.com/Controlling-colours-for-NaN-values-with-basemap-tp25609596p25612886.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Note

palette.set_bad ('w',1.0) # Bad values (i.e., masked, set to white!)

mdekauwe wrote:

···

Problem solved thanks to Jose.

For interest...

import numpy as np
import matplotlib.pyplot as plt
a = np.array([[1,2,3,np.nan,5],[4,22,np.nan,11,9]])
palette = plt.cm.jet
palette.set_bad ('w',1.0) # Bad values (i.e., masked, set to grey 0.8
A = np.ma.array ( a, mask=np.isnan(a))
plt.imshow(A,interpolation='nearest',cmap=palette)
plt.show()

mdekauwe wrote:

Hi,

I am trying to plot a 2D array which contains some NaN values as a map. I
would like to be able to control the colours assigned to these data
points. At the moment it seems that there are given the same colour as
the highest value in the array. Any suggestions would be appreciated.
Although not using the basemap I think this example highlights my issue

import numpy as np
import matplotlib.pyplot as plt
a = np.array([[1,2,3,np.nan,5],[4,22,np.nan,11,9]])
plt.imshow(a)
plt.show()

as you can hopefully see the NaNs are given the same colours as the
highest values in the array. Ideally I would like to give these the
colour white, regardless of what colourmap is later applied with basemap.

Many thanks

Martin

--
View this message in context: http://www.nabble.com/Controlling-colours-for-NaN-values-with-basemap-tp25609596p25612897.html
Sent from the matplotlib - users mailing list archive at Nabble.com.