How to get the values of x axis only visible at the bottom subplots?

22 Ansichten (letzte 30 Tage)
Aaro
Aaro am 1 Apr. 2025
Kommentiert: dpb am 1 Apr. 2025
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!

Antworten (2)

dpb
dpb am 1 Apr. 2025
Bearbeitet: dpb am 1 Apr. 2025
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
You can also get fancy with set for multiple handles after the creation phase...
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...

Mathieu NOE
Mathieu NOE am 1 Apr. 2025
Bearbeitet: Mathieu NOE am 1 Apr. 2025
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 Kommentare
Mathieu NOE
Mathieu NOE am 1 Apr. 2025
Bearbeitet: Mathieu NOE am 1 Apr. 2025
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
dpb am 1 Apr. 2025
If solved the problem, go ahead and Accept an answer...and can vote for either or both as well...

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by