如何将 savefig(seaborn 热图)创建的图像大小更改为 1000*1000 px?
How to change the size of image created by savefig (seaborn heatmap ) to 1000*1000 px?
正在尝试更改绘图的大小。但是某处发生泄漏,图像不是 1000x1000 而是 775x770 像素。我知道垫子收紧了身材。我希望这个数字是 1000x1000,没有边缘、边框等
w = 1000
h = 1000
plt.figure(figsize=(w/1000,h/1000), dpi=100)
sn.heatmap(depthnp, xticklabels=False, yticklabels=False,
center=default, cmap=self.cmap, cbar=False)
plt.savefig('tempFile.png', dpi=1000, bbox_inches='tight',pad_inches = 0)
有没有办法让它符合预期的大小?
plt.subplots_adjust(left=0, bottom=0, right=1, top=1)
会减少空格。 plt.axis('off')
关闭轴。
另请注意,figsize=(1,1)
在处理文本时可能会产生奇怪的结果。 figsize=(10,10)
和 plt.savefig(..., dpi=100)
可以更好地工作。
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from scipy.ndimage import gaussian_filter
w = 1000
h = 1000
plt.figure(figsize=(w / 100, h / 100))
ax = sns.heatmap(gaussian_filter(np.random.rand(50, 50), 5), xticklabels=False, yticklabels=False, cbar=False)
plt.subplots_adjust(left=0, bottom=0, right=1, top=1)
plt.axis('off')
plt.savefig('tempFile.png', dpi=100, pad_inches=0)
正在尝试更改绘图的大小。但是某处发生泄漏,图像不是 1000x1000 而是 775x770 像素。我知道垫子收紧了身材。我希望这个数字是 1000x1000,没有边缘、边框等
w = 1000
h = 1000
plt.figure(figsize=(w/1000,h/1000), dpi=100)
sn.heatmap(depthnp, xticklabels=False, yticklabels=False,
center=default, cmap=self.cmap, cbar=False)
plt.savefig('tempFile.png', dpi=1000, bbox_inches='tight',pad_inches = 0)
有没有办法让它符合预期的大小?
plt.subplots_adjust(left=0, bottom=0, right=1, top=1)
会减少空格。 plt.axis('off')
关闭轴。
另请注意,figsize=(1,1)
在处理文本时可能会产生奇怪的结果。 figsize=(10,10)
和 plt.savefig(..., dpi=100)
可以更好地工作。
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from scipy.ndimage import gaussian_filter
w = 1000
h = 1000
plt.figure(figsize=(w / 100, h / 100))
ax = sns.heatmap(gaussian_filter(np.random.rand(50, 50), 5), xticklabels=False, yticklabels=False, cbar=False)
plt.subplots_adjust(left=0, bottom=0, right=1, top=1)
plt.axis('off')
plt.savefig('tempFile.png', dpi=100, pad_inches=0)