Как на графике выровнять метки точек и обозначение оси в одну линию?

13 次查看(过去 30 天)
Aleksandr
Aleksandr 2025-11-5,17:27
回答: Cris LaPierre 2025-11-5,18:56
У меня есть диаграмма.
Есть ли какой-то элегантный способ разместить обозначение оси x в одну линию с метками x1, x2, x3?
На данный момент код для настройки графика у меня выглядит вот так:
xTicks = [pi, 2*pi, 3*pi];
yTicks = [0, 0.5];
ax = gca;
ax.XTick = xTicks;
ax.XTickLabel = {'$x_1$','$x_2$','$x_3$'};
ax.YTick = yTicks;
ax.YTickLabel = {'0','$\lambda_0$'};
ax.FontSize = 14;
ax.TickLabelInterpreter = 'latex';
xlabel('$x$', 'Interpreter', 'latex');
ylabel('$y$', 'Interpreter', 'latex');
ax.XAxis.LabelHorizontalAlignment = 'right';
ax.YAxis.LabelHorizontalAlignment = 'right';
ax.YAxis.Label.Rotation = 0;
ax.LabelFontSizeMultiplier = 1;
  1 个评论
Walter Roberson
Walter Roberson 4 minutes 前
Approxiomate translation:
How to align point labels and axis labels on a chart?
I have a diagram.
Is there an elegant way to align the x-axis label with the x1, x2, and x3 labels?
Currently, my chart setup code looks like this:

请先登录,再进行评论。

回答(1 个)

Cris LaPierre
Cris LaPierre about 5 hours 前
Perhaps not the expected solution, but this works: add the xlabel and ylabel as an xtick/ytick label at the axis limit.
x = linspace(0,15,50);
y = -sin(x);
plot(x,y,'.-')
pos = axis;
xticks([pi, 2*pi, 3*pi pos(2)])
xticklabels({'$x_1$','$x_2$','$x_3$','$x$'});
yticks([0, 0.5, pos(4)])
yticklabels({'0','$\lambda_0$','$y$'});
ax = gca;
ax.FontSize = 14;
ax.TickLabelInterpreter = 'latex';

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by