Engine
Engine

Reputation: 5432

how to change the background only of a part of a plot in MATLAB

say I got this command :

plot(1:100);

is their a way to make the only the part between say : 50 : 60 having a yellow background ? thanks for any hint

Upvotes: 0

Views: 56

Answers (1)

TroyHaskin
TroyHaskin

Reputation: 8401

You can use the fill function to create a yellow rectangle, either behind the plot lines or with some transparency.

Put this before the plots:

xrec = [0,1,1,0,0];
yrec = [0,0,1,1,0];
fill(xrec,yrec,'y');

Or do this afterward (this will shade the plot lines as well though):

fill(xrec,yrec,'y','FaceAlpha',0.2);

Upvotes: 3

Related Questions