Creating a grouped bar plot from a table having multiple column
8 views (last 30 days)
Show older comments
I have the following table:
ValuationRatios company industry sector
___________________________________ _______ ________ ______
"P/E Ratio" 31.96 0 0
"Price/Revenue" 7.79 6.35 7.04
"Price/Book" 45.88 25.45 10.02
"Price to Cash Flow per Share" 28.46 1.33 3.89
"Price to Free Cash Flow per Share" 31.66 1.82 6.37
"Dividend Yield" 0.49 0.49 0.6
"Payout Ratio" 15.58 15.59 28.8
"Quick/Acid Test Ratio" 0.75 0.61 1.03
whos Tindclean
Name Size Bytes Class Attributes
Tindclean 23x4 4221 table
Tindclean.Properties.VariableTypes
string double double double (1 x 4) string
I am trying to create a grouped bar plot/stacked from the table.
0 Comments
Answers (2)
dpb
on 29 Jul 2025
VNames=["ValuationRatios","company","industry","sector"];
VR=[
"P/E Ratio"
"Price/Revenue"
"Price/Book"
"Price to Cash Flow per Share"
"Price to Free Cash Flow per Share"
"Dividend Yield"
"Payout Ratio"
"Quick/Acid Test Ratio"];
Data=[
31.96 0 0
7.79 6.35 7.04
45.88 25.45 10.02
28.46 1.33 3.89
31.66 1.82 6.37
0.49 0.49 0.6
15.58 15.59 28.8
0.75 0.61 1.03 ];
tData=[table(VR) array2table(Data)];
tData.Properties.VariableNames=VNames;
tData=convertvars(tData,'ValuationRatios','categorical')
bar(tData.ValuationRatios,tData{:,2:end})
Cris LaPierre
on 29 Jul 2025
Tindclean = readtable('Tindclean.xlsx')
% Create a stacked barplot of table Tindclean
barData = Tindclean{:, 2:end}; % Assuming the first column is categorical
barLabels = Tindclean{:, 1}; % Assuming the first column contains labels
figure;
bar(barData, 'stacked');
set(gca, 'XTickLabel', barLabels);
xlabel('Categories');
ylabel('Values');
title('Stacked Bar Plot of Tindclean');
legend(Tindclean.Properties.VariableNames(2:end), 'Location', 'bestoutside');
4 Comments
Cris LaPierre
on 30 Jul 2025
Possible without a for loop. However, the challenge now is how to indicate which bar corresponds to which axis.
Tindclean = readtable('mydata.xls');
Tindclean.ValuationRatios = categorical(Tindclean.ValuationRatios);
% Create a stacked barplot of table Tindclean
barData = Tindclean{:, 2:end}; % Assuming the first column is categorical
barLabels = Tindclean{:, 1}; % Assuming the first column contains labels
figure;
yyaxis left
colororder("gem")
ind = contains(string(barLabels),'Employee');
bar(barLabels(~ind),barData(~ind,:), 'stacked');
xlabel('Categories');
ylabel('Values');
yyaxis right
colororder("gem")
bar(barLabels(ind),barData(ind,:), 'stacked');
title('Stacked Bar Plot of Tindclean');
legend(Tindclean.Properties.VariableNames(2:end), 'Location', 'bestoutside');
See Also
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




