How can I have a graph with labeled x-axis ticks on the bottom and top of the graph?
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
Akzeptierte Antwort
MathWorks Support Team
am 27 Jun. 2009
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!