
Plotting 2 streamlines on the same plot
4 次查看(过去 30 天)
显示 更早的评论
Hi everyone.
I need to plot 2 different streamlines on the same plot. I was able to do it, but I can't insert a propper legend. My plot code is:
figure
a=streamline(XYe);
hold on
area(circ(1,:),circ(2,:),'FaceColor',Col,'EdgeColor',Col)
hold off
xlabel('x/a [adim.]','FontSize',25)
ylabel('y/a [adim.]','FontSize',25)
set(a,'Color','k')
legend('Stokes','Euler')

But the legend doesn't show the color of the lines correctly (both lines on the legend are blue, the default color of the streamline, and 'Euler' doesn't appear black on the legend, but it does appear black on the plot).
I know the use of set and the figures is not appropiate, and I know this is just a detail, but that's my problem, I want to understand figures, and "set". It would be very helpful if you could help me plot this, and also help me understand the mechanism of figures.
Thanks in advance.
José
0 个评论
回答(2 个)
Ojas
2024-6-20
Hi,
I'm not sure if you could solve your problem, but I discovered the method to solve the problem. You insert "" as many times as the lines are which you do not want in the legend, and then add your actual name in the legend. Attaching the code for the same below. Here, I have the length of the streamlines as 9, hence I inserted my true label once, and then used "" 8 times. Hope this helps.
[startX,startY] = meshgrid(xbins(1:9), zbins(1));
figure(4);
axis equal
lineobj = streamline(X, Z, abs(u'), abs(v'), startX, startY);
for i=1:9
lineobj(i).LineWidth = 2;
end
hold on
A = scatter(x, z, 3, "red", "filled", "o", "MarkerEdgeColor","flat", "MarkerFaceColor","auto" );
hold off
xlabel("X")
ylabel("Z")
title("Streamlines plot")
legend("Force streamlines", "", "", "", "", "", "", "", "", "Particles")
legend('show')

0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

