Adding an upward arrow to legend
古いコメントを表示
I would like to add a small upward arrow with a text next to it similar to the four entries of the legend in the code below. I created the legend in a bit alternative way, because not all entries are in the figure, while I do want to show them in the legend. I cannot find any documentation on how to do this. Could anyone help me?
h = zeros(4, 1);
h(1) = plot(NaN,NaN,'color','k');
h(2) = plot(NaN,NaN,'color',[0, 0.1, 1]);
h(3) = plot(NaN,NaN,'color',[1, 0.647059, 0]);
h(4) = plot(NaN,NaN,'color','r');
[legh,objh,outh,outm] = legend(h, 'text1','text2','text3','text4');
回答 (1 件)
Walter Roberson
2017 年 8 月 18 日
UP = char(8593);
[legh,objh,outh,outm] = legend(h, [UP 'text1'], [UP 'text2'],[UP 'text3'],[UP 'text4']);
Note: this will not work if you set the legend Interpreter property to LaTex, but will work with Interpreter Tex or None
2 件のコメント
Patrick Looij
2017 年 8 月 18 日
Walter Roberson
2017 年 8 月 18 日
You would need to create an additional graphics object to attach it to. You could use the same plot() of nan technique that you already used.
To adjust the color, index the objh output to get the 5th entry (that is, the one corresponding to the 5th legend text) to get the underlying text object; you can then set the object's Color property to the color you want the arrow to be.
カテゴリ
ヘルプ センター および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!