matplotlib の imshow を使用して、Python でカーペットプロットを作成しています。これが私のコードです:
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.cm as cm
DATA = np.array([[0,0,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 9,0,0,1,2,4,5,5,4,3,2,0],[ 0,0,0,1,2,4,5,5,4,3,2,0],[ 0,0,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0],[ 0,3,0,1,2,4,5,5,4,3,2,0] ])
#plt.imshow(DATA, interpolation='nearest', cmap=cm.bwr)
DATA.shape
fig = plt.figure(figsize=(5.5,6),dpi=300)
ax = fig.add_subplot(111)
plot = ax.imshow(DATA, interpolation='nearest', cmap=cm.rainbow)
cb = fig.colorbar(plot)
xlabel = ax.set_xlabel('Days')
ylabel= ax.set_ylabel('bla bla bla')
fig.savefig('carpet_test.png',bbox_extra_artists=[xlabel], bbox_inches='tight')
出力は次のとおりです。
しかし、DATA を短縮して同じコードを使用すると、出力は次のようになります。
1 と 2 の唯一の違いは の長さですDATA
。問題は、各ピクセルまたはポイントが同じ幅と高さになるように、figsize
使用されたをどのように計算できるかということです。plt.figure
DATA
グラフの幅は常に同じでなければならず、幅はDATA
変わらず、高さだけです。