Create a figure with the same x-axis on top and bottom, and y-axis on the left and right.
61 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How can I create a figure with the same x-axis on top and bottom of my figure. Also, how can I do the same with the same y-axis on the right and left? Also, how can I have labels for the top,bottom, left, and right of the figure.
0 Kommentare
Antworten (2)
the cyclist
am 4 Feb. 2023
Bearbeitet: the cyclist
am 4 Feb. 2023
I am not entirely sure I understand everything you want. But, borrowing from this answer, here is code that will label ticks on all sides of a plot. Maybe you can adapt it to what you need.
% Plot some data
figure
plot(1:10);
% First, store the handle to those axes.
% Next create a second set of axes,
% position This on top of the first and make it transparent.
ax1=gca;
ax2 = axes('Position', get(ax1, 'Position'),'Color', 'none');
set(ax2, 'XAxisLocation', 'top','YAxisLocation','Right');
% set the same Limits and Ticks on ax2 as on ax1;
set(ax2, 'XLim', get(ax1, 'XLim'),'YLim', get(ax1, 'YLim'));
set(ax2, 'XTick', get(ax1, 'XTick'), 'YTick', get(ax1, 'YTick'));
OppXTickLabels = {'a' 'b' 'c' 'd' 'e' 'f'};
OppYTickLabels = {'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k'};
% Set the x-tick and y-tick labels for the second axes
set(ax2, 'XTickLabel', OppXTickLabels,'YTickLabel',OppYTickLabels);
the cyclist
am 5 Feb. 2023
Based on your comment on my other solution, here is a different guess as to what you mean. (I'm still not really sure.)
This code uses the tiledlayout function to make three plots side-by-side (in this case some random histograms), and then uses the linkaxes function to synchronize the x- and y-axes.
figure
tiledlayout(1,3)
% Tile 1
ax1 = nexttile;
histogram(randn(1000,1)+2)
% Tile 2
ax2 = nexttile;
histogram(randn(1000,1)+7)
% Tile 3
ax3 = nexttile;
histogram(randn(1000,1)+19)
% Link the axes
linkaxes([ax1, ax2, ax3])
0 Kommentare
Siehe auch
Kategorien
Mehr zu Axes Appearance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


