Legend position in piecharts

18 ビュー (過去 30 日間)
Marc
Marc 2023 年 11 月 4 日
コメント済み: Marc 2023 年 11 月 21 日
Hey guys, I am trying to add a single legend at the bottom of 2 piecharts and also increase the font of the percentages on the chart. See code below.Thanks for your help,
clc
clear
Costs = ["Feedstock","Other Variable Costs","Labour","O & M"];
Cost_Values1 = [13.7341 0.4169 1.0288 2.920 ];
Cost_Values2 = [13.777 1.51 1.226 4.4647 ];
tiledlayout(1,2)
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 = p2.Labels;
p2.Names = Costs;
p2.Labels = Labels;
title("BE-CHPCCS")
colororder meadow;
  1 件のコメント
Image Analyst
Image Analyst 2023 年 11 月 5 日
Can you specify the Position property of p1? Then just don't set up the labels or names of p2 to get just one "legend".

サインインしてコメントする。

採用された回答

Sai Teja G
Sai Teja G 2023 年 11 月 20 日
編集済み: Sai Teja G 2023 年 11 月 20 日
Hi Marc,
I understand that you wish to enlarge the font size for the percentages and utilize a single legend for both pie charts.
The issue you're experiencing with the font size in the pie charts is due to the size of the legend when using the `piechart()` function, coupled with a horizontal orientation for the `tiledlayout` plots. Since the 'legend' property is linked to the 'piechart()' function, it is not possible to directly set the position of a single legend to be shared by both pie charts simultaneously. To resolve these issues and implement a single legend for both pie charts, please refer to the following code example:
clc
clear
Costs = ["Feedstock","Other Variable Costs","Labour","O & M"];
Cost_Values1 = [13.7341 0.4169 1.0288 2.920 ];
Cost_Values2 = [13.777 1.51 1.226 4.4647 ];
tiledlayout(1,2)
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', 'off', 'FontSize', 10);
Labels = p2.Labels;
p2.Names = Costs;
p2.Labels = Labels;
title("BE-CHPCCS")
colororder meadow;
Hope it helps!
  1 件のコメント
Marc
Marc 2023 年 11 月 21 日
Thanks man. Another challenge I'm facing is changing the fontweight of the legend and percentages to "bold".

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by