Exploded Bar plot (stacked)?

7 ビュー (過去 30 日間)
Dominik Mattioli
Dominik Mattioli 2021 年 7 月 16 日
回答済み: Arthi Sathyamurthi 2021 年 7 月 23 日
Is there functionality for "exploding" the stacked bars in a bar plot? I have data that can be visualized using the bar( x, y, 'stacked' ) method, but the y-axis values don't hold intuitive value. I think that my approach (below) may remedy this issue with a new plot design, but I'm curious if this MATLAB functionality already exists.
So if this were the result of plotting your data 'stacked':
Then this would be the exploded stacked plot, removing the need for a legend by using the y-axis:
% Stacked, conventional.
figure; bar( xdata, ydata, 'stacked' );
% Stacked, exploded. First, figure out the patch dimensions, then plot.
boxPatchXY = cell( numGroups, numItems );
bufferY = 0.125;
bufferX = 0.2;
minY = 10 * bufferY;
minX = 0.6 : 1 : numItems + 0.6;
maxX = 1.4 : 1 : numItems + 1.4;
midY = NaN( numGroups, 1 );
for group = 1:numGroups
groupData = ydata( group, : );
if group == 1
minY = minY + bufferY;
else
minY = maxY + bufferY;
end
maxY = max( groupData ) + minY;
midY( group ) = ( minY + maxY ) / 2 ;
for item = 1:numItems
startX = minX( item );
endX = maxX( item );
itemX = vertcat( startX, startX, endX, endX, endX, startX );
itemY = vertcat( midY( group ), midY( group ) - groupData( item ) / 2,...
midY( group ) - groupData( item ) / 2, midY( group ),...
midY( group ) + groupData( item ) / 2, midY( group ) + groupData( item ) / 2 );
boxPatchXY{ group, item } = horzcat( itemX, itemY );
end
end
boxPatchPlots = gobjects( numel( boxPatchXY ), 1 );
for idx = 1:numel( boxPatchPlots )
boxPatchPlots( idx ) = patch( boxPatchXY{ idx }( :, 1 ), boxPatchXY{ idx }( :, 2 ),...
'FaceColor', barColors{ idx }, 'EdgeColor', barColors{ idx },...
'Parent', aLaneColumns );
end

回答 (1 件)

Arthi Sathyamurthi
Arthi Sathyamurthi 2021 年 7 月 23 日
Hello Dominik,
Currently we are not supporting 'explode' feature in the bar plot function. I have brought this issue to the notice of the concerned people and it might be considered for a future release.

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by