How to make a column plot like this one?

4 visualizzazioni (ultimi 30 giorni)
Leon
Leon il 18 Giu 2019
Commentato: Adam Danz il 18 Giu 2019
Anyone knows how to make a column plot like the one in the attachment?
Many thanks!
  1 Commento
Leon
Leon il 18 Giu 2019
Modificato: Leon il 18 Giu 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!

Accedi per commentare.

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Tag

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by