How to move line plot to be above a stacked bar chart?

3 ビュー (過去 30 日間)
Arijit Bhattacharyya
Arijit Bhattacharyya 2021 年 9 月 19 日
コメント済み: Mathieu NOE 2021 年 9 月 21 日
Hello, here is my current code:
indexValues = [repelem(6, 33), repelem(5,6), repelem(4,6), repelem(3,6), repelem(2,6), repelem(1,74); ...
repelem(1, 131); repelem(4,64), repelem(3,6), repelem(2,6), repelem(1,55); repelem(1, 131); repelem(1, 131); ...
repelem(2, 131)];
lineValues = [repelem(-42.8043, 33), repelem(-48.8249, 6), repelem(-54.8455, 6), repelem(-60.8661, 6), ...
repelem(-66.8867, 6), repelem(-72.9073, 7), repelem(-78.9279, 6), repelem(-84.9485, 6), repelem(-90.9691, 55)];
figure
colororder({'k','k'})
yyaxis left
bar(-120:10, indexValues, 1, 'stacked', 'EdgeColor', 'none')
ylabel('Global Index')
colororder('default')
hold on
grid on
grid minor
yyaxis right
ylabel('Temperature')
plot(-120:10, lineValues, '- . m', 'DisplayName', 'Temperature', 'LineWidth',5)
xlabel('Relative Distance (m)')
xlim([-125 15])
Does anyone know if there is a way to physically move the pink line plot so that it is above the stacked bar chart? I want the curve to ideally be above, so that the multiple colours do not overlap with each other and confuse the user. I have seen that it is possible to move the curve above with the "pan" feature in the figure window, but is there a way to code this in MATLAB to move the pink line automatically? Thank you!

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 9 月 20 日
hello
this would be my 2 cents suggestion using ylim :
code :
indexValues = [repelem(6, 33), repelem(5,6), repelem(4,6), repelem(3,6), repelem(2,6), repelem(1,74); ...
repelem(1, 131); repelem(4,64), repelem(3,6), repelem(2,6), repelem(1,55); repelem(1, 131); repelem(1, 131); ...
repelem(2, 131)];
lineValues = [repelem(-42.8043, 33), repelem(-48.8249, 6), repelem(-54.8455, 6), repelem(-60.8661, 6), ...
repelem(-66.8867, 6), repelem(-72.9073, 7), repelem(-78.9279, 6), repelem(-84.9485, 6), repelem(-90.9691, 55)];
figure
colororder({'k','k'})
yyaxis left
bar(-120:10, indexValues, 1, 'stacked', 'EdgeColor', 'none')
ylim([0 max(sum(indexValues,1))+5]); % here
ylabel('Global Index')
colororder('default')
hold on
grid on
grid minor
yyaxis right
ylabel('Temperature')
plot(-120:10, lineValues , '- . m', 'DisplayName', 'Temperature', 'LineWidth',5)
xlabel('Relative Distance (m)')
xlim([-125 15])
ylim([min(lineValues)-40 max(lineValues)+10]); % and here
  3 件のコメント
Arijit Bhattacharyya
Arijit Bhattacharyya 2021 年 9 月 21 日
Yes, this is great. Thank you!
Mathieu NOE
Mathieu NOE 2021 年 9 月 21 日
my pleasure !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by