Plot transparent area of max and min on line graph

1 view (last 30 days)
I have a line graph with max and min plotted as points. I want to turn those points instead into a transparent area that highlights max and min. My code works, mostly.
Problem: area() only plots from zero either up or down. This is fine if my max is positive and my min value is negative. If my max AND min value are both positive, then it overlaps the plots and makes them 1/2 as transparent if that makes sense. Below is code that works except during cases pointed out
if true
% Plotting max and min as transparent area in background
p1=area(year,max);
p2=area(year,min);
childp1=get(p1,'Children');
childp2=get(p2,'Children');
set(childp1,'FaceAlpha',0.05) %transparency between 0 to 1
set(childp2,'FaceAlpha',0.05)
What I tried to do to fix it is combine max and min into matrix and plot that into an area with this
if true
% Plotting max and min as transparent area in background
maxmin = [min.',max.']; %.' to transpose, maybe not necessary
p=area(year,maxmin);
childp=get(p,'Children');
set(childp,'FaceAlpha',0.05) %transparency between 0 to 1
I get the error: Conversion to double from cell is not possible.
The transpose is just to change my max min I pull from csv file. Thank you!
  2 Comments
Steven Crisp
Steven Crisp on 17 Apr 2015
Edited: Steven Crisp on 17 Apr 2015
I think I found a solution with flip and fliplr
if true
% Plotting max and min as transparent area in background
maxmin = [max.';fliplr(min).'];
yearm(:,1) = [year;flip(year)];
p2=area(yearm,maxmin);
childp2=get(p2,'Children');
set(childp2,'FaceAlpha',0.05)

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!