Shade the region between a curve and the vertical axis

58 views (last 30 days)
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
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
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
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
I would like to shade along the X axis (instead of Y) up to the curve.
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

Accepted Answer

Star Strider
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
  8 Comments
Star Strider
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.

Sign in to comment.

More Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!