如何制作连续堆叠条形图

sha*_*aia 2 matlab

有人知道如何用matlab制作类似于这个的图形吗?

在此输入图像描述

对我来说,这似乎是一个连续的堆积条形图.

我没有设法下载相同的数据,所以我使用其他数据.

我尝试了以下代码:

clear all

filename = 'C:\Users\andre\Desktop\GDPpercapitaconstant2000US.xlsx';
sheet = 'Data';
xlRange = 'AP5:AP259'; %for example

A = xlsread(filename,sheet,xlRange);

A(isnan(A))=[]; %remove NaNs

%create four subsets
A1=A(1:70);
A2=A(71:150);
A3=A(151:180);
A4=A(181:end);


edges=80:200:8000; %bins of the distributions

[n_A1,xout_A1] = histc(A1,edges); %distributions of the first subset
[n_A2,xout_A2] = histc(A2,edges);
[n_A3,xout_A3] = histc(A3,edges);
[n_A4,xout_A4] = histc(A4,edges);

%make stacked bar plot
for ii=1:numel(edges)
    y(ii,:) = [n_A1(ii) n_A2(ii) n_A3(ii) n_A4(ii)];
end

bar(y,'stacked', 'BarWidth', 1)
Run Code Online (Sandbox Code Playgroud)

得到了这个:

在此输入图像描述

它并不是那么糟糕.也许与其他数据相比它看起来更好......但我想知道是否有人有更好的想法.也许有可能以fitdist类似的方式适应?

jka*_*zan 6

首先,定义x轴.如果您希望它遵循规则bar,则使用:

x = 0.5:numel(edges)-0.5;
Run Code Online (Sandbox Code Playgroud)

然后使用area(x,y),产生填充/堆积区域图:

area(x,y)
Run Code Online (Sandbox Code Playgroud)

如果您想要与顶部发布的示例颜色相同,请定义颜色表并调用colormap:

map = [
    218 96  96
    248 219 138
    253 249 199
    139 217 140
    195 139 217
    246 221 245
    139 153 221]/255;

colormap(map)
Run Code Online (Sandbox Code Playgroud)

(它可能不像你发布的那个,但我认为它非常接近.而且,并非所有颜色都显示在下面的结果中,因为只有4个参数,但所有颜色都已定义)

结果:

在此输入图像描述