Azzera filtri
Azzera filtri

Creating Legend in Piechart

102 visualizzazioni (ultimi 30 giorni)
Marc
Marc il 2 Nov 2023
Modificato: Dyuman Joshi il 3 Nov 2023
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');

Risposta accettata

Dyuman Joshi
Dyuman Joshi il 3 Nov 2023
Modificato: Dyuman Joshi il 3 Nov 2023
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;

Più risposte (0)

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by