Matlab 轴标签不可见?

Matlab 轴标签不可见?,matlab,label,subplot,Matlab,Label,Subplot,我有以下代码: 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 percen

我有以下代码:

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
这将生成以下绘图:


为什么这根本不显示标签?我正试图在整个绘图中使用一个xlabel和一个ylabel,但我不明白为什么它们甚至不会在单个子绘图中显示。

对于
饼图和数学图,
X
Y
轴的概念对我来说没有什么意义,所以他们决定“隐藏”这些毫无意义的标签

不显示标签,因为饼图下面的每个轴都将其
可见属性设置为
'off'
。这将隐藏有关斧头的所有信息(即记号、网格线、背景色等)

如果它们对您来说并非毫无意义,并且您确实希望显示标签,则必须将轴
visible
属性设置为
'on'
。下面的代码是从您的示例中得到启发的,并向您展示了如何做到这一点

这种方法的问题在于,您必须手动“隐藏”您不想看到的所有其他内容。这就是为什么我隐藏了记号、背景和网格线,但斧头边框将保留

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
注意,我还更改了将控制柄固定到轴的变量。调用某个
handle
不是一个好主意,因为它是Matlab内置函数的名称。我还将这些句柄放在一个数组中,以便您可以在以后设置轴属性(如果需要)

还要注意的是,您可以将所有对
set(hdl(i,j),…)
的调用合并到一行中,为了清晰起见,我在这里开发了它

编辑:如果要同时隐藏轴边框(X0和Y0线),请查看中的答案



这向您展示了如何强制显示每个axe标签,但实际上它非常混乱。我建议只创建
text
对象,并确定如何将它们放置在每个饼图附近。至少,您不必手动管理其他所有内容的可见性。

如果他只想为整个绘图分组创建一个轴,那么创建一个虚拟轴并删除背景似乎更有意义。或者使用uicontrol创建一对文本标签。@excaza,完全同意您的意见。我展示的方法只是解释和回答为什么标签没有出现。在他的例子中,我只使用
text
对象。使用
text
影响轴标签。