我已经绘制了matplotlib.pyplot
图。我已经删除了情节的轴和标题,这样在jupyter笔记本中它看起来就像一幅图像
但我需要以所需像素分辨率将该绘图作为图像保存到本地磁盘。就我而言,是40 X 98
我已经试过了,但是我不能准确地得到测量值。我在下面提供了我的代码片段。(光谱)是我的2D阵列,它将被绘制为x轴和y轴的函数
spect = 20 * np.log10(spectrum)
fig, ax = plt.subplots(figsize=(1,1))
ax = sns.heatmap(spect,cmap='viridis',cbar=False,xticklabels=False, yticklabels=False)
ax.invert_yaxis()
plt.savefig('sample.png',bbox_inches = 'tight', pad_inches = 0)
尝试调整
savefig
中的dpi
参数。从文档中: “dpi:以每英寸点数为单位的分辨率”。 https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.savefig.html实际像素数可能因屏幕分辨率而异
有关更详细的说明,请参见以下答案: Specifying and saving a figure with exact size in pixels
相关问题 更多 >
编程相关推荐