The concept of X
and Y
axis make little sense to me for a pie
chart, and probably for the Mathworks too, so they decided to "hide" these meaningless labels.
The labels are not displayed because each axe underlying the pie chart has its visible
property set to 'off'
. This hides everything about the axe (i.e. ticks, grid line, background color, etc...).
If they are not meaningless to you and you really want the labels to be displayed, you have to set the axes visible
property to 'on'
. The code below is inspired from your example and shows you how to do it.
The problem with this method, is that you will have to manually 'hide' everything else you do not want to see. This is why I hid the ticks, the background and the grid lines, but the axe border will remain.
count = 0 ;
hdl = zeros(4,4) ;
for i = 1:4 %// number combination of player and opponent
for j = 1:4 %// starting indexes for board sizes
percentageStepResult = rand(4,1) ;
count = count + 1 ;
hdl(i,j) = subplot(4, 4, count) ;
pie(percentageStepResult)
set( hdl(i,j) , 'Visible','on' ) %// set the underlying axes to visible
set( hdl(i,j) , 'Color','none' ) %// set the axes background color to nothing (transparent)
set( hdl(i,j) , 'XTick',[] , 'YTick',[] ) %// remove the 'X' and 'Y' ticks
grid off %// make sure there is no grid lines
xlabel('x axis');
ylabel('y axis');
end
end
Note that I also changed the variable which holds the handles to the axes. It is not a good idea to call something handle
as it is the name of a Matlab built in function. I also put these handles in an array so you can set the axes properties later on if you'd like.
Also note that you can combine all the calls to set( hdl(i,j) , ... )
into one line, I only developed it here for clarity.
edit: Look at the answers from this questions if you want to also hide the axe border (X0 and Y0 lines).
This showed you how to force each axe label to be displayed, but in practice it is very messy. I would recommend instead to just create text
objects and work out how to position them near each pie. At least you won't have to manage the visibility of everything else manually.
text
to affect axis labels. – AnonSubmitter85