Legend Problems with Graph

3 ビュー (過去 30 日間)
Hamish Brown
Hamish Brown 2021 年 1 月 26 日
コメント済み: Star Strider 2021 年 1 月 26 日
I am attempting to plot three data lines on a graph, 'Critical Flow','Sub Critical Flow' and 'Super Critical Flow'. When i add the legend onto the graph, it seems to think that Sub Critical FLow and Super Critical flow are the same thing and doesnt add the correct legend to the graph. I then tried to fix this by adding 'DisplayName' to the graph and then it seemed to think that each individual point is a seperate plot (image attached). I tried plotting a similar graph with a different variable and it worked fine.
figure(6) %corresponds to bottom graph
clf
hold on
plot(pos01,Umeasured1,'k-o','MarkerSize',4);
plot(pos02,Umeasured2,'b-s','MarkerSize',4);
plot(pos03,Umeasured3,'r-d','MarkerSize',4);
legend('Critical','SubCritical','SuperCritical','Location','SW')
xlabel('y ordinate (mm)');
ylabel('Wake Velocity u/U\infty');
grid minor
hold off
figure(6) %corresponds to top graph
clf
hold on
plot(pos01,Umeasured1,'k-o','MarkerSize',4,'DisplayName','Critical');
plot(pos02,Umeasured2,'b-s','MarkerSize',4,'DisplayName','SubCritical');
plot(pos03,Umeasured3,'r-d','MarkerSize',4,'DisplayName','SuperCritical');
legend('show')
xlabel('y ordinate (mm)');
ylabel('Wake Velocity u/U\infty');
grid minor
hold off

採用された回答

Star Strider
Star Strider 2021 年 1 月 26 日
Try something like this:
figure(6) %corresponds to bottom graph
% clf
hold on
h1 = plot(pos01,Umeasured1,'k-o','MarkerSize',4);
h2 = plot(pos02,Umeasured2,'b-s','MarkerSize',4);
h3 = plot(pos03,Umeasured3,'r-d','MarkerSize',4);
legend([h1(1),h2(1),h3(1)], 'Critical','SubCritical','SuperCritical','Location','SW')
xlabel('y ordinate (mm)');
ylabel('Wake Velocity u/U\infty');
grid minor
hold off
I obviously cannot test this, so I am posting it as UNTESTED CODE. That, or some variation of it, should work.
  2 件のコメント
Hamish Brown
Hamish Brown 2021 年 1 月 26 日
yea that worked! thanks so much
Star Strider
Star Strider 2021 年 1 月 26 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by