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!