Annotate Coordinate Axis When Plotting in MATLAB by LaTeX \raisebox Command

Dec. 17, 2024

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
clc, clear, close all

ax = gca();
hold(ax,"on"), box(ax, "on"), grid(ax, "on")
set(ax, "Units", "points")
x = 0:.1:5;
y = x.^2;
plot(x, y, "LineWidth", 1.5, "Color", "b")
xlim([0,5])
xt = 0:5;
set(ax, "xtick", xt, "XTickLabel", sprintfc("$T_{%d}$",xt), "TickLabelInterpreter", "latex")

for i = 1:5
    txt = sprintf("\\raisebox{-5pt}{$\\underbrace{\\hspace{54.5pt}}_{M_{%d}}$}", i);
    text(i-1, 0, txt, "Interpreter", "latex", "FontSize", 12, "Color", "r")
end

exportgraphics(gca, "fig.jpg", "Resolution", 600)

fig


References