![1Shade the region between a curve and the vertical axis - 2020 01 06.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260036/1Shade%20the%20region%20between%20a%20curve%20and%20the%20vertical%20axis%20-%202020%2001%2006.png)
Shade the region between a curve and the vertical axis
24 views (last 30 days)
Show older comments
Nathaniel H Werner
on 6 Jan 2020
Commented: Star Strider
on 8 Jan 2020
I have several velocity profiles in a figure, and I've been trying to play around with the area function to try and shade the region between the curve a vertical line. I'm looking to create a plot like this.
![Screen%20Shot%202014-03-16%20at%208.45.32%20PM.png](http://mathonline.wdfiles.com/local--files/calculating-areas-bounded-by-the-y-axis/Screen%20Shot%202014-03-16%20at%208.45.32%20PM.png)
Here is the relavent parts of my code.
% V is the dependent variable, plotted on the x-axis
% Y is the independent variable, plotted on the y-axis
% My actual data is not attached but you can use tan(x) -1<x<1 or tan^-1(x) mirrored about y = x
Y = linspace(-1,1,50);
V = atan(Y);
% R is an array for the radial positions along the wing, the zero location has to move with each radial position
R = 1:4; % for this case
% plot data
plot(V+(R(1)),Y); % only using the first R value for this example
% draw vertical line for reference
plot(R(1)*ones(1,50),Y,'k')
![Capture.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260017/Capture.png)
Now if I try to shade in the region, let's say from a base of 0 this is the result.
area(V+R(1),Y,1,'facealpha',0.5)
![Capture2.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260018/Capture2.png)
As expected the area function fills in the region from Y = 1 to V. I tried switching X and Y as some have suggested, but I don't get the results I would like. The area function does what's it's supposed to and shades in the region up to V = atan(X)+1 from Y = 1.
![Capture3.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260019/Capture3.png)
I would like to shade along the X axis (instead of Y) up to the curve.
![Capture4.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260020/Capture4.png)
This last figure shows what I am actually trying to accomplish but with my actual data instead of with V = atan(Y) as I did above.
![Normalized Flow Profile Utnd_C0_Q1_02_AR5_Reg110_shaded.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260021/Normalized%20Flow%20Profile%20Utnd_C0_Q1_02_AR5_Reg110_shaded.png)
0 Comments
Accepted Answer
Star Strider
on 6 Jan 2020
Edited: Star Strider
on 6 Jan 2020
I am not certain what you want.
Try this:
Y = linspace(-1,1,50);
V = atan(Y);
% R is an array for the radial positions along the wing, the zero location has to move with each radial position
R = 1:4; % for this case
% plot data
plot(V+(R(1)),Y); % only using the first R value for this example
% draw vertical line for reference
hold on
plot(R(1)*ones(1,50),Y,'k')
Vidx = (V+R(1)) > 1;
Vones = ones(size(V));
patch([V(Vidx)+R(1) fliplr(V(Vidx)+R(1))], [Y(Vidx) Vones(Vidx)], [0.1 0.3 0.5], 'FaceAlpha',0.3) % ‘patch’ Call
hold off
It uses the patch function to define the area I believe you want to shade. Increase the number of elements in ‘Y’ to increase the resolution of the patch object.
EDIT —
Added plot image —
![1Shade the region between a curve and the vertical axis - 2020 01 06.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260036/1Shade%20the%20region%20between%20a%20curve%20and%20the%20vertical%20axis%20-%202020%2001%2006.png)
8 Comments
Star Strider
on 8 Jan 2020
As always, my pleasure.
While I would like to see the actual problem, itwould be best to post a detailed description of the problem — and your solution (and all other necessary code) — as a new Question if you want specific help with it.
It would be best to add a Comment with a link to the new Question here, for continuity.
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!