Draw objects (arrows, brackets, ...) outside the axis area

조회 수: 36 (최근 30일)
Sim
Sim 2020년 10월 21일
편집: Thomas 2021년 10월 23일
I need to draw some objects (arrows, brackets, ...) outside the axis area.. Any idea on how to do it?
In particular I would need to draw curly brackets outside the axis area.

채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 21일
plot(rand(1,20)); %your basic data
hold on
plot(randn(1,20), 'clipping', 'off'); %your brackets etc
ylim([0 1]);
hold off
  댓글 수: 2
Sim
Sim 2020년 10월 21일
편집: Sim 2020년 10월 22일
Yessss!!! It works, many thanks!!
bracket1 = drawbrace([69 0], [69 -line1], 10, 'Color', 'm')
bracket2 = drawbrace([69 -line1], [69 -line2], 10, 'Color', 'b')
set(bracket1,'clipping', 'off')
set(bracket2,'clipping', 'off')
And I got this plot with the brackets outside the axis area!
Note: for a sake of clarity, the curly brace function gives (if I understood correctly) left brackets by default. As you can see by the picture/screenshot I put here, I instead used right brackets. To get them just make a couple of changes to the drawbrace function and command.
Go to [line 77] of the drawbrace function:
[line 77] h = line(x, y);
and replace "y" with "-y" as follows:
[line 77] h = line(x, -y);
Then, just add a minus sign to the y-coordinates in the drawbrace command:
drawbrace([X1,-Y1], [X2,-Y2], W)
After that you can just run the above mentioned examples, or something similar:
bracket1 = drawbrace([0 0], [0 -0.5], 9, 'Color', 'm')
bracket2 = drawbrace([0 -0.5], [0 -1], 20, 'Color', 'b')
Please, if anyone finds some more robust ways to get right braces (instead of the default left braces) let me know!
Thomas
Thomas 2021년 10월 23일
편집: Thomas 2021년 10월 23일
It seems like I cannot comment on the comment. Anyway, I want to point out that curly brace function actually works for the right brackets. (中国朋友可以直接跳最后一段)See here:
x = linspace(5, 11);
y2 = (70./(x./100)).*(1-1./(1+(x./100)).^100)+1000./(1+(x./100)).^100;
plot(x,y2,'Color','k');
line([6 10],[875.0568 875.0568],'linestyle','--','color','k');
%left red brace
drawbrace([6 875.0568], [6 1166.17], 10, 'Color', 'r');
%right blue brace
drawbrace([10 875.0568], [10 700.0218], 10, 'Color', 'b');
%other code omitted
You see if your start point is lower than the end point, it would be the left braces. While tart point is higher than the end point, it would be the right braces. In fact, the brace will appear on the clockwise middle of these two points.(It is the end. Left is for Chinese people.)
简单来说,curly brace function 这个函数不用调整也可以画出右括号。括号总是生成在起始点的顺时针一侧,然后连接终点。drawbrace([高处的点], [低处的点]);即可生成右括号。

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by