Plot with two Y-axis and logarithmix scaling
3 次查看(过去 30 天)
显示 更早的评论
Hi everybody
I am trying to construct a diagram with following code:
y1 = ....
y2 = ....
y3 = y2./y1
t = ...
[ax, h1, h2] = plotyy(t,y1,y3,'loglog','plot');
set(h1,'LineWidth',2,'color',[1 0 0])
set(h2,'LineWidth',2,'color',[0 1 0])
set(ax(1),'FontWeight','Bold','LineWidth',1)
set(ax(2),'FontWeight','Bold','LineWidth',1)
set(get(AX(1),'Ylabel'),'String','TIME,h','FontSize',18,'fontweight','bold','fontname','times new roman')
set(get(AX(2),'Ylabel'),'String','0.2% CREEPSTRENGTH/RUPTURE STRESS,MPa','FontSize',18,'fontweight','bold','fontname','times new roman')
axes(ax(2))
hold on
loglog(t,y2)
legend([y1 y2 y3],{'0.2% Creep strength','Rupture strength','L^{max}_r'},'Location','Southwest','fontname','times new roman','fontsize',20)
xlim([10^3 10^4])
Explanation: I have the arrays y1,y2 which should be plotted on the left Y-axis, which has a logarithmic scale. y3 then should be plotted on the right Y-axis, which is non logarithmic. y1,y2,y3 all share the same X-axis t, which should also have a logarithmic scale.
I experience follwing issues:
- The scaling is somehow not correct
- I always have double sclaing for the X-axis
- I cant not set axis limiations
- I can not edit the colors of the Axis
I know this might be easy for some people, however I already have spent a lot of time on this and I can not get the correct solution
Thank you all!
0 个评论
回答(1 个)
dpb
2013-8-16
编辑:dpb
2013-8-19
y1,y2 should be plotted on the left Y-axis, which has a logarithmic scale. y3 then should be plotted on the right [linear] Y-axis... the ...X-axis t, ...should also have a logarithmic scale
Start with
hax= plotyy(t,[y1 y2],t,y3,'loglog','semilogx'); % save the two axes handles
and prettify from there...
doc plotyy % and friends for details on usage
BTW, the deal about two x-axes--yes, TMW leaves both x-axes visible and plotyy isn't smart enough internally to keep the two synchronized with each other so you have to modify both of them if modify one. Instead of dealing with that nuisance, I generally simply set the visible stuff non-so on the RH axis so while it's not consistent w/ the left it doesn't clutter up the rendition. You can do this by
set(hax(2),'xtick',[]) % clear tick value array for rh axes
which since there are then no tick values, causes h-graphics to not display any tick marks or tick labels for the second (right) x-axis. (I used to actually do this internally in my copy of plotyy() (not that I would recommend doing this by anybody else :) ) but now it's a p-file so can't do it except w/ a wrapper around plotyy).
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!