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

21 ビュー (過去 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 2025 年 11 月 5 日 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:

サインインしてコメントする。

採用された回答

Cris LaPierre
Cris LaPierre 2025 年 11 月 5 日 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';

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by