2016-08-06 29 views
4

Ich versuche, Farbe einige Array plotten, und einige der Werte in np.nan konvertieren (für die leichtere Interpretation) und erwartet eine andere Farbe, wenn geplottet (weiß?), Stattdessen verursacht es Problem mit der Handlung und die Farbleiste.Plot Farbe NaN Werte

#this is before converted to nan 
array = np.random.rand(4,10) 
plt.pcolor(array) 
plt.colorbar(orientation='horizontal')     

normal result

#conditional value converted to nan 
array = np.random.rand(4,10) 
array[array<0.5]=np.nan 
plt.pcolor(array) 
plt.colorbar(orientation='horizontal')     

conditional result

Jeder Vorschlag?

Antwort

4

Einer der Lösung ist maskierte Array zu zeichnen, wie hier:

import matplotlib.pylab as plt 
import numpy as np 

#conditional value converted to nan 
array = np.random.rand(4,10) 
array[array<0.5]=np.nan 
m = np.ma.masked_where(np.isnan(array),array) 
plt.pcolor(m) 
plt.colorbar(orientation='horizontal')  
plt.show() 

enter image description here