Plot and bar with descending data and double yaxes

4 ビュー (過去 30 日間)
Rachele Franceschini
Rachele Franceschini 2022 年 7 月 14 日
編集済み: Adam Danz 2022 年 7 月 15 日
I would like to create a plot with discending data, but I have some problem (see image).I would like that the green line followes yaxes on the right. Why I have this result?
Below there is my script
%grafico con doppio asse y
workdays = dataset.regione;
workhours = dataset.("somma_classe1");
y1 = dataset.("conteggio_classe1");
[~,arr] = sort(y1,'descend');
X = reordercats(categorical(workdays),workdays(arr));
figure;
bar(X,workhours,'yellow');
title('title 1+2')
ylabel('count news','FontSize',11)
hold on
plot(y1,'green')
yyaxis right
ylabel('media impact');

回答 (1 件)

Adam Danz
Adam Danz 2022 年 7 月 14 日
編集済み: Adam Danz 2022 年 7 月 15 日
You're adding the green line to the left y-axis.
Switch these two lines
plot(y1,'green')
yyaxis right
% to
yyaxis right
plot(y1,'green')
Also,
  1. you should explicitly call yyaxis left before you do the plotting for the left y-axis.
  2. no need for the hold on
  3. you might want to specify the same x values from the bar plot in the line plot.

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by