1
私は(np.asarray(vectors).T
)を表示したい行列を持っていますが、これまではすべてを除いてを除いて、画像は下部のx軸の下に多くのパディングがあります。imshow()で作成したFigureからスペーシングを削除するには?
私はtight_layout()
を使用しようとしましたが、それは全く効果がありません。私はそんなに間隔が存在しないことを正しくように私の画像を切り抜くことができますどのように
import numpy as np
import matplotlib.pyplot as plt
# Creating fake data
topn = 15
nb_classes = 13
rows = 27
columns = nb_classes * topn
labels = ['Class {:d}'.format(i) for i in range(nb_classes)]
m = np.random.random((rows,columns))
# Plotting
plt.figure()
plt.imshow(m, interpolation='none')
plt.grid(False)
plt.xlabel('Word', size=16)
plt.ylabel('Dimension', size=16)
ax = plt.gca()
ax.yaxis.set_ticks_position("right")
ax.xaxis.set_ticks_position("top")
yticks = list()
for i in range(0, nb_classes):
if i != 0:
plt.axvline(i*n - 0.5, c='w')
yticks.append((i*n - 0.5 + n/2))
plt.xticks(yticks, labels, rotation=90)
plt.tight_layout()
plt.show()
これは、結果として得られる画像(灰色の線がちょうど大きさを可視化する)である:
を
'plt.imshow'の呼び出しに' aspect = 'auto''を追加してみてください。これは、あなたの望むことですか? ([here](https://matplotlib.org/devdocs/api/_as_gen/matplotlib.axes.Axes.imshow.html) – Michael
@Michael Hm、間隔はなくなりましたが、今では各ピクセルがy軸。 – displayname
大きな空白も太い線もないようにするには、 'plt.figure(figsize =(x、y))'を試して、もっと小さな図を作ってみてください。 – Michael