Method for aligning tick labels
36 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 14 de Sept. de 2012
Editada: Azzi Abdelmalek
el 14 de Sept. de 2012
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Axis Labels en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!