Creating Legend in Piechart
66 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Dyuman Joshi
on 3 Nov 2023
Edited: Dyuman Joshi
on 3 Nov 2023
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 Comments
More Answers (0)
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!