Pie chart help grouping

5 ビュー (過去 30 日間)
Sophia Nador
Sophia Nador 2020 年 12 月 2 日
回答済み: Rahul 2025 年 3 月 13 日
Hi,
I want to make a pie chart group by one of my variable on a dataframe.
In python we can do :
my_data.groupby('Var1').sum().plot(kind='pie',y='Var2', autopct='%1.1f%%')
And I will obtain a pie chart of 'Var1' depending on 'Var2'
But I don't know how to do it in matlab.
How can I do this ?
Thank you very much for any help.

回答 (1 件)

Rahul
Rahul 2025 年 3 月 13 日
In order to plot a pie chart in MATLAB wherin one of the variables is dependant upon the another variable like 'Var1' dependant on 'Var2', consider using 'groupsuummary' and 'pie' functions provided by MATLAB.
Here is an example:
my_data = readtable(filename) % Reading file with data.
groupedData = groupsummary(my_data, 'Var1', 'sum', 'Var2'); % Group by 'Var1' and sum 'Var2'
figure;
pie(groupedData.sum_Var2, groupedData.Var1); % Create pie chart
title('Pie Chart of Var1 grouped by Var2');
Consider referring to the following MATLAB Answers:
The following MathWorks documentations can be referred to know more:
Hope this helps. Thanks.

カテゴリ

Help Center および File ExchangePie Charts についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by