How to get the values of x axis only visible at the bottom subplots?
13 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a series of subplots (5x4). Every subplot has the same x axis and the same limits. At the moment, I have the values of x axis visible in every subplot. I would like to have the values only visible at the bottom subplots, so that the figure would be simpler. I already edited the code so that the x label is only visible at the bottom subplots. But how do I do the same to the x axis values?
I tried turning of the 'XTick'
set(gca,'XTick',[]);
This worked, however, now the grid also turned off. How can I get the values to be only at the bottom subplots, and the grid on?
The same goes for y axis. I only want the values of the y axis to be visible at the left subplots.
Thank you in advance for any answers!
0 个评论
回答(2 个)
dpb
2025-4-1
编辑:dpb
2025-4-1
R=5; C=4;
n=0;
for r=1:R
for c=1:C
n=n+1;
hAx(r,c)=subplot(R,C,n);
if r<R, xticklabels(''), end
if c>1, yticklabels(''), end
grid on
end
end
figure
n=0;
for r=1:R
for c=1:C
n=n+1;
hAx(r,c)=subplot(R,C,n);
end
end
set(hAx(1:end-1,:),{'xticklabel'},{''}) % clear tick labels except first column, last row
set(hAx(:,2:end),{'yticklabel'},{''}) % clear tick labels except first column, last row
set(hAx,{'xgrid','ygrid','box'},{'on','on','on'}) % turn on grids and box
set([hAx.XAxis;hAx.YAxis],{'TickLabelFormat'},{'%0.1f'}) % set consistent formatting
It's the tick labels you don't want to display...
0 个评论
Mathieu NOE
2025-4-1
编辑:Mathieu NOE
2025-4-1
hello
maybe this ? (all credits to this answer , adapted to your question : Plot - Remove axis ticks but keep grid lines - MATLAB Answers - MATLAB Central)
% Create a new figure
figure
subplot(2,2,1)
plot(randn(15,1));
ylim([-2 2])
xticklabels("");% Remove x axis numbering
figtune(gca); % special figure tweak
subplot(2,2,2)
plot(randn(15,1));
ylim([-2 2])
xticklabels("");% Remove x axis numbering
yticklabels("");% Remove y axis numbering
figtune(gca);
subplot(2,2,3)
plot(randn(15,1));
ylim([-2 2])
figtune(gca);
subplot(2,2,4)
plot(randn(15,1));
ylim([-2 2])
yticklabels("");% Remove y axis numbering
figtune(gca);
%% special fig rendering function
function figtune(ax)
% Set major Grid lines
ax.GridLineStyle = '--';
ax.GridColor = 'b';
ax.GridAlpha = 1;
grid on;
% Set minor Grid lines
ax.MinorGridLineStyle = '-';
ax.MinorGridColor = 'b';
ax.MinorGridAlpha = 0.5;
grid minor;
end
3 个评论
Mathieu NOE
2025-4-1
编辑:Mathieu NOE
2025-4-1
my pleasure - was not a hard work as everything was almost available in the other post !
and I learned also how to make a really nice plot BTW
dpb
2025-4-1
If solved the problem, go ahead and Accept an answer...and can vote for either or both as well...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!