Creating Legend in Piechart

115 次查看(过去 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');

采纳的回答

Dyuman Joshi
Dyuman Joshi 2023-11-3
编辑:Dyuman Joshi 2023-11-3
The syntax for showing legend in the new piechart function is different than before
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 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by