Shade the region between a curve and the vertical axis
17 次查看(过去 30 天)
显示 更早的评论
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.
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')
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)
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.
I would like to shade along the X axis (instead of Y) up to the curve.
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.
0 个评论
采纳的回答
Star Strider
2020-1-6
编辑:Star Strider
2020-1-6
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 —
8 个评论
Star Strider
2020-1-8
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!