How to make a column plot like this one?

2 vues (au cours des 30 derniers jours)
Leon
Leon le 18 Juin 2019
Commenté : Adam Danz le 18 Juin 2019
Anyone knows how to make a column plot like the one in the attachment?
Many thanks!
  1 commentaire
Leon
Leon le 18 Juin 2019
Modifié(e) : Leon le 18 Juin 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!

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 18 Juin 2019
Modifié(e) : Adam Danz le 18 Juin 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 commentaires
Leon
Leon le 18 Juin 2019
This works! Thanks you so much, Adam!
Adam Danz
Adam Danz le 18 Juin 2019
That was an interesting one. Glad I could help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by