How to make a contourf plot follow a line?

조회 수: 2 (최근 30일)
Margaux
Margaux 2023년 6월 23일
댓글: Mathieu NOE 2023년 6월 26일
Good morning! I plotted a contourf plot in a figure, until then evrything is working, but now, I awant to make that contour follow a line. I have been trying to use a for loop but I cannot make it work. Any idea on what I could try to achieve my goal?
Here is my foor loop:
for i = 1:200
c = contourf(X, Y, -) %% different variables from my code to make it easier
xticks([])
yticks([])
cmap = colormap("summer");
xline(0, "black", "LineWidth", 2)
view([180 90]); % changes the view so that the pattern is facing down
pause(2)
drawnow
end
Thank you
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2023년 6월 23일
편집: Mathieu NOE 2023년 6월 23일
hello
can you share your data ? and a picture / sketch of what you want to achieve
Margaux
Margaux 2023년 6월 23일
Hi! Sadly, I cannot share the data as it is way to big. But currently, the output looks like this (image). it is basically an ellipse and an xline is going right down the middle. What I want (image(1)), is basically that same ellipse, just following the lne and leaving a trail behind so it basically becomes a big line. I hope that makes sense.
Thank you

댓글을 달려면 로그인하십시오.

채택된 답변

Mathieu NOE
Mathieu NOE 2023년 6월 23일
hello again
here a small demo code based on a first given elipse (bottom left on the picture)
you can use a spacing between them if needed (xr_spacing)
the intersections function is attached
% dummy ellipse
n = 100;
alpha = pi/n+(0:n)/n*2*pi;
a = 1;
b = 3;
x0 = 2.5;
y0 = 3;
x = x0 + a*cos(alpha);
y = y0 + b*sin(alpha);
% create the reference line
xref = (0:0.1:10);
yref = y0*ones(size(xref));
figure(1);
plot(x,y,'*-b',xref,yref,'r--')
xlim([0 8])
ylim([0 8])
axis square
% for fun let's apply a rotation angle to this
% rotation around the origin(0,0)
% Create rotation matrix
theta = 45; % to rotate 25 degrees counterclockwise
R = [cosd(theta) -sind(theta); sind(theta) cosd(theta)];
% Rotate your point(s)
for k =1:numel(x)
rotpoint = R*([x(k) ;y(k)]);
xr(k) = rotpoint(1);
yr(k) = rotpoint(2);
end
for k =1:numel(xref)
rotpoint = R*([xref(k) ;yref(k)]);
xrefr(k) = rotpoint(1);
yrefr(k) = rotpoint(2);
end
%
figure(2);
plot(xr,yr,'*-b',xrefr,yrefr,'r--')
xlim([-4 8])
ylim([0 12])
axis square
hold on
% now create replicates of the rotated elipse along the reference line
% intersections makes finding the intersection points very easy.
[xout,yout] = intersections(xr,yr,xrefr,yrefr,1);
dx = diff(xout);
dy = diff(yout);
% do n duplicates
xr_spacing = 0.25; % along the reference line (rotated)
xy_spacing = R*([xr_spacing ;0]); % gives the true x and y spacing in the absolute referential
for n = 1:3
newx = xr + n*(dx+xy_spacing(1));
newy = yr + n*(dy+xy_spacing(2));
plot(newx,newy);
end
  댓글 수: 19
Margaux
Margaux 2023년 6월 26일
Oh yeah of course!
Again, thank you so much for your help! I will try to implement it that way!! Thank you!!!
Mathieu NOE
Mathieu NOE 2023년 6월 26일
as always, my pleasure !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by