2016-05-10 5 views
0

matplotlibとcolorbarについて質問があります。私は自分のプロジェクトでヒートマップをたくさん持っています。私の配列は、2つの配列の間の割り算の結果であると仮定します。 (問題を可視化するために)データのカラーバーを設定する

例えば

import numpy as np 
import matplotlib as plt 

array_1 = A/B # A and B are 2 arrays, same shape etc .. 
array_2 = C/D # C and D are 2 arrays, same shape etc .. 

################################## 
# Representation with matplotlib # 
################################## 

fig_step1 = ax1.imshow(array_1, interpolation='nearest') 
fig1.colorbar(fig_step1,ax=ax1) 
ax1.set_xlabel("X (arcmin)") 
ax1.set_ylabel("Y (arcmin)") 
ax1.set_title("array number 1") 

fig_step2 = ax2.imshow(array_2, interpolation='nearest') 
fig1.colorbar(fig_step2,ax=ax2) 
ax2.set_xlabel("X (arcmin)") 
ax2.set_ylabel("Y (arcmin)") 
ax2.set_title("array number 2") 

==>しかし、除算は、私のデータの99%のために良いですし、私はarray_1から平均値を取得した場合でもarray_2はarount値1など。時にはA/Bの結果が1000000であり、カラーバーを間違えるような点(1%)がありません。

==>ヒートマップで印刷するためにカラーバーで再生するにはどうすれば[0; 1]の間のポイントにすることができますか?つまり、ダイナミックなカラーバーを持つことですか?

私は非常に悪い英語のために謝罪:/

ありがとうございました!

答えて

1

私は2つの解決策があることを推測する:imshowvminvmax引数を設定したり、配列内の無効な値をマスクのいずれかで。その結果

import numpy as np 
import matplotlib.pylab as plt 

A = np.random.random((20,20)) 
B = np.random.random((20,20)) 

array_1 = A/B # A and B are 2 arrays, same shape etc .. 

fig1 = plt.figure() 
ax1 = plt.subplot(121) 
fig_step1 = ax1.imshow(array_1, interpolation='nearest') 
fig1.colorbar(fig_step1,ax=ax1) 
ax1.set_xlabel("X (arcmin)") 
ax1.set_ylabel("Y (arcmin)") 
ax1.set_title("Without limits") 

ax2 = plt.subplot(122) 
fig_step2 = ax2.imshow(array_1, interpolation='nearest', vmin=0, vmax=1) 
fig1.colorbar(fig_step2, ax=ax2) 
ax2.set_xlabel("X (arcmin)") 
ax2.set_ylabel("Y (arcmin)") 
ax2.set_title("With limits") 

:あなたは無効な値をマスクしたい場合は、 enter image description here

か(1より大きいすべてが無効であると仮定して):

:その結果

import numpy as np 
import matplotlib.pylab as plt 

A = np.random.random((20,20)) 
B = np.random.random((20,20)) 

array_1 = A/B # A and B are 2 arrays, same shape etc .. 

# Mask the array with the required limits 
array_1 = np.ma.masked_where(array_1 > 1, array_1) 

fig1 = plt.figure() 
ax1 = plt.subplot(111) 
fig_step1 = ax1.imshow(array_1, interpolation='nearest') 
fig1.colorbar(fig_step1,ax=ax1) 
ax1.set_xlabel("X (arcmin)") 
ax1.set_ylabel("Y (arcmin)") 
ax1.set_title("No limits, but masked") 

enter image description here

+0

よりあなたの答えにks。私は 'vmin'と' vmax'で解を試してみます。私の場合、マスクは使用できません。私が 'np.ma.masked.greater'で試しても – Deadpool

関連する問題