我有以下代码:
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,但我很困惑为什么他们甚至不能为各个子图显示。
答案 0 :(得分:1)
X
和Y
轴的概念对我来说对于pie
图表没什么意义,也可能对于 Mathworks ,所以他们决定“隐藏”这些毫无意义的标签。
不会显示标签,因为饼图下面的每个轴都将visible
属性设置为'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线),请查看this questions的答案。
这向您展示了如何强制显示每个斧头标签,但实际上它非常混乱。我建议只创建text
个对象并找出如何将它们放在每个饼图附近。至少您不必手动管理其他所有内容的可见性。