How to create a plot of the spread of the data

14 views (last 30 days)
How can I create e distribution of the spread for the data below. I want to have in the same figure 5 distributions respresenting
the spread of the data from its mean in each zone.The columns contain the daily prices for 5 different zones.
My purpose is to check if there are significant differences in the prices between zones. How can I get a similar figure like the one below where the red line is the mean and the blue space showing the data below and above the mean and also the standard deviation of the data. x-axis all the zones and in y-axis the price values.
I have tried to use the following code but it is not fulfilling my purpose. Anyone can help me ...
x1=Data(:,1); x2=Data(:,2); x3=Data(:,3); x4=Data(:,4); x5=Data(:,5);
z1=(x1-mean(x1))/std(x1);
z2=(x2-mean(x2))/std(x2);
z3=(x3-mean(x3))/std(x3);
z4=(x4-mean(x4))/std(x4);
z5=(x5-mean(x5))/std(x5);
pd1=fitdist(z1,'Kernel');
pd2=fitdist(z2,'Kernel');
pd3=fitdist(z3,'Kernel');
pd4=fitdist(z4,'Kernel');
pd5=fitdist(z5,'Kernel');
s=(-2:0.01:2);
y1=pdf(pd1,s);
y2=pdf(pd2,s);
y3=pdf(pd3,s);
y4=pdf(pd4,s)
y5=pdf(pd4,s);;
figure
p=plot(s,y1,'-b',s,y2,'k',s,y3,'-g',s,y4,':r',s,y5,'-m');
title('Empirical kernel')

Accepted Answer

the cyclist
the cyclist on 28 Mar 2020
Edited: the cyclist on 28 Mar 2020
Does using subplots help show your point better?
% Load the data
load Data1.mat
% Convert from table to numeric
Data = table2array(Data1);
% Get the z-score
z = (Data - mean(Data))./std(Data);
% Define the range of s
s = -2:0.01:2;
% For convenience, get the dimensions of these arrays
nr = numel(s);
nc = size(z,2);
% Preallocate memory for the distributions and pdf values. Use a cell array
% for pd.
pd = cell(nc,1);
y = zeros(nr,nc);
% For each column of z, fit the distribution and get the pdf
for nd = 1:nc
pd{nd} = fitdist(z(:,nd),'Kernel');
y(:,nd) = pdf(pd{nd},s);
end
% Plot in subplots
figure
for nd = 1:nc
subplot(nc,1,nd), plot(s,y(:,nd))
end
If not, can you please explain more specifically what you need?
  4 Comments
gjashta
gjashta on 28 Mar 2020
Edited: gjashta on 28 Mar 2020
Do you think the two-sample Kolmogorov-Smirnov test will help me, because I just want a way how to show the variability as a distribution, I have also used boxplot, histogram, and histcounts for each zone but as the data vary from 13-15 I got very few bins.
the cyclist
the cyclist on 28 Mar 2020
Can you be more specific in what you mean by "show the variability"? To me, the subplots of the distributions give very complete information, so I don't understand what the problem is. Could you draw a picture by hand? Or are you trying to calculate a number?

Sign in to comment.

More Answers (0)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!