Method for aligning tick labels
조회 수: 28 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!