How can convert line plot to bar plot

7 ビュー (過去 30 日間)
NOUF ALHARBI
NOUF ALHARBI 2022 年 12 月 19 日
コメント済み: Walter Roberson 2022 年 12 月 19 日
Hi everyone
I have code for a line plot, but I'd like to convert it to a bar plot, for example, for GR with 50 and 100 nodes, two bars adjust together under the same name, GR, and so on for other algorithms:
nodeSize=[50 100]
figure;
x = sort([energyConsumption_GR; energyConsumption_UGR; energyConsumption_CUC], 'descend');
hold on;
plot(nodeSize, x(1, :)', '-', 'LineWidth', 2);
plot(nodeSize, x(2, :)', '--', 'LineWidth', 2);
plot(nodeSize, x(3, :)', '-.', 'LineWidth', 2);
xlabel('# Nodes');
ylabel('J');
legend({'GR','UGR','CUC'}, 'Location', 'northwest');
title('ECC');
whitebg('white');
grid on;
  2 件のコメント
NOUF ALHARBI
NOUF ALHARBI 2022 年 12 月 19 日
I would to be like this graph:
I have try like this but give me one bar for each algorithm, How can I add next each bar the results of 50 nodes?
node=100;
x = sort([energyConsumption_GR; energyConsumption_UGR; energyConsumption_CUC], 'descend');
hold on;
bar(1, x(1), 'FaceColor', '#0072BD', 'BarWidth', 0.2);
bar(2, x(2), 'FaceColor', '#D95319', 'BarWidth', 0.2);
bar(3, x(3), 'FaceColor', '#EDB120', 'BarWidth', 0.2);
ylabel('J');
title('Energy Consumption, # Node= 100');
set(gca,'XTick',[1 2 3]);
set(gca,'XTickLabel',{'GR','UGR','CUC'});
whitebg('white');
grid on;
Walter Roberson
Walter Roberson 2022 年 12 月 19 日
[energyConsumption_GR; energyConsumption_UGR; energyConsumption_CUC] -- are those scalars or vectors or ...?

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

採用された回答

Star Strider
Star Strider 2022 年 12 月 19 日
I have no idea what you want to do.
Perhaps something like this —
nodeSize=[50 100];
x = rand(3,2);
figure
hb = bar(x, 'FaceColor','flat', 'BarWidth',0.2);
% hb(1)
% hb(2)
hb(1).FaceColor = '#0072BD';
hb(2).FaceColor= '#D95319';
ylabel('J');
title('Energy Consumption, # Node= 100');
set(gca,'XTick',[1 2 3]);
set(gca,'XTickLabel',{'GR','UGR','CUC'});
I also have no idea what ‘nodeSize’ does here.
.
  2 件のコメント
NOUF ALHARBI
NOUF ALHARBI 2022 年 12 月 19 日
Thank you so much, yes this is right.
Star Strider
Star Strider 2022 年 12 月 19 日
As always, my pleasure!

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

その他の回答 (1 件)

Adam Danz
Adam Danz 2022 年 12 月 19 日
It appears you're looking for
bar(x)
or
bar(x.')
depending on how you'd like to group the bars.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by