Adding an upward arrow to legend
17 views (last 30 days)
Show older comments
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');
0 Comments
Answers (1)
Walter Roberson
on 18 Aug 2017
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 Comments
Walter Roberson
on 18 Aug 2017
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.
See Also
Categories
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!