필터 지우기
필터 지우기

Gradient coloring of streamlines

조회 수: 21 (최근 30일)
Cyril GADAL
Cyril GADAL 2017년 7월 10일
답변: Manish Annappa 2017년 7월 12일
Hello,
I'm currently using the streamline function https://fr.mathworks.com/help/matlab/ref/streamline.html to plot the streamlines of a flow I'm considering. I would like to have an "evoluting" color along the streamlines according to the flow speed in each point.
I don't know how to start ... Any hint will be very appreciated ! Here is my code that is ploting the streamlines :
%%%%%%%%%%%%%%%%%Shear over topo
alpha = 70 ;
lambda = 20 ;
k = cosd(alpha) * 2 *pi/lambda ;
l = sind(alpha) * 2 *pi/lambda ;
x = 0 : 0.1 : 50 ;
y = 0 : 0.1 :50 ;
A = 1;
B = 3 ;
Amp = 0.1/sqrt(k^2+l^2) ;
[X,Y] = meshgrid(x,y) ;
TauX = Amp * sqrt(A^2+B^2)*(k^2/sqrt(k^2+l^2)).*cos(k.*X+l.*Y + atan(B/A)) ;
TauY = Amp * sqrt(A^2+B^2)*(k*l/sqrt(k^2+l^2)).*cos(k.*X+l.*Y + atan(B/A)) ;
Topo = Amp .* cos(k.*X + l.*Y) ;
figure
imagesc(x,y,Topo)
hold on
hlines = streamline(X(1:step:end,1:step:end),Y(1:step:end,1:step:end),1 + TauX(1:step:end,1:step:end), TauY(1:step:end,1:step:end),0*y(1:step:end,1:step:end),y(1:step:end,1:step:end)) ;
set(hlines, 'Color', 'k')
Thank you very much !

답변 (1개)

Manish Annappa
Manish Annappa 2017년 7월 12일
As per your description, you either want to set different colors to each line in variable 'hlines' or you want to set multiple colors to a single line (varying colors along Y axis).
1) You can set different colors to each line using the code snippet below.
colorstring = 'kbgry';
for i = 1:5
set(hlines(i), 'Color', colorstring(i))
end
2) As per the link below, it is not possible to set different colors for different region of a line.
However, below link that illustrates the usage of patch objects may help you.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by