Shade the region between a curve and the vertical axis

17 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Star Strider
Star Strider el 6 de En. de 2020
Editada: Star Strider el 6 de En. de 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 comentarios
Nathaniel H Werner
Nathaniel H Werner el 8 de En. de 2020
That makes sense. I'll provide the solution I found as an answer later when I have time. Thank you for your help, and I apologize for the confusion. This is a surprisingly difficult problem.
Star Strider
Star Strider el 8 de En. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by