How can I shade the background of a timeseries plot based on another value.

9 views (last 30 days)
I have the following code:
days = [152:272]; %n = 120
PA = [0 0 0 0 1 1 1 1....1 0]; % 1 or 0 for each of the 120 day time series
I would like to shade the back of the plot blue when PA = 1 and yellow when PA = 0
I am going to plot another line in front of the color patches.

Accepted Answer

jonas
jonas on 17 Jul 2020
Edited: jonas on 17 Jul 2020
You could do something like this,
%some data
days = 100:199;
PA = repmat([0 0 0 0 1 1 1 1 1 1],1,10);
%PA = 1 -> blue background
[x,y] = stairs(days,PA);
area(x,y,'edgecolor','none','facecolor','b')
%otherwise yellow background
set(gca,'color','y')
  6 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!