How to make a column plot like this one?

4 views (last 30 days)
Anyone knows how to make a column plot like the one in the attachment?
Many thanks!
  1 Comment
Leon
Leon on 18 Jun 2019
Edited: Leon on 18 Jun 2019
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!

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 18 Jun 2019
Edited: Adam Danz on 18 Jun 2019
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 Comments
Leon
Leon on 18 Jun 2019
This works! Thanks you so much, Adam!
Adam Danz
Adam Danz on 18 Jun 2019
That was an interesting one. Glad I could help.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!