2016-04-20 56 views
2

誰かがこのようなグラフをmatlabで作成する方法を知っていますか?私に連続積み上げ棒グラフの作成方法

enter image description here

それが連続積算バーグラフのように思えます。

私はother onesを使用したので、同じデータをダウンロードすることはできませんでした。

私は次のコードを試してみました:

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) 

をし、この取得した:それは悪くないです

enter image description here

を...たぶん他のデータと、それは立派に見える...しかし、私誰かがより良いアイデアを持っているかどうか疑問に思っおそらくfitdistを同様の方法で適応させることは可能でしょうか?

答えて

6

まず、x軸を定義します。あなたはそれがbarのルールに従うことをしたい場合は、使用します。

area(x,y) 

そして、あなたは同じ色をしたい場合:

x = 0.5:numel(edges)-0.5; 

はその後埋め/積み上げ面グラフを生成area(x,y)を使用たとえば、あなたがカラーマップを定義し、最上部に掲載さとして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) 

(それはまさにあなたが投稿一人としてではないかもしれないが、私はそれを得たQUそれは近いと思う。また、)ではないすべての色はわずか4パラメータがあるとして、以下の結果に示されているが、すべての色が定義されてい

結果:

enter image description here

+0

クール!ありがとうございました! – shamalaia

+0

ようこそ;) – JCKaz

+1

@A_C、投稿した例と同じようにしたい場合に備えて、色を修正しました。 – JCKaz

関連する問題