Как на графике выровнять метки точек и обозначение оси в одну линию?
15 views (last 30 days)
Show older comments
У меня есть диаграмма.

Есть ли какой-то элегантный способ разместить обозначение оси 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 Comment
Walter Roberson
ongeveer 8 uur ago
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:
Answers (1)
Cris LaPierre
ongeveer 8 uur ago
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 Comments
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!