Newbie: Order of line and plot in a simple figure
조회 수: 11 (최근 30일)
이전 댓글 표시
Sorry for asking stupid questions, but I'm not getting it
Main Problem: Bar chart is always overlaying line plot
Month = [1 2 3 4 5 6 7 8 9 10 11 12]
Temp = [15.8 15.8 15.8 15.7 15.8 15.1 14.7 14.6 15.0 15.7 16.2 16.1]
Prec = [88.0 108.4 129.3 169.5 197.3 212.9 204.3 145.6 121.0 116.2 101.3 99.9]
left_color = [0 0 0]
right_color = [0 0 0]
set(figure(1),'defaultAxesColorOrder',[left_color; right_color]);
hold
xticks([1 2 3 4 5 6 7 8 9 10 11 12])
xlabel ('Monate')
h1=plot(Month,Temp,'color','r')
axis ([1 12 0 30])
yyaxis right
axis ([1 12 0 300])
h2=bar(Month,Prec,'b')
I know, this alreasy looks confused, because I am, I changed everything thousand times, now I'm absolutely coinfus.
What I was trying to do:
Plotting a line graph and bars in oine figure. Line graphe in foreground.
Left yaxis for the Line Graph
Right yaxis for the bars
bars blue, line red
So far, everythign worked but I'm not managing to bring the Line graph to the foreground
Help needed. Thank you
댓글 수: 0
채택된 답변
TADA
2019년 3월 30일
This is actually not a newbie issue...
As far as I know, it's a known issue with yyaxis.
figure(42);
clf();
Month = [1 2 3 4 5 6 7 8 9 10 11 12];
Temp = [15.8 15.8 15.8 15.7 15.8 15.1 14.7 14.6 15.0 15.7 16.2 16.1];
Prec = [88.0 108.4 129.3 169.5 197.3 212.9 204.3 145.6 121.0 116.2 101.3 99.9];
% first init the left & right axes, give both the same position
% left axis needs to be created second to be on top.
rightAx = axes('Position',[0.1300 0.1100 0.7750 0.8150]);
leftAx = axes('Position',[0.1300 0.1100 0.7750 0.8150]);
xticks([1 2 3 4 5 6 7 8 9 10 11 12]);% not necessary really
xlabel ('Monate');
h1=plot(Month,Temp,'color','r');
axis ([0 13 0 30]);
% yyaxis right
subplot(rightAx);
h2=bar(Month,Prec,'b');
% Need to move the Y-axis after plotting the foreground data for some
% reason.
rightAx.YAxisLocation = 'right';
% Now we have to set the background of the front axis to be transparent.
set(leftAx, 'Color', 'None');
still need some playing with the tick marks but it's a good start
댓글 수: 9
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Labels and Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!