Create a figure with the same x-axis on top and bottom, and y-axis on the left and right.
조회 수: 9(최근 30일)
표시 이전 댓글
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
답변(2개)
the cyclist
2023년 2월 4일
편집: the cyclist
2023년 2월 4일
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
2023년 2월 5일
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
참고 항목
범주
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!