如何在matlab上制作透明的饼图?

How to make pie charts with transparency on matlab?

我目前在为饼图添加透明度时遇到问题。 我无法使用 FaceAlphaEdgeAlpha 进行设置,并且在编译 eps 文件时单独使用 alpha 会撕裂图表的边缘。

有什么建议吗?

figure;
subplot(1,2,1)
h=pie3(P1,[0 0 0 1 1])
set(h,'EdgeColor','none','LineStyle','none')
hold on
colormap cool
hold on

subplot(1,2,2)
h=pie3([PF PG],[1 0 ],{'X1','X2'})
set(h,'EdgeColor','none')
colormap cool
%alpha(0.5)

print teste -depsc2 

真的很难弄清楚你在问什么。
我的代码示例展示了一种更严格地控​​制图中对象的方法。
我希望您可以将我的示例修改为您可以使用的东西。
(如果不是,请插入图像和有关您的问题的更多详细信息,并添加 P1、PF、PG 的值)。

Matlab命令图形对象是一种"tree"结构。

结构是:

figure -> axes-> object
                 object
                 ...
                 object
       -> axes-> object
                 object
                 ...
                 object

轴是图形的子项,对象是轴的子项。

以下代码获取坐标轴句柄数组:

%Get handles to two axes inside figure;
h_axes_arr = get(gcf, 'Children');

以下代码获取对象句柄数组(第一个轴的子项):

%Array of handles - children of first axes.
h_arr = get(h_axes_arr(1), 'Children'); 

h = h_arr(1);
get(h, 'Type')查询第一个对象的类型

这是我的代码示例:

P1 = [1,3,0.5,2.5,2];
PF = 1;
PG = 2;

figure;
subplot(1,2,1)
h=pie3(P1,[0 0 0 1 1]);
set(h,'EdgeColor','none','LineStyle','none')
hold on
colormap cool
hold on

subplot(1,2,2)
h=pie3([PF PG],[1 0 ],{'X1','X2'});
set(h,'EdgeColor','none')
colormap cool
%alpha(0.5)

%Get handles to two axes inside figure;
h_axes_arr = get(gcf, 'Children');

%Array of handles - children of first axes.
h_arr = get(h_axes_arr(1), 'Children'); 

for i = 1:length(h_arr)
    %Handle to specific children.
    h = h_arr(i);
    if (isequal(get(h, 'Type'), 'surface'))
        %Set trasparency only if handle type is 'surface'
        set(h, 'FaceAlpha', 0.5); %Set Alpha to 0.5
    end
end

%Array of handles - children of second axes.
h_arr = get(h_axes_arr(2), 'Children'); 

for i = 1:length(h_arr)
    %Handle to specific children.
    h = h_arr(i);
    if (isequal(get(h, 'Type'), 'surface'))
        %Set trasparency only if handle type is 'surface'
        set(h, 'FaceAlpha', 0.3); %Set Alpha to 0.5
    end
end

%print teste -depsc2 

结果:

我知道它很难看...
我希望你能从中做出一些有用的东西。

pie3 的输出是句柄数组。有些是表面的句柄,有些是补丁,有些是文本。您需要 select 这些句柄的 子集 实际上具有 EdgeAlphaFaceAlpha 属性。您可以使用 findobj.

执行此操作
h = pie3(rand(1,5), [0 0 0 1 1]);

set(findobj(h, '-property', 'FaceAlpha'), 'FaceAlpha', 0.2);
set(findobj(h, '-property', 'EdgeAlpha'), 'EdgeAlpha', 0);

当导出到 EPS 时,不支持透明度。此外,由于您的图形具有透明度,因此 MATLAB 将使用 OpenGL 渲染器,这会导致 EPS 文件无法按照您的预期进行渲染。您可以尝试使用 export_fig 以获得更好的结果。