Matlab三维饼图绘制函数pie3用法

4.3
(4)

今天,带来Matlab中绘制三维饼图的函数pie3的使用方法,饼图将将数据分割,然后每一块以一个扇形圆台显示并绘图,并且可以分割这些扇形圆台显示。这种饼图,看起来非常直观,也是数据统计中常用的绘图方法。

本文,主要介绍pie3函数的常见用法、语法说明、创建三维饼图、指定三维饼图的文本标签、比较两个饼图等方面的介绍。

Matlab三维饼图绘制函数pie3用法

下面我们将开始非常详细的 Matlab pie3 函数语法介绍,实例引用,结果展示。首先,我们给出 Matlab 中关于 pie3 函数的帮助文本如下:

>> help pie3
 pie3   3-D pie chart.
    pie3(X) draws a 3-D pie plot of the data in the vector X.  The
    values in X are normalized via X/SUM(X) to determine the area of
    each slice of pie.  If SUM(X) <= 1.0, the values in X directly
    specify the area of the pie slices.  Only a partial pie will be
    drawn if SUM(X) < 1.
 
    pie3(X,EXPLODE) is used to specify slices that should be  pulled out
    from the pie.  The vector EXPLODE must be the same size  as X.  The
    slices where EXPLODE is non-zero will be pulled out.
 
    pie3(...,LABELS) is used to label each pie slice with cell array
    LABELS.  LABELS must be the same size as X and can only contain
    strings.
 
    pie3(AX,...) plots into AX instead of GCA.
 
    H = pie3(...) returns a vector containing patch, surface, and text
    handles.
 
    Example
       pie3([2 4 3 5],[0 1 1 0],{'North','South','East','West'})

常见用法

pie3(X)
pie3(X,explode)
pie3(...,labels)
pie3(axes_handle,...)
h = pie3(...)

语法说明

pie3(X) 使用 X 中的数据绘制三维饼图。X 中的每个元素表示饼图中的一个扇区。

  • 如果 sum(X) ≤ 1,X 中的值直接指定饼图切片的面积。如果 sum(X) < 1,pie3 仅绘制部分饼图。
  • 如果 X 中元素的总和大于一,则 pie3 会通过 X/sum(X) 将值归一化,以确定饼图每个扇区的面积。

pie3(X,explode) 指定是否从饼图中心将扇区偏移一定位置。如果 explode(i,j) 非零,则从饼图中心偏移 X(i,j)。explode 和 X 的大小必须相同。

pie3(…,labels) 指定扇区的文本标签。标签数必须等于 X 中的元素数。

pie3(axes_handle,…) 将图形绘制到带有句柄 axes_handle 的坐标区中,而不是当前坐标区 (gca) 中。

h = pie3(…) 将句柄向量返回至补片、曲面和文本图形对象。

创建三维饼图

创建向量 x 的三维饼图。

x = [1,3,0.5,2.5,2];
figure
pie3(x)
Matlab三维饼图绘制函数pie3用法

为了偏移第二个饼图扇区,请将对应的 explode 元素设置为 1。

explode = [0,1,0,0,0];
figure
pie3(x,explode)
Matlab三维饼图绘制函数pie3用法

指定三维饼图的文本标签

创建三维饼图并指定文本标签。

x = 1:3;
labels = {'Taxes','Expenses','Profit'};
    
figure
pie3(x,labels)
Matlab三维饼图绘制函数pie3用法

比较两个饼图

创建包含两年财务数据的向量 y2010 和 y2011。然后创建一个包含值标签的元胞数组。

y2010 = [50 0 100 95];
y2011 = [65 22 97 120];
labels = {'Investments','Cash','Operations','Sales'};

创建一个 2×1 分块图布局,并在第一个图块中显示 y2010 数据的饼图和图例。然后在第二个图块中显示 y2011 数据的饼图和图例。

t = tiledlayout (2,1);
ax1 = nexttile;
pie3(ax1,y2010)
title('2010')
legend(labels)
ax2 = nexttile;
pie3(ax2,y2011)
title('2011')
legend(labels)

我这里是Matlab2016版本,没有tiledlayout和nexttile这两个函数。这里,我是用subplot这个函数来对比两个饼图,具体代码如下(此外,Matlab2016不支持显示0元素的饼图,所以我把y2010中的0元素改成了10):

y2010 = [50 10 100 95];
y2011 = [65 22 97 120];
labels = {'Investments','Cash','Operations','Sales'};
subplot(2,1,1)
pie3(y2010)
title('2010')
legend(labels)
subplot(2,1,2)
pie3(y2011)
title('2011')
legend(labels)
Matlab三维饼图绘制函数pie3用法

关于饼图绘制函数pie,可以参考之前的文章:Matlab饼图绘制函数pie用法大全

共计4人评分,平均4.3

到目前为止还没有投票~

很抱歉,这篇文章对您没有用!

让我们改善这篇文章!

告诉我们我们如何改善这篇文章?

文章目录

转载文章,原文出处:MathWorks官网,由古哥整理发布

如若转载,请注明出处:https://iymark.com/articles/735.html

(1)
微信公众号
古哥的头像古哥管理团队
上一篇 2020年11月06日 23:45
下一篇 2020年11月08日 12:59

你可能感兴趣的文章

发表回复

登录后才能评论
微信小程序
微信公众号