How can I have a graph with labeled x-axis ticks on the bottom and top of the graph?
조회 수: 26 (최근 30일)
이전 댓글 표시
I would like to make a graph which has labeled tick marks along the bottom and top of the graph. The tick marks should be in the same horizontal positions, but with different labels. How can I do this?
채택된 답변
MathWorks Support Team
2009년 6월 27일
By default the plot should have a set of axes with a labeled set of tick marks on the bottom and the left. The example below explains how this can be done for both the X and Y axes with different Tick labels on all four sides.
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'));
OppTickLabels = {'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', OppTickLabels,'YTickLabel',OppTickLabels);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Labels and Annotations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!