matplotlibは上部と右側の境界線を削除します



Matplotlib Remove Top



方法1:

import numpy as np import matplotlib.pyplot as plt # data preparation data=np.random.rand(10,10) fig, ax=plt.subplots() data[data==-1]=np.nan# Remove the default value of -1 im =ax.imshow(data,interpolation='none',cmap='Reds_r',vmin=0.6,vmax=.9)# No interpolation # Remove border ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.spines['left'].set_visible(False) plt.show()

方法2:

メソッドはfigにパラメータを設定できません。このメソッドはオブジェクトを初期化してから、設定します。

fig = plt.figure(1, dpi = 160) ax = plt.axes() ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) plt.close(fig)

チップ:
多くのグラフィックを作成する場合は、必ずfunc:を明示的に呼び出してください。 'Pyplot.close(図)。
これは、pyplotがメモリを適切にクリーンアップできるようにするためです。