Hi all,
I have a question about subplot. How can we plot 2 suplots, but only one horizontal axis.
subplot(3, 1, 1:2);
plot(rand(10, 1), 'b.-', 'LineWidth', 2);
grid on;
subplot(3, 1, 3);
plot(rand(10, 1), 'b.-', 'LineWidth', 2);
grid on;
My expection as:
Thank you so much

 Réponse acceptée

VBBV
VBBV le 11 Oct 2022
Modifié(e) : VBBV le 12 Oct 2022
subplot(3, 1, 1:2);
plot(rand(10, 1), 'b.-', 'LineWidth', 2);
xticks(1:10)
grid on;
xticklabels({})
subplot(3, 1, 3);
plot(rand(10, 1), 'b.-', 'LineWidth', 2);
grid on;

3 commentaires

galaxy
galaxy le 12 Oct 2022
Thank you so much your answer.
But, you can see that grid 2 subplot does not same.
How to fix it?
VBBV
VBBV le 12 Oct 2022
add xticks
galaxy
galaxy le 12 Oct 2022
Thank you so much.
It is OK

Connectez-vous pour commenter.

Plus de réponses (1)

Martin Pryde
Martin Pryde le 12 Oct 2022
Modifié(e) : Martin Pryde le 12 Oct 2022
ax1 = subplot(3,1,1:2);
plot(ax1,rand(10,1),'b.-','LineWidth',2);
ax2 = subplot(3, 1, 3);
plot(ax2,rand(10,1),'b.-','LineWidth',2);
grid(ax1,'on');
xlim(ax1,[1,10]);
xticks(ax1,1:10);
xticklabels(ax1,{})
grid(ax2,'on');
xticks(ax2,1:10);
xlim(ax2,[1,10]);

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Produits

Version

R2019b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by