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

조회 수: 4 (최근 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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by