我正在尝试在灰度图像上绘制一些温度数据,温度数据使用色标显示。我已经能够通过在图像数据上覆盖部分透明的数据和温度数据来实现。当我尝试将其保存为tiff(或jpeg)时出现问题。虽然颜色条(对于温度数据)完全按照Matlab图中的预期显示,但当我将其保存为tiff时,颜色条呈空(纯白色)。有任何想法吗?
figure
imagesc(xlims, ylims, image_data)
set(gca,'YDir','normal');
colormap(gray)
title(title)
xlabel('xlabel')
ylabel('ylabel')
hold on
axis equal
axis tight
%Skip lines of code where I build my temperature array (T) here
%Force a single pixel to 2200
T(1,1)=2200;
%Remove any data below 1000
T(T<1000)=0;
% Establish Transparency Mask for Temperature Data
transp = T~=0; % Binary matrix highlighting where temp data exists
% Overlay Temp Data on Background Image
imagesc(xlims, ylims, T,'AlphaData',transp)
% Create Colormaps and Combine Them
% Note: Assumes no overlap between background image values and temp data
% (highest value in background image is 73)
cmap1 = colormap(gray(73));
cmap2 = colormap(gray(999-73));
cmap3 = colormap(jet(2200-999));
cmap = [cmap1; cmap2; cmap3];
% Apply Combined Colormap to Figure
colormap(cmap)
% Add and Modify colorbar
h = colorbar;
set(h,'YLim',[1000 2200]) % Reduces Range of Colorbar to show only Temp Data
ylabel(h,'Temperature, Kelvin')
print(gcf, '-dtiff', 'filename');
保存时,颜色栏如下所示:
在Matlab图中它看起来很好:
更新:我有一些旧代码,我做了类似的事情,并逐行查看差异。出于某种原因,让这个数字显得很重要?如果我改变
figure
到
figure ('visible','off');
整个事情都有效。仍然好奇为什么????