MATLAB Answers

Images are altered in appearance when saved.

1 ビュー (過去 30 日間)
Jamie
Jamie 2011 年 9 月 26 日
Hello! I have been having this issue for some time now and I cannot for my life figure out the problem. I am using a for loop to create an image with 3 subplots. Each iteration, it plots a contour plot, labels axis, etc. The only difference between each iteration is the subplot number, a couple of labels, and some text. The code that actually creates the plot, including setting linewidths and styles, etc, is exactly the same for each iteration.
So the issue is this: I am creating contour plots, and I just have the color of the lines show up as default black:
[MAP1,h1]=contourf(aspvec,slopevec,interp2(Cold,1));
BUT, I want to highlight a particular contour in white, so I add:
[MAP2,h2]=contour(aspvec,slopevec,interp2(Cold,1),[-2,-2]);
set(h2,'LineColor',[1 1 1],'Linewidth',1.5,'LineStyle','-');
When the image is created, it does and looks exactly like what it is supposed to. However, when I actually save the image (using print), the third panel is saved with the "highlighted" contour in black, instead of white. However, the linewidth is still increased, so it didn't completely ignore the whole line, just the part about the color. The first two panels are fine.
Suggestions? I don't understand what is making it change in appearance when saved. (almost) Full code below. Thanks.
for j=1:3
slopevec=(1:5:91)-1;
aspvec=(1:20:361)-1;
if j==1
Cold=zeros(10,10);
Cold(:,:)=dTcold(j,:,:);
subplot(1,3,1)
hold on
[MAP1,h1]=contourf(aspvec,slopevec,interp2(Cold,1));
[MAP2,h2]=contour(aspvec,slopevec,interp2(Cold,1),[-2,-2]);
set(h2,'LineColor',[1 1 1],'Linewidth',1.5,'LineStyle','-');
ylabel('Rock Slope (Deg)','FontSize',24,'FontName','Times');
set(gca,'XTick',[0 90 180 270 360],'XTickLabel',{'0';'90';'180';'270';'0'},'FontSize',18,'FontName','Times');
set(gca,'YTick',[40 65 90],'YTickLabel',{'40';'65';'90'},'FontSize',18,'FontName','Times');
axis([0 360 32 90])
text(8,37,['Min = ',num2str(min(min(Cold))),' deg/min'],'FontSize',18,'Color','k','BackgroundColor','w','FontName','Times');
set(gcf,'Colormap',Blues)
ccmax=max(max(Cold));
ccmin=min(min(Cold));
caxis([ccmin ccmax])
hold off;
end
if j==2
Cold=zeros(10,10);
Cold(:,:)=dTcold(j,:,:);
subplot(1,3,2)
hold on
[MAP1,h1]=contourf(aspvec,slopevec,interp2(Cold,1));
[MAP2,h2]=contour(aspvec,slopevec,interp2(Cold,1),[-2,-2]);
set(h2,'LineColor',[1 1 1],'Linewidth',1.5,'LineStyle','-');
xlabel('Rock Aspect (Deg E of N)','FontSize',24,'FontName','Times') ;
set(gca,'XTick',[0 90 180 270 360],'XTickLabel',{'0';'90';'180';'270';'0'},'FontSize',18,'FontName','Times');
set(gca,'YTick',[40],'YTickLabel',{' '},'FontSize',18,'FontName','Times');
axis([0 360 32 90])
text(8,37,['Min = ',num2str(min(min(Cold))),' deg/min'],'FontSize',18,'Color','k','BackgroundColor','w','FontName','Times');
set(gcf,'Colormap',Blues)
caxis([ccmin ccmax])
hold off;
end
if j==3
Cold=zeros(10,10);
Cold(:,:)=dTcold(j,:,:);
subplot(1,3,3)
hold on
[MAP1,h1]=contourf(aspvec,slopevec,interp2(Cold,1));
[MAP2,h2]=contour(aspvec,slopevec,interp2(Cold,1),[-2,-2]);
set(h2,'LineColor',[1 1 1],'Linewidth',1.5,'LineStyle','-');
set(gca,'XTick',[0 90 180 270 360],'XTickLabel',{'0';'90';'180';'270';'0'},'FontSize',18,'FontName','Times');
set(gca,'YTick',[40],'YTickLabel',{' '},'FontSize',18,'FontName','Times');
axis([0 360 32 90])
text(8,37,['Min = ',num2str(min(min(Cold))),' deg/min'],'FontSize',18,'Color','k','BackgroundColor','w','FontName','Times');
set(gcf,'Colormap',Blues)
caxis([ccmin ccmax])
hold off;
end
end
subplotspace('horizontal',-10)
set(gca,'color','none')
titlestr=[[str1,vstr],'_Cold'];
set(gcf,'pos',get(gcf,'pos').*[1,1,0,0]+[0,0,400,400]);
set(gcf,'PaperUnits','Inches','PaperPosition',[0 0 12 4]);
print(titlestr,'-dtiff','-r600');
  1 件のコメント
Jan
Jan 2011 年 9 月 27 日
The debugging of the program is much easier, if you omit all lines, which do not concern the problem. There is a high chance for you to find a solution by your own, if you've boiled the program down to the essential, because then you know, what is essential.

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2011 年 9 月 27 日
Every day we have questions about figures or pictures not saving correctly. I don't even try to debug them. There are various reasons and it's just not worth my time trying to figure them all out or remember all the possible reasons why it could go wrong. I just simply suggest trying the solution described in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_save_my_figure.2C_axes.2C_or_image.3F_I.27m_having_trouble_with_the_built_in_MATLAB_functions.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by