Cannot overlay line of best fit over boxplot
4 views (last 30 days)
Show older comments
In the script below;
% Fit line of best fit to median data
logData=log(Data+1); y=median(logData); x=j; [P,S]=polyfit(x,y,1); [Y,DELTA]=polyval(P,x,S);
% Plot everything
ii=ii+1; figure(ii) orient Landscape; set(gcf,'units', 'normalized', 'outerposition', [0 0 1 1]);
%boxplot(logData, num2cell(int16(j))) boxplot(logData, int16(j)), hold on
plot(x,Y, 'c','LineWidth', 3) plot(x,Y+DELTA,'r-') plot(x,Y-DELTA,'r-') title('log(BEFORE Data + 1)') hold off boxplot plots correctly and the line of best fit, if plotted on a separate figure also plots correctly. However the line of best fit is NOT overlaid on the boxplot as intended. I think that I am using hold on and hold off correctly? Why is this not working?
0 Comments
Accepted Answer
Star Strider
on 16 Feb 2015
I can’t run your code (and I don’t have the energy just now to try to re-create your data), so it may be that all the ‘hold on’ commands could be the problem. Just one call to each should suffice.
Try this instead:
figure(ii)
orient Landscape;
set(gcf,'units', 'normalized', 'outerposition', [0 0 1 1]);
boxplot(logData, int16(j))
hold on
plot(x,Y, 'c','LineWidth', 3)
plot(x,Y+DELTA,'r-')
plot(x,Y-DELTA,'r-')
title('log(BEFORE Data + 1)')
hold off
4 Comments
More Answers (1)
Helen Kourous
on 30 Mar 2015
"Hold on" does not seem to work well with boxplots, even when you presize the axes. (Even tried "hold all")
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!