I am trying to use python to create and save a heatmap. these lines of code do it.
import numpy as np; np.random.seed(0) import seaborn as sns; sns.set_theme() uniform_data = np.random.rand(10, 12) ax = sns.heatmap(uniform_data, xticklabels=False, yticklabels=False, cbar=False) ax.figure.savefig('image.png') My problem occurs when I try to load the image. I am using pillow for that.
from PIL import Image Image.open('image.png') It opens the image, but it adds some white pixels on each side of it, so that when you open with jupyterLab you can see the gap between the two images. The original is at the limit with the top and bottom cells, while the one that was saved before and then reloaded is right in the middle of the screen. I also see some white pixels on each side of the image when I open it with Preview (default image viewer on mac).
How could I only save the heat map without adding any white pixel around it ? Any hints will be welcome, thanks.
https://stackoverflow.com/questions/66020267/how-to-only-save-the-image-without-adding-white-pixels-on-each-side-of-it February 03, 2021 at 10:06AM
没有评论:
发表评论