Axis markers are invisible?

I have the following code:

figure(1);
suptitle('Percentage of games won with board size');
count = 0;
% relation of board size and the game outcome
for i = 1:4 % number combination of player and opponent
    for j = 1:4 % starting indexes for board sizes
        percentageStepResult = [sum(sizeResultVec{i}(j:4:120) == 1), sum(sizeResultVec{i}(j:4:120) == -1), sum(sizeResultVec{i}(j:4:120) == 0)];
        count = count + 1;
        handle = subplot(4, 4, count);
        xlabel('x axis');
        ylabel('y axis');
        pie(percentageStepResult)
    end
end

      

Which generates the following graph:

enter image description here

Why doesn't this display labels at all? I'm trying to move towards having one xlabel and one label for the whole plot, but I'm confused as to why they won't even show up for individual subplots.

+3


source to share


1 answer


The concept of axis X

and Y

does not make any sense to me for the chart pie

and is likely to The Mathworks, so they decided to "hide" these meaningless labels.

The labels are not displayed because each tog underlying the pie chart has a property visible

set to 'off'

. This hides everything about the ax (i.e. Ticks, gridlines, background colors, etc.).

If they are not meaningless to you, and you really want the labels to be displayed, you need to set the axes property to a visible

value 'on'

. The code below is inspired by your example and shows you how.

The problem with this method is that you have to manually "hide" anything you don't want to see. This is why I have hidden the ticks, background and grid lines, but the ax 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 that holds the handles in the axes. It is not recommended to name something handle

as it is the name of a Matlab built-in function. I also put these descriptors in an array so you can set the axis properties later if you want.

Also note that you can combine all the calls from set( hdl(i,j) , ... )

into one line, I only developed it here for clarity.

edit: look at the answers to these questions if you also want to hide the border of the ax (lines X0 and Y0).


This showed you how to get each ax mark to show, but in practice it is very messy. Instead, I would recommend just creating objects text

and determining how to position them next to each cake. At the very least, you don't have to manually control the visibility of everything else.

+1


source







All Articles