在 Matlab 中保存没有轴、图例或标题的图形
Saving a figure without axes, legend or title in Matlab
我正在使用 matlab 将信号转换为频谱图,然后将其另存为 png 图像文件。
这是我目前拥有的:
我希望只有情节,没有边框、坐标轴或图例。
(奖金问题:如何获得灰度频谱图?)
这是我使用的代码:
for index = 1:Nb_Samples
%Loads the data from the current example
Time_Data = Data4{1,index}.time;
Signal_Data = Data4{1,index}.values;
figure(1)
%Generates the spectrogram for the current example
spectrogram(Signal_Data,hamming(CustomHammingWindowSize1),CustomHammingWindowSize1/2,(PatchWindowSize^2-1)*2,1000,'yaxis')
h=gcf;
set(h,'PaperPositionMode','auto');
set(h,'PaperOrientation','landscape');
set(h,'Position',[20 20 1100 700]);
print(gcf, '-dpng', 'Spectro.png')
end
最好的方法是直接保存数据,而不是绘制它,例如使用 imwrite
,因为您用来绘制的任何东西都必须是 NxM 矩阵,即图像。
正如@CrisLuengo 在评论中所说,只需获取 spc=spectogram(...
输出,将其缩放到 [0-1] 并使用 imwrite
保存以获得最佳结果。
对于这种情况,我不推荐它,但您始终可以 colormap(gray)
、axis off
好吧,只是不要调用 colorbar
(或 colorbar('off')
),以去掉图中多余的东西。但是做好科学!妥善保存数据,不要通过添加额外的绘图步骤引入伪影。
我正在使用 matlab 将信号转换为频谱图,然后将其另存为 png 图像文件。
这是我目前拥有的:
我希望只有情节,没有边框、坐标轴或图例。
(奖金问题:如何获得灰度频谱图?)
这是我使用的代码:
for index = 1:Nb_Samples
%Loads the data from the current example
Time_Data = Data4{1,index}.time;
Signal_Data = Data4{1,index}.values;
figure(1)
%Generates the spectrogram for the current example
spectrogram(Signal_Data,hamming(CustomHammingWindowSize1),CustomHammingWindowSize1/2,(PatchWindowSize^2-1)*2,1000,'yaxis')
h=gcf;
set(h,'PaperPositionMode','auto');
set(h,'PaperOrientation','landscape');
set(h,'Position',[20 20 1100 700]);
print(gcf, '-dpng', 'Spectro.png')
end
最好的方法是直接保存数据,而不是绘制它,例如使用 imwrite
,因为您用来绘制的任何东西都必须是 NxM 矩阵,即图像。
正如@CrisLuengo 在评论中所说,只需获取 spc=spectogram(...
输出,将其缩放到 [0-1] 并使用 imwrite
保存以获得最佳结果。
对于这种情况,我不推荐它,但您始终可以 colormap(gray)
、axis off
好吧,只是不要调用 colorbar
(或 colorbar('off')
),以去掉图中多余的东西。但是做好科学!妥善保存数据,不要通过添加额外的绘图步骤引入伪影。