MATLAB Answers


Range limits with plot background color

Asked by Adam
on 5 Feb 2013
Latest activity Edited by Stan Kruger
on 23 Oct 2015

Hello Forum, I am trying to set the plot background of a series of plots to be white and for y-axis values above 60 grey. Is there a way to do this? I am trying to highlight values above a certain criteria. Other suggestions are welcome. Thanks.



2 Answers

Answer by Image Analyst
on 5 Feb 2013
 Accepted answer

Maybe use the rectangle() or patch() function to lay down a gray rectangle in the appropriate place in the plot. Be sure to set "hold on" after that and before you plot your actual data.


Answer by Shashank Prasanna
on 5 Feb 2013

yUp = 0.7;
patch('XData',[x fliplr(x)],'YData',[yUp yUp y(2) y(2)],'FaceColor','r','FaceAlpha',0.3)

  1 Comment

Works great, thanks for clear answer!

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!