Matlab 散点饼图

Matlab 散点饼图,matlab,plot,pie-chart,matlab-figure,scatter-plot,Matlab,Plot,Pie Chart,Matlab Figure,Scatter Plot,我试图将软集群可视化。存在多个点和少量的簇,每个点以一定的概率属于每个簇 目前,我正在为每个簇覆盖一个散点图,“o”标记的大小随概率而变化。这样就可以很容易地识别出最可能的集群,但仅此而已 我想画一个饼图的散点图,即为许多数据点中的每个点绘制一个小饼图,显示这些概率。这在Matlab中是可能的吗?我还没有找到一种方法来将饼画成标记,或者将多个饼图放在一个绘图中的任意位置…亚伯拉罕·安德森在Matlab文件交换上的文章似乎与您所描述的内容相关 作为第一次尝试,我仅使用两个图形对象在每个点绘制饼图:

我试图将软集群可视化。存在多个点和少量的簇,每个点以一定的概率属于每个簇

目前,我正在为每个簇覆盖一个散点图,“o”标记的大小随概率而变化。这样就可以很容易地识别出最可能的集群,但仅此而已

我想画一个饼图的散点图,即为许多数据点中的每个点绘制一个小饼图,显示这些概率。这在Matlab中是可能的吗?我还没有找到一种方法来将饼画成标记,或者将多个饼图放在一个绘图中的任意位置…

亚伯拉罕·安德森在Matlab文件交换上的文章似乎与您所描述的内容相关


作为第一次尝试,我仅使用两个图形对象在每个点绘制饼图:一个用于圆,另一个用于圆内的分割。因此,我们只是绘制未填充的饼图

这在性能方面非常有效。它是通过使用
NaN
将线分割成段来实现的。将其与其他建议的解决方案进行比较;如果我们观察它,我们会发现它为每个点创建一个轴,并在其中调用MATLAB函数

我们从一些数据点及其“模糊聚类”开始:

下面是绘制饼图散点图的代码:

%# pie parameters
theta = linspace(0, 2*pi, 100); %# steps to approximate a circle
r = min(range(points)) / 10;    %# radius (determined based on points spread)

%# pie circles
px = bsxfun(@plus, cos(theta).*r, points(:,1))';
py = bsxfun(@plus, sin(theta).*r, points(:,2))';
px(end+1,:) = NaN; py(end+1,:) = NaN;

%# pie divisions
tt = cumsum(prob,2) .* 2*pi;
qx = cat(3, ...
    bsxfun(@plus, cos(tt).*r, points(:,1)), ...
    repmat(points(:,1), [1 numClasses]), ...
    NaN(numPoints,numClasses));
qy = cat(3, ...
    bsxfun(@plus, sin(tt).*r, points(:,2)), ...
    repmat(points(:,2), [1 numClasses]), ...
    NaN(numPoints,numClasses));
qx = permute(qx, [3 2 1]); qy = permute(qy, [3 2 1]);

%# plot
figure
line(px(:), py(:), 'Color','k')
line(qx(:), qy(:), 'Color','k')
axis equal


在我的第二次尝试中,我通过使用函数绘制每个圆中的每个切片来绘制彩色饼图。显然,这意味着我们正在创建比以前多得多的图形对象

我们本可以使用相同的
NaN
技术,使用单个补丁调用从每个圆绘制相同的切片,但当饼图重叠时(特别是z顺序不正确),结果证明是有问题的


如果百分比标签太多,只需删除上面的呼叫。

啊,谢谢,我不知道文件交换。但是,用这种方式轻松绘制数百个数据点有点太慢了。太棒了!我必须使用
set(gcf,'Renderer','painters')
或行将位于所有内容的顶部。@Amro:我建议您将其作为FileExchange提交。如果使用输入输出参数、错误处理等进行适当处理,它可能很容易成为“一周中的峰值”。MATLAB中确实缺少此类函数。BubblePie对每个饼图使用单独的轴,并且还有许多其他问题。祝你好运有一个建议:根据
sum(prob,2)
(对于初始prob)来确定圆的半径
r
。@yuk:谢谢,也许我会这么做(我一直想向FEX提交一些自定义文件,但从来没有为函数创建一个干净的API)。如果你愿意的话,你也可以这样做,因为so上的所有贡献都是在下面授权的,所以添加到这篇文章的链接就足够了(有点像FEX上的“灵感来源”)
%# pie parameters
theta = linspace(0, 2*pi, 100); %# steps to approximate a circle
r = min(range(points)) / 10;    %# radius (determined based on points spread)

%# pie circles
px = bsxfun(@plus, cos(theta).*r, points(:,1))';
py = bsxfun(@plus, sin(theta).*r, points(:,2))';
px(end+1,:) = NaN; py(end+1,:) = NaN;

%# pie divisions
tt = cumsum(prob,2) .* 2*pi;
qx = cat(3, ...
    bsxfun(@plus, cos(tt).*r, points(:,1)), ...
    repmat(points(:,1), [1 numClasses]), ...
    NaN(numPoints,numClasses));
qy = cat(3, ...
    bsxfun(@plus, sin(tt).*r, points(:,2)), ...
    repmat(points(:,2), [1 numClasses]), ...
    NaN(numPoints,numClasses));
qx = permute(qx, [3 2 1]); qy = permute(qy, [3 2 1]);

%# plot
figure
line(px(:), py(:), 'Color','k')
line(qx(:), qy(:), 'Color','k')
axis equal
clr = hsv(numClasses);          %# colors for each class
r = min(range(points)) / 10;    %# radius (determined based on points spread)
tt = cumsum(prob,2) .* 2*pi;    %# pie divisions

figure
h = zeros(numPoints,numClasses);    %# handles to patches
for idx=1:numPoints                 %# for each point
    for k=1:numClasses              %# for each class
        %# start/end angle of arc
        if k>1
            t(1) = tt(idx,k-1);
        else
            t(1) = 0;
        end
        t(2) = tt(idx,k);

        %# steps to approximate an arc from t1 to t2
        theta = linspace(t(1), t(2), 50);

        %# slice (line from t2 to center, then to t1, then an arc back to t2)
        x = points(idx,1) + r .* [cos(t(2)) ; 0 ; cos(t(1)) ; cos(theta(:))];
        y = points(idx,2) + r .* [sin(t(2)) ; 0 ; sin(t(1)) ; sin(theta(:))];
        h(idx,k) = patch('XData',x, 'YData',y, ...
            'FaceColor',clr(k,:), 'EdgeColor','k');

        %# show percentage labels
        ind = fix(numel(theta)./2) + 3;     %# middle of the arc
        text(x(ind), y(ind), sprintf('%.2f%%', prob(idx,k)*100), ...
            'Color','k', 'FontSize',6, ...
            'VerticalAlign','middle', 'HorizontalAlign','left');
    end
end
axis equal

labels = cellstr( num2str((1:numClasses)', 'Cluster %d') );
legend(h(1,:), labels)