Creating Legend in Piechart

106 ビュー (過去 30 日間)
Marc
Marc 2023 年 11 月 2 日
編集済み: Dyuman Joshi 2023 年 11 月 3 日
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 Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by