2
votes

This code

  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

Saves this graph in the filename 'B'...enter image description here

It works fine, but I'd like to put it in a different context, for which I need it to have a black background...

I have tried setting

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

as described by Setting the background color of a plot in MATLAB using the command line?

and I've tried

whitebg(1,'k')

...and I'm getting nowhere -particualarly because sometimes when I try and play around with some of

set(gca,'color','black') set(gcf,'color','black') settings, some of my plots disappear.

I'm deeply confused.. could someone tell me why the accepted answer at Setting the background color of a plot in MATLAB using the command line? isn't working here...?

1
What is B? Do you have this problem in the figure displayed in matlab or only in the printed file?Molly
you should try to use the handle of the figure\axes directly, instead of using gca\gcfLucius II.
@Molly B is the filename - have edited - and it turned out I was looking at the printed file... which helped me solve it...Joe

1 Answers

2
votes

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...