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!