Make zeros of right and left axis coincident in plotyy

2 views (last 30 days)
Hello!!
I am doing a subplot of plotyy functions and i would like to make the zeros of left and right axis coincident. Any suggestion? I should adjust it in the second set of fors
for i=1:cell2mat(varargin(1))%columnas
for j=1:length(fichero)%filas
subplot(length(fichero),cell2mat(varargin(1)),(j-1)*cell2mat(varargin(1))+i)%Se rellenan las subdivisiones primero hacia abajo y luego hacia la derecha
set(gcf,'numbertitle','off','name',titulo_fig(end).name,'units','normalized','outerposition',[0 0 1 1],'DefaultAxesColorOrder',[1 0 0;0 0 1]);%fijacion colores
[AX,H1,H2]=plotyy(tiempo,valores(:,(i-1)*n_variables(j)/(2*cell2mat(varargin(1)))+2:i*n_variables(j)/(2*cell2mat(varargin(1)))+1,j)*1000,tiempo,valores(:,(i-1)*n_variables(j)/(2*cell2mat(varargin(1)))+2+n_variables(j)/2:i*n_variables(j)/(2*cell2mat(varargin(1)))+1+n_variables(j)/2,j)*1000);
set(H2,'LineStyle','-.');
AX1(j,i)=AX(1);
AX2(j,i)=AX(2);
[maximos1,minimos1]=sacar_maxmin(valores(:,(i-1)*n_variables(j)/(2*cell2mat(varargin(1)))+2:i*n_variables(j)/(2*cell2mat(varargin(1)))+1,j)*1000);
escala_min_izq(j,i)=min(minimos1(1,:));
escala_max_izq(j,i)=max(maximos1(1,:));
[maximos2,minimos2]=sacar_maxmin(valores(:,(i-1)*n_variables(j)/(2*cell2mat(varargin(1)))+2+n_variables(j)/2:i*n_variables(j)/(2*cell2mat(varargin(1)))+1+n_variables(j)/2,j)*1000);
escala_min_der(j,i)=min(minimos2(1,:));
escala_max_der(j,i)=max(maximos2(1,:));
end
end
for j=1:length(fichero) %filas
for i=1:cell2mat(varargin(1))%columnas
x_tick=round((linspace(tiempo(1),tiempo(end),7))*10)/10;
ratio_izq=(max(escala_max_izq(j,:))-min(escala_min_izq(j,:)))*0.05;
ratio_der=(max(escala_max_der(j,:))-min(escala_min_der(j,:)))*0.05;
set(AX1(j,i),'XLim',[x_tick(1) x_tick(end)],'XTick',x_tick,'YLim',[min(escala_min_izq(j,:))-ratio_izq max(escala_max_izq(j,:)+ratio_izq)],'YTick',linspace(min(escala_min_izq(j,:))-ratio_izq,max(escala_max_izq(j,:))+ratio_izq,8),'FontSize',7
if min(escala_min_der(j,:))-ratio_der==0 && max(escala_max_der(j,:))+ratio_der==0 %si no entran topes pone en y la misma escala que en el eje izq
set(AX2(j,i),'XLim',[x_tick(1) x_tick(end)],'XTick',x_tick,'YLim',[min(escala_min_der(j,:))-ratio_izq max(escala_max_der(j,:)+ratio_izq)],'YTick',[0],'FontSize',7
else
set(AX2(j,i),'XLim',[x_tick(1) x_tick(end)],'XTick',x_tick,'YLim',[(max(escala_max_der(j,:))+ratio_der)*ratio_0 max(escala_max_der(j,:)+ratio_der)],'YTick',linspace(min(escala_min_der(j,:))-ratio_der,max(escala_max_der(j,:))+ratio_der,8),'FontSize',7
end
if mean(abs(get(AX1(j,i),'YTick')'))>2
set(AX1(j,i),'YTickLabel',num2str(round(get(AX1(j,i),'YTick')')),'FontSize',7);
else
set(AX1(j,i),'YTickLabel',num2str(round(get(AX1(j,i),'YTick')'*100)/100),'FontSize',7
end
if mean(abs(get(AX2(j,i),'YTick')'))>2
set(AX2(j,i),'YTickLabel',num2str(round(get(AX2(j,i),'YTick')')),'FontSize',7);
else
set(AX2(j,i),'YTickLabel',num2str(round(get(AX2(j,i),'YTick')'*100)/100));
end
end
end
Thank you in advanced

Answers (0)

Categories

Find more on Two y-axis in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!