-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_visualizing_pieCharts.m
55 lines (37 loc) · 1.02 KB
/
stats_visualizing_pieCharts.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%%
% COURSE: Master statistics and machine learning: intuition, math, code
% URL: udemy.com/course/statsml_x/?couponCode=202112
%
% SECTION: Visualizing data
% VIDEO: Pie charts
%
% TEACHER: Mike X Cohen, sincxpress.com
%
%%
% a clear MATLAB workspace is a clear mental workspace
close all; clear
%% create data for the plot
nbins = 5;
totalN = 100;
rawdata = ceil(logspace(log10(1/2),log10(nbins-.01),totalN));
% prepare data for pie chart
uniquenums = unique(rawdata);
data4pie = zeros(length(uniquenums),1);
for i=1:length(uniquenums)
data4pie(i) = sum(rawdata==uniquenums(i));
end
%% show the pie chart
figure(1), clf
subplot(121)
pie(data4pie)
subplot(122)
pie(data4pie,[0 30 0 1 0],{'one','two','three','four','five'})
%% for continuous data
% generate log-normal distribution
data = exp( randn(1000,1)/10 );
figure(2), clf
% generate bins using histogram
histbins = histcounts(data,6);
% and show that as a pie chart
pie(histbins)
%% done.