Method for aligning tick labels

34 ビュー (過去 30 日間)
Richard
Richard 2012 年 9 月 14 日
Is there a method of aligning tick labels? I have a figure that has two y axis where the values vary greatly. I would like to align the tick labels so that each value shown on one y label matches up with a value on the opposite ylabel. For example:
data1 = 1+ (12-1).*rand(365,1);
data2 = 1 + (700-1).*rand(365,1);
time = 1:365;
figure(1);
ax1 = axes('position',[0.05 0.5 0.22 0.37]);
plot(time,data1,'k','linewidth',1);
ylabel('label 1');
pos=double(get(ax1,'position'));
ax2=axes('position',pos,'color','none','YAxisLocation','right','xtick',[])
hold on;
plot(time,data2,'r','linewidth',1,'parent',ax2);
ylabel(ax2,'label 2');
Here I would like the second yaxis to have the same number of ticks as the first yaxis as well as the same spacing between them. How can I achieve this?

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 14 日
編集済み: Azzi Abdelmalek 2012 年 9 月 14 日
add this code
data1m=get(ax1,'ylim');
data2m=get(ax2,'ylim')
nt=5; %tick number
data1_tick=linspace(data1m(1),data1m(2),nt);
data2_tick=linspace(data2m(1),data2m(2),nt);
set(ax1,'ytick',round(data1_tick*100)/100)
set(ax2,'ytick',round(data2_tick*100)/100)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by