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

21 Ansichten (letzte 30 Tage)
Aleksandr
Aleksandr am 5 Nov. 2025 um 17:27
Beantwortet: Cris LaPierre am 5 Nov. 2025 um 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 Kommentar
Walter Roberson
Walter Roberson am 5 Nov. 2025 um 18:20
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:

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 5 Nov. 2025 um 18:56
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';

Weitere Antworten (0)

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by