How to make a column plot like this one?

2 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by