Eliminating Axes, Legends, and White Padding in Matplotlib Images
To create a clean visual representation of images in Matplotlib, removing axes, legends, labels, and any additional elements is essential. Here's how to do it:
In your example:
def make_image(inputname, outputname): data = mpimg.imread(inputname)[:,:,0] fig = plt.imshow(data) fig.set_cmap('hot') plt.axis('off') plt.savefig(outputname, bbox_inches='tight')
This code successfully removes the axes and eliminates the white padding, leaving only the desired image.
Note: In some newer versions of Matplotlib, bbox_inches='tight' has been replaced with bbox_inches=0.
The above is the detailed content of How to Remove Axes, Legends, and White Padding from Matplotlib Images?. For more information, please follow other related articles on the PHP Chinese website!