14 views (last 30 days)
Show older comments
José Irusta Solera on 9 Feb 2021
-
-
Link
Direct link to this question
https://webchat.mathworks.com/matlabcentral/answers/740092-plotting-2-streamlines-on-the-same-plot
Answered: Ojas about 23 hours ago
Open in MATLAB Online
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 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Answers (2)
Ojas about 23 hours ago
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 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
darova on 9 Feb 2021
Open in MATLAB Online
Use handlers properly
clc,clear
[x,y,z] = peaks(5);
h1 = plot(y,z,'r');
hold on
h2 = plot(y,0.9*z,'b');
hold off
legend('red','blue')
%legend([h1(1) h2(1)],'red','blue')
3 Comments Show 1 older commentHide 1 older comment
Show 1 older commentHide 1 older comment
José Irusta Solera on 9 Feb 2021
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/740092-plotting-2-streamlines-on-the-same-plot#comment_1318512
Open in MATLAB Online
The problem is that I can't choose the color in the function streamline, because apparently it doesn't work as the plot function. If I do this:
streamline(XY,'r')
Where XY is the result of the "stream2" function. With this, the program throws an error at the "streamline" function.
darova on 10 Feb 2021
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/740092-plotting-2-streamlines-on-the-same-plot#comment_1320052
Open in MATLAB Online
Try this way:
h = streamline(x,y,u,v,startx,starty);
set(h,'color','r')
José Irusta Solera on 10 Feb 2021
Direct link to this comment
https://webchat.mathworks.com/matlabcentral/answers/740092-plotting-2-streamlines-on-the-same-plot#comment_1320362
Open in MATLAB Online
That works on changing the color of the lines on the plot, but the problem is the legend. If I do that, and don't do anything on the legend, then the legend doesn't appear. If I use:
legend('show')
Then the legend shows "Stokes" (or "Euler") lots of times, according to the number of lines there are. I just need it to appear once, like in the image I presented. That's what I can't do.
Thank you.
Sign in to comment.
Sign in to answer this question.
See Also
Categories
MATLABGraphicsFormatting and AnnotationLabels and AnnotationsLegend
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office