I am trying to label my bars in a 3D bar graph:
clf
yMax = 2;
xMax = 3;
z=floor(10*rand(yMax,xMax));
bar3(z)
xlabel('x-axis')
ylabel('y-axis')
x = reshape( repmat(1:xMax,yMax,1), [], 1 );
y = repmat( (1:yMax)', xMax,1 );
%htext = text( x, y, z(:), repmat( {'TEST'}, xMax*yMax, 1 ) )
htext = text( x, y, z(:), 'TEST' )
No matter how big I make the figure, the text gets chopped at the bottom:
Can anyone suggest a way to track down the cause, and/or suggest a solution?
I was fortunate to catch a few minutes with a guru. The explanation: The VerticalAlignment
defaults to middle
, which works fine for 2D plots. For each of the 3D bars above, however, middle
means that the middle of the text sits right at the top surface of the box. Therefore, the bottom half of the text is inside the box. The problem is solved by modifying the text
command:
htext = text( x, y, z(:), 'TEST' , 'VerticalAlignment','Bottom' )
Weird how I couldn't find it in a web search, but hopefully, this answer will fix that.