如何让matlab在​画图时,保持左右y轴​与上下x轴都有轴线,​但是仅有左y和下x有​刻度线?

23 次查看(过去 30 天)
远帅
远帅 2025-7-8
回答: Sameer 2025-7-11
在画图时,我无法单独控制不同x轴和y轴,只能同时设置

采纳的回答

Sameer
Sameer 2025-7-11
The axes box and ticks are controlled with properties like Box, XAxisLocation, YAxisLocation, and the Tick properties. By default, the ticks appear on the axes at the bottom (x) and left (y), but when you turn the box on (with box on), the axis lines also appear at the top and right—with ticks on all sides.
To achieve axis lines on all four sides but ticks only on the left and bottom, you can use a trick: overlay two axes objects. The bottom one will have box on, but no ticks; the top one will have ticks only on the left and bottom, but no box.
Here's an example:
x = 0:0.1:10;
y = sin(x);
% First axes: box and all lines, but no ticks
ax1 = axes('Position',[0.13 0.11 0.775 0.815]);
plot(x, y, 'b');
set(ax1, 'Box', 'on', ...
'XTick', [], ...
'YTick', [], ...
'Color', 'none');
% Second axes: only left and bottom ticks, no box, on top
ax2 = axes('Position', get(ax1,'Position'), ...
'Color', 'none', ...
'XAxisLocation', 'bottom', ...
'YAxisLocation', 'left', ...
'Box', 'off');
hold(ax2, 'on');
plot(ax2, x, y, 'b');
set(ax2, 'Box', 'off');
% Link axes so zooming/panning works together
linkaxes([ax1 ax2]);
% Send the first axes to the back
uistack(ax1, 'bottom');
Hope this helps!

更多回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!