Print curly braces in a plot
42 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Adriano
il 20 Set 2011
Commentato: Jozef Lukac
il 20 Giu 2025
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?
0 Commenti
Risposta accettata
Patrick Kalita
il 20 Set 2011
There's nothing that ships with MATLAB that does exactly what you want. The 'doublearrow' annotation is probably the thing that comes the closest. It can be used to indicate a distance in a plot, but it's clearly not a brace.
If you're really committed to having a brace, I would just draw some kind of brace-like shape using the line command. The task then becomes generating x-data and y-data that define your brace. This can be as simple or as complicated as you like. Here's one idea:
% Here's the plot I'm annotating
plot(1:10)
% These define the placement and size of the brace
x = 6;
y1 = 0;
y2 = 6;
width = 0.2;
% Make some x-data and y-data
line_x = x + [0, 0.5, 0.5, 1, 0.5, 0.5, 0]*width;
line_y = y1 + [0, 0.02, 0.48, 0.5, 0.52, 0.98, 1]*(y2-y1);
% Draw the brace and some text, too, for fun.
line(line_x, line_y, 'Color', 'k')
text(x+1.5*width, y1 + 0.5*(y2-y1), 'Whoaaa! Look at this gap!');
You can see that's a relatively primitive brace. If I wanted to make it fancier, I might start looking at using Bézier curves.
0 Commenti
Più risposte (3)
Pål Næverlid Sævik
il 22 Ott 2012
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".
0 Commenti
Sean de Wolski
il 20 Set 2011
I would recommend starting by reading the tutorial in:
doc
MATLAB>User Guide>Graphics>Annotating Graphs>Adding Text Annotations to Graphs
0 Commenti
Joe Lettieri
il 24 Mag 2023
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 Commento
Jozef Lukac
il 20 Giu 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');
Vedere anche
Categorie
Scopri di più su Labels and Annotations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!