How can I have a graph with labeled x-axis ticks on the bottom and top of the graph?

27 ビュー (過去 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
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 件)

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by