2

这段代码

  1 function makegraph(A,B)
  2 results=load(A);
  3 time = results(:,3) - 1238370000;
  4 firstTimeIndex = find(time >= (max(time) - 86400*7), 1);
  5 results = results(max(1,firstTimeIndex-1):end, :);%Results now only containe    s data from the last week 
  6 temp = results(:,3)-1238370000;
  7 h=plot(temp,smooth(results(:,1)),':b','linewidth',2)
  8 ylim([0 80])
  9 xlim([max(temp)-(86400*7),max(temp)-1])
 10 set(gca,'color','black')
 11 set(gcf,'color','black') %get's rid of he axis alltogether
 12 hold on
 13 plot(temp, smooth(results(:,4)), 'r', 'linewidth', 2);
 14 plot(temp, smooth(results(:,5)), 'g', 'linewidth', 2);
 15 plot(temp, smooth(results(:,6)), 'm', 'linewidth', 2);
 16 xlim([max(temp)-(86400*7),max(temp)-1])
 17 set(gca,'XTick',[1:86400:(max(temp))+1])
 18 set(gca,'XTickLabel',['Mon';'Tue';'Wed';'Thu';'Fri';'Sat';'Sun'])
 19 print('-djpeg',B)
 20 hold off

将此图保存在文件名“B”中...在此处输入图像描述

它工作正常,但我想把它放在不同的上下文中,我需要它有一个黑色的背景......

我试过设置

set(gca,'color',[1 1 0])
set(gcf,'color',[1 1 0])

使用命令行在 MATLAB 中设置绘图的背景颜色所述?

我试过了

whitebg(1,'k')

...而且我无处可去-尤其是因为有时当我尝试玩一些

set(gca,'color','black') set(gcf,'color','black') 设置,我的一些图消失了。

我很困惑..有人可以告诉我为什么在使用命令行在 MATLAB 中设置绘图的背景颜色时接受的答案?不在这里工作...?

4

1 回答 1

2

Turns out that the commands were working within MATLAB, they just weren't working on the printed file because, according to http://www.mathworks.co.uk/help/matlab/ref/print.html....

By default, MATLAB changes the figure background color of printed output to white, but does not change the color of uicontrols. If you have set the background color, for example, to match the gray of the GUI devices, you must set InvertHardcopy to off to preserve the color scheme. To set InvertHardcopy on the current figure, use the command: set(gcf,'InvertHardcopy','off')

So once I set set(gcf,'InvertHardcopy','off'), everything was peachy... thanks in particular to Molly, who put me on the right track...

于 2013-08-08T06:57:48.923 回答