How can convert line plot to bar plot
이전 댓글 표시
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
2022년 12월 19일
Walter Roberson
2022년 12월 19일
[energyConsumption_GR; energyConsumption_UGR; energyConsumption_CUC] -- are those scalars or vectors or ...?
채택된 답변
추가 답변 (1개)
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.
카테고리
도움말 센터 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

