Print curly braces in a plot
Afficher commentaires plus anciens
Hello everyone,
I am trying draw a curly brace to indicate a distance in a plot (with some accompanying text). The brace should be "stretchable", i.e. vary its length according to a beginning and end point.
Any suggestions?
Réponse acceptée
Plus de réponses (3)
Pål Næverlid Sævik
le 22 Oct 2012
7 votes
I know this is one year old, but I had the same problem. I therefore wrote a function which plots a curly brace on the current figure. The code can be found at http://www.mathworks.com/matlabcentral/fileexchange/38716-curly-brace-annotation, or by searching Matlab File Exchange for "Curly Brace Annotation".
Sean de Wolski
le 20 Sep 2011
I would recommend starting by reading the tutorial in:
doc
MATLAB>User Guide>Graphics>Annotating Graphs>Adding Text Annotations to Graphs
Another idea is to use the text command and a LaTeX math mode brace and just rotate it and change the font size...
clear; clc;
x = linspace(0,2*pi,100);
y = sin(x);
figure(1); clf;
plot(x,y)
grid on;
ylim([-1.25, 1.25]);
text(2.8, 0.75, '$\{$', 'rotation', 210, 'fontsize', 40, ...
'interpreter', 'latex');
text(2.85, 0.75, 'My favorite part', 'fontsize', 14, ...
'interpreter', 'latex');
1 commentaire
Jozef Lukac
le 20 Juin 2025
Latex commands \overbrace and \underbrace can be used here. They stretch the brace according to the content. The stretch can be set usting \hspace, e.g. \hspace{3cm}.
\overbrace{some base-text}^{upper annotation}
\underbrace{some base-text}_{lower annotation}
text(2.3, 0.9, '$\overbrace{\hspace{3cm}}^{}$',...
'rotation', -63, 'fontsize', 10, 'interpreter', 'latex');
Catégories
En savoir plus sur Labels and Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
