下面的设置是我找到的 best practice 了。
plt.gca().set_axis_off()
plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0)
plt.margins(0, 0)
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.gca().yaxis.set_major_locator(plt.NullLocator())
output_name = os.path.join(outdir, img_id+"_detection.png")
plt.savefig(output_name, bbox_inches='tight', transparent=True,
pad_inches=0)
plt.clf()
要记得关掉画图 figure 或者 axis 否则会报 warning about too many open figures,参见 https://stackoverflow.com/questions/21884271/warning-about-too-many-open-figures
heat_map
should be numpy array
plt.imshow(heat_map)
plt.colorbar()
plt.show()
# img must be numpy array, not mxnet.nd
plt.imshow(img, cmap='gray')