Creating Legend in Piechart
조회 수: 106 (최근 30일)
이전 댓글 표시
How do I create a legend using the new piechart function in Matlab 2023b? I keep on getting the error too many input arguments specified when using legend with piechart. See code below:
Costs = ["Feedstock","Chemicals","Labour","Maintenace",...
"Insurance and Taxes","Overheads","Waste Disposal/WWT","Utilities"];
Cost_Values1 = [13.7341 0.1162 1.0288 0.9720 0.9720 0.9760 0.2263 0.1162];
Cost_Values2 = [13.777 1.110 1.226 1.650 1.650 1.163 0.2829 0.11654];
tiledlayout(1,2)
nexttile
piechart(Cost_Values1);
title("BE-CHP")
nexttile
piechart(Cost_Values2);
title("BE-CHPCCS")
colororder meadow;
legend(Costs,'Location','south','Orientation','horizontal');
댓글 수: 0
채택된 답변
Dyuman Joshi
2023년 11월 3일
편집: Dyuman Joshi
2023년 11월 3일
And, given the size of the legend for piechart(), you will have to use a vertical orientation for the tiledlayout plots.
Costs = ["Feedstock","Chemicals","Labour","Maintenace",...
"Insurance and Taxes","Overheads","Waste Disposal/WWT","Utilities"];
Cost_Values1 = [13.7341 0.1162 1.0288 0.9720 0.9720 0.9760 0.2263 0.1162];
Cost_Values2 = [13.777 1.110 1.226 1.650 1.650 1.163 0.2829 0.11654];
tiledlayout(2,1)
nexttile
p1 = piechart(Cost_Values1, 'LegendVisible', 'on', 'FontSize', 10);
%Get the labales
Labels = p1.Labels;
%Change the names of the slices
p1.Names = Costs;
%Changing the names of the slices also changes the labels,
%And that makes things a bit packed/stuffed, so revert back the changes
p1.Labels = Labels;
title("BE-CHP")
nexttile
p2 = piechart(Cost_Values2, 'LegendVisible', 'on', 'FontSize', 10);
Labels = p1.Labels;
p2.Names = Costs;
p2.Labels = Labels;
title("BE-CHPCCS")
colororder meadow;
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!