How to make a column plot like this one?

3 ビュー (過去 30 日間)
Leon
Leon 2019 年 6 月 18 日
コメント済み: Adam Danz 2019 年 6 月 18 日
Anyone knows how to make a column plot like the one in the attachment?
Many thanks!
  1 件のコメント
Leon
Leon 2019 年 6 月 18 日
編集済み: Leon 2019 年 6 月 18 日
I'm able to use the below script to plot something like this:
A = xlsread('Analysis.xlsx');
han = figure(1);
han01 = subplot(1,1,1);
y = [A(1), 0; ... % pCO2 at 20oC
A(1), A(2); ... % by HCO3 dissociation
A(1)+A(2), A(3); ... % by H2O dissociation
A(1)+A(2)+A(3)+A(4), -A(4); ... % Borate dissociation
A(1)+A(2)+A(3)+A(4), A(5); ... %others
A(1)+A(2)+A(3)+A(4)+A(5), A(6); ... % solubility change
A(7), 0 ];
bar(y, 'stacked');
I want to make the lower half disappear for some of the columns, but not all of them. Is it possible for me to control the color and borderlines of each of the stack components?
How do I do that?
Thanks!

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2019 年 6 月 18 日
編集済み: Adam Danz 2019 年 6 月 18 日
Interesting plot! Here's a recreation using similar values. "chgData" are the height of each country bar while "worldData" are the heights of the two world bars. The trick is to set the facecolor and edgecolor of the lower bars to 'none' and then plot the two end bars separately so you have a different handle that can be used to modify their colors.
% Vector of bar heights for except for the first and last "world" bars
chgData = [.10 .08 .04 .03 .2];
% Vector of bar height for the first and last "World" bars
worldData = [35.7, 36.15];
% Create stacked bar data for all bars except last one
cs = cumsum([worldData(1),chgData]);
stack = [[0;cs(1:end-1)';0],[0;chgData';0],...
[worldData(1);zeros(size(chgData'));worldData(2)]];
% Create figure
figure()
h = bar(stack, 'stacked','BarWidth',1); %BarWidth=1 so that bars touch
ylim([34,37])
% "Remove" the lower bars
h(1).FaceColor = 'none';
h(1).EdgeColor = 'none';
190618 160606-Figure 3.jpg
  2 件のコメント
Leon
Leon 2019 年 6 月 18 日
This works! Thanks you so much, Adam!
Adam Danz
Adam Danz 2019 年 6 月 18 日
That was an interesting one. Glad I could help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by