Create a custom legend

617 ビュー (過去 30 日間)
Richard Rees
Richard Rees 2022 年 1 月 10 日
コメント済み: Javier Cervantes 2023 年 12 月 29 日
Hello, I am struggling on how to create a custom label for a series of plots I am doing at the moment (I know how to change the right axis colour). Attached is a sample graph. What I want to do is extract the symbol shapes and give them their space on the legend with an attached lable i.e. X = O and Y = +, then remove those symbols from the rest of the lines, just displaying those colours.
If you need to code to work with, I can supply it will just take a while to trim the accompanying data down.
Could you offer some suggestions.
Thanks

採用された回答

ANKUR KUMAR
ANKUR KUMAR 2022 年 1 月 11 日
You can add the legend manually and set the color and marker as per your own. See the below example for your reference.
x = linspace(0,pi);
figure
plot(x, cos(x),'r')
hold on
plot(x, sin(x),'b')
plot(x, sin(2*x),'m')
qw{1} = plot(nan, 'r-o');
qw{2} = plot(nan, 'b--');
qw{3} = plot(nan, 'm-d');
qw{4} = plot(nan, 'k-d'); % You can add an extra element too
legend([qw{:}], {'Data1','Data2','Data3', 'Data4'}, 'location', 'best')
  3 件のコメント
Bhanu
Bhanu 2023 年 9 月 17 日
Thank you very much
Javier Cervantes
Javier Cervantes 2023 年 12 月 29 日
Thans Ankur!!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by