Matlab - How to make graphs with different limits match using plotyy
1 次查看(过去 30 天)
显示 更早的评论
I have two arrays that I want to plot with two axes. One using a bar-plot, and the second using regular line.
The left hand yaxis is area, and the left hand side is change in area in percent. X-axis is the date of the measurement.
My problem is that the second axis don't match the points of the bar plot. I want the points to be in the same x,y location of the plot.
if true
% code
Code:
date= [714262 724124 731733 734732 736209]; %matlab dates
area = [ 60154 48444 38991 29487 24084]; % area
area_change = [0 0.1947 0.3518 0.5098 0.5996 ]; %change in percent
figure(7)
[AX, T1, T2] = plotyy(date, area ,date, area_change, 'bar', 'line')
set(TX(2), 'ycolor', 'r')
set(TX(2),'YDir','reverse') %%reversed to show area decrease.
end
0 个评论
回答(1 个)
Ilham Hardy
2016-5-4
Something like this? (not completely sure about the reverse part, though)
date= [714262 724124 731733 734732 736209]; %matlab dates
area = [ 60154 48444 38991 29487 24084]; % area
area_change = [0 0.1947 0.3518 0.5098 0.5996 ]; %change in percent
figure(7)
[AX, T1, T2] = plotyy(date, area ,date, area_change, 'bar', 'line');
set(AX(1),'xtick',date,'xticklabel',mat2cell(date));
set(AX(2),'xtick',date,'xticklabel',mat2cell(date));
aax = get(AX(1),'Xlim');
aay = get(AX(1),'Ylim');
set(AX(2),'XLim',aax,'YLim',aay.*1e-5,'YTickMode','auto','YGrid','on','XGrid','on')
set(AX(2),'xtick',date);
set(T2, 'color', 'r')
set(AX(2), 'Ycolor', 'r')
set(AX(2),'YDir','reverse') %%reversed to show area decrease.
aay_lbl = get(AX(2),'YTickLabel');
set(AX(2),'YTickLabel',flipud(aay_lbl)) %%reversed to show area decrease.
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!