align problem in multiple axes
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to plot two lines in one graph (in one subplot, if not in the subplot, there is no problem) and one axes on bottom and left, the other axes on top and right. However, when I add xlabel to one axes system, the two y axis don't match at the bottom line. the code is as follow:
subplot(4,1,4);
line(time,std);
ax1=gca;
set(ax1,'color','none','Xcolor',xcolor,'ycolor',leftcolor,...
'xminortick','on','yminortick','on','xlim',[t(1),t(2)],...
'ylim',[0.01,100],'yscale','log');
set(get(ax1,'ylabel'),'string','Std (%)','parent',ax1);
set(get(ax1,'xlabel'),'string','time (s)','parent',ax1);
ax2=axes('position',get(ax1,'position'),'xaxislocation','top',...
'yaxislocation','right','color','none',...
'xticklabel','','xminortick','on','yminortick','on',...
'ylim',[0.01,100],'yscale','log');
%set(get(ax2,'xlabel'),'string','time (s)','parent',ax2);
Could anyone tell me how to solve this problem? Thanks!
0 comentarios
Respuestas (2)
Oleg Komarov
el 17 de Abr. de 2011
EDIT
What problems you have with plotyy?
With your example:
time = [0.974 1.232 1.342 1.315 1.539 1.654 1.618 1.275 0.764 0.332 0.294 0.451 0.493 0.405 0.278 0.447 0.800 0.965 0.873 0.601 0.340 0.489 0.634 0.661 0.582 0.591 0.659 0.643 0.508 0.332 0.558 0.823 0.836 4.95 4.693 4.522 4.441 4.372 0.526 0.531 0.777 0.951 0.911 0.823 0.498 0.298 0.260 0.306 0.437 0.617 0.646 0.614 0.448 0.285 0.163 0.0950 0.149 0.248 0.338 0.365 0.422 0.435 0.411 0.377 0.241 0.185 0.371 0.529 0.513 0.346 0.271 0.320 0.283 0.338 0.647 0.953 1.099 0.959 0.620 0.333 0.347 0.615 0.709 0.550 0.724 2.011 3.016 2.659 1.991 1.762 1.914 1.202 1.123 0.976 0.863 0.740 0.600 0.488 0.438 0.465 0.563 0.666 0.676 0.597 0.486 0.346 0.288 0.255 0.226 0.261 0.353 0.429 0.454 0.353 0.216 0.191 0.336 0.474 0.567 0.565];
std = [0.974 1.232 1.342 1.315 1.539 1.654 1.618 1.275 0.764 0.332 0.294 0.451 0.493 0.405 0.278 0.447 0.800 0.965 0.873 0.601 0.340 0.489 0.634 0.661 0.582 0.591 0.659 0.643 0.508 0.332 0.558 0.823 0.836 4.95 4.693 4.522 4.441 4.372 0.526 0.531 0.777 0.951 0.911 0.823 0.498 0.298 0.260 0.306 0.437 0.617 0.646 0.614 0.448 0.285 0.163 0.0950 0.149 0.248 0.338 0.365 0.422 0.435 0.411 0.377 0.241 0.185 0.371 0.529 0.513 0.346 0.271 0.320 0.283 0.338 0.647 0.953 1.099 0.959 0.620 0.333 0.347 0.615 0.709 0.550 0.724 2.011 3.016 2.659 1.991 1.762 1.914 1.202 1.123 0.976 0.863 0.740 0.600 0.488 0.438 0.465 0.563 0.666 0.676 0.597 0.486 0.346 0.288 0.255 0.226 0.261 0.353 0.429 0.454 0.353 0.216 0.191 0.336 0.474 0.567 0.565];
[ax, h1, h2] = plotyy(time, std,time,std);
set(ax,'xminortick','on','yminortick','on',...
'ylim',[0.01,100],'yscale','log','ygrid','on','ycolor','k');
set([h1 h2],'Color','b')
set(cell2mat(get(ax,'ylabel')),'string','Std (%)');
set(get(ax(1),'xlabel'),'string','time (s)');
Matt Fig
el 17 de Abr. de 2011
When I run your code, with some made-up values for time, std, xcolor, leftcolor and t, I don't see any problem.
How about you provide a complete example, one where people don't have to make up values, and put a pause statement in so we can see where the y-axis mismatch happens? Of course your values should be enough to reproduce what you are seeing, but not so long as to make somebody have to scroll for pages...
time = ...
std = ...
xcolor = ...
leftcolor = ...
t = ...
% Plotting code, from first post
pause(2) % Here comes the mismatching
% set xlabel so that the y-axis doesn't match...
Ver también
Categorías
Más información sobre Two y-axis en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!