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

3 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 20 Sep. 2021
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 Kommentare
Arijit Bhattacharyya
Arijit Bhattacharyya am 21 Sep. 2021
Yes, this is great. Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by