如何让matlab在画图时,保持左右y轴与上下x轴都有轴线,但是仅有左y和下x有刻度线?
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
在画图时,我无法单独控制不同x轴和y轴,只能同时设置
0 Kommentare
Akzeptierte Antwort
Sameer
am 11 Jul. 2025
HI @远帅
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!