Plotting subplots in one figure, with shared axes and labels
Afficher commentaires plus anciens
This segment of code is supposed to plot some plots in (9 subplots for each figure) arrangment. However, I am trying to make a shared y-axis for each row and a shared x-axis for each column and keep only one axis label on each axis. This code works perfectly fine for the first figure that is plotted, however, for the next figures it does not apply the same formatting on them.If anyone can help in resolving this.
the figure "i1" shows what I am getting for the first figure and what I want, and the figure "i2" shows what I am getting for the other figures. we want to keep the formatting of all figers as figure one.
attached is a sample of the data being plotted.
This is the segment of code used:
% ii represents the number of plots that we have to plot. In this case ii=86
numFigures = ceil(ii / 9);
% Check if a new figure is needed
if mod(ii - 1, 9) == 0
% Create a new figure
hFig = figure('Name', ['Combined Plots Figure ', num2str(numFigures)], 'NumberTitle', 'off');
numFigures = numFigures + 1;
end
% Plot each set of 9 plots together
subplot(3, 3, mod(ii - 1, 9) + 1, 'Parent', hFig);
hold on;
% Plot data
plot(xss, updatedy, '-x', 'color', "#000000", 'LineWidth', 1)
% Adjust axes and labels for all figures
if mod(ii - 1, 3) == 0
ylabel('Height (km)');
else
set(gca, 'YTickLabel', []);
end
if ii > 6
xlabel('Ne (el/m^3)');
else
set(gca, 'XTickLabel', []);
end
ylim([100 800])
grid on
hold off
3 commentaires
Dyuman Joshi
le 25 Déc 2023
We can not run your code nor infer anything from it as it is missing data and context.
Nor is it clear what the expected output is.
Please share the data, context and what the expected output is (an example should suffice).
Additionally -
Are you running a for loop to plot the figures? And why not add the labels after plotting everything?
Dyuman Joshi
le 25 Déc 2023
@Salma fathi, I see that you have updated the question, however you have not answered my questions.
Are you running a for loop?
What is ii? If it is 86, then is the output supposed to be 9 figures with 9 subplots and 1 figure with 5 subplots?
Salma fathi
le 25 Déc 2023
Modifié(e) : Salma fathi
le 25 Déc 2023
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!








