Exploded Bar plot (stacked)?

조회 수: 3 (최근 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 CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by