How to get the values of x axis only visible at the bottom subplots?
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
dpb
le 1 Avr 2025
Modifié(e) : dpb
le 1 Avr 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
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 commentaires
Mathieu NOE
le 1 Avr 2025
Modifié(e) : Mathieu NOE
le 1 Avr 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 commentaires
Mathieu NOE
le 1 Avr 2025
Modifié(e) : Mathieu NOE
le 1 Avr 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
le 1 Avr 2025
If solved the problem, go ahead and Accept an answer...and can vote for either or both as well...
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!