Matlab - How to make graphs with different limits match using plotyy
조회 수: 3 (최근 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!