2016-08-06 18 views
4

私は色をいくつかの配列にプロットしようとしていて、値の一部をnp.nan(解釈しやすいように)に変換してプロットしたとき(白?)、カラーバー。プロットの色NaNの値

#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

任意の提案?

答えて

4

解決策の一つは、ここのように、マスクされた配列をプロットすることである。

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

関連する問題