0
matplotlib:http://www.scipy.org/Cookbook/Matplotlib/HintonDiagramsでヒントダイアグラムを作成する方法に関するこの例が見つかりました。matplotlibのヒントダイアグラムをサブテンプレートに追加する際に、軸ラベルを壊さずに追加する
私はので、私はそう
import matplotlib.pyplot as plt
import numpy as N
def hintonForTwo(W1, W2, maxWeight=None):
height, width = W1.shape
if not maxWeight:
maxWeight = 2**N.ceil(N.log(N.max(N.abs(W1)))/N.log(2))
fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True, sharey=True)
hintonSubPlot(ax1, W1, maxWeight)
ax1.set_yticks(N.arange(height))
# the input matrices will have row height of 7
# and years 1981, 1986... up to 2011 are supposed to be the ytick labels
ax1.set_yticklabels(tuple(range(1981,2012,5)))
ax1.set_aspect('equal')
ax1.set_axis_off()
hintonSubPlot(ax2, W2, maxWeight)
return fig, ax1, ax2
def hintonSubPlot(F, W, maxWeight):
height, width = W.shape
F.fill(N.array([0,width,width,0]),N.array([0,0,height,height]),'white')
for x in xrange(width):
for y in xrange(height):
_x = x+1
_y = y+1
w = W[y,x]
if w > 0:
_blobAlt(F, _x - 0.5, height - _y + 0.5, min(1,w/maxWeight),'black')
elif w < 0:
_blobAlt(F, _x - 0.5, height - _y + 0.5, min(1,-w/maxWeight),'gray')
return F
def _blobAlt(F, x,y,area,colour):
hs = N.sqrt(area)/2
xcorners = N.array([x - hs, x + hs, x + hs, x - hs])
ycorners = N.array([y - hs, y - hs, y + hs, y + hs])
F.fill(xcorners, ycorners, colour, edgecolor=colour)
dim = (7,50)
X1 = N.ones(dim) * N.nan
X2 = N.ones(dim) * N.nan
rm = N.random.random(dim)
X1[rm > 2.0/3] = 1
X1[rm < 1.0/3] = -1
rm = N.random.random(dim)
X2[rm > 2.0/3] = 1
X2[rm < 1.0/3] = -1
f, a, b = hintonForTwo(X1, X2)
f.savefig('tmp.png')
のようにそれを書き直した。しかし、私は修正することはできません。このにはいくつかの問題がある目盛りのラベルで複数の図とy軸を必要:
- 場合do ax1.set_axis_off()、ytickラベルを取得できません
- 軸をオンのままにすると、下位のサブ図の周囲に大きな空白の矩形が表示されます
- 軸をオフに設定しても、アッパーsubfigと私は
は、どのように私はytickラベルを取得しますが、subfigs周囲および上部と下部との間に大きなギャップのない大きな白い長方形なくてはならないが、狭いことができます下subfigとの間に大きなギャップがありますか?
を、あなたのコードが不完全ですあなたにテスト済みの解決策を教えてください – joaquin
@joaquinコードを追加してコピー/貼り付けと実行が可能になりました。 – JasonMond