PieChart
更多信息和选项
- 当中间留下一个洞时,饼图也称为圆环图.
- PieChart 将数据集中的值显示为整个圆的比例切片. 饼图通常用于较小的数据.
- 可以用下列形式给出 PieChart 的数据元素:
-
yi 一个扇区的值 Quantity[yi,unit] 带有单位的扇区的值 wi[yi,…] 由值 yi 和封装 wi 定义的一个扇区 formi->mi 具有元数据 mi 的一个扇区 - 没有按这些形式给出的数据在饼图的形成过程中被忽略.
- 可以用下列形式给出 PieChart 中的数据集:
-
{e1,e2,…} 带有封装或无封装的元素列表 <|k1y1,k2y2,…|> 由键和数值组成的关联 TimeSeries[…],EventSeries[…],TemporalData[…] 时间序列、事件序列和暂态数据 WeightedData[…],EventData[…] 增广数据集 w[{e1,e2,…},…] 应用到整个数据集的封装 w[{data1,data1,…},…] 应用到所有数据集的封装 - PieChart[objcspec] 用列指定 cspec 从 Tabular、TimeSeries 或 EventSeries 对象 obj 中提取值并绘制.
- 可使用以下形式的列指定 cspec 来绘制表格数据:
-
col 绘制列 col 的值 {col1,col2,…,coln} 将列 {col1, …, coln} 的值作为一组数据来绘制 - 下列封装可以用于图表元素:
-
Annotation[e,label] 提供一个注解 Button[e,action] 当点击元素时,执行的行为 Callout[e,label] 使用标注显示元素 EventHandler[e,…] 定义元素的普通事件处理 Hyperlink[e,uri] 使得元素作为一个超链接 Labeled[e,…] 用标签显示元素 Legended[e,…] 在一个图例中元素的特例 Mouseover[e,over] 使得元素显示为一个鼠标指向的形式 PopupWindow[e,cont] 为元素增加一个弹出窗口 StatusArea[e,label] 当鼠标指向时,在状态栏上显示 Style[e,opts] 用指定的样式显示元素 Tooltip[e,label] 为元素增加一个提示工具 - 在 PieChart 中,Labeled 和 Placed 允许使用下列位置:
-
"RadialOuter","RadialCenter","RadialInner" 扇区内的坐标 "RadialOutside","RadialInside","RadialEdge" 扇区外的坐标 "RadialCallout", "VerticalCallout" 标注线的坐标 {{sθ,sr},{lx,ly}} 缩放标签中坐标 {lx,ly} 到扇区中极坐标 {sθ,sr} - 在 PieChart 中,Callout 允许下列坐标 pos:
-
Automatic 自动放置 {x,y} 图形中的坐标 Scaled[{sθ,sr}] 扇区内缩放的极坐标 {sθ,sr} {pos,{lx,ly}} 在位置 pos 处标签中的缩放坐标 {lx,ly} - PieChart 有和 Graphics 相同的选项,不同之处及增加选项如下所示: [所有选项的列表]
-
ChartElementFunction Automatic 如何产生扇区的原图形 ColorFunction Automatic 如何着色扇区 ColorFunctionScaling True 是否将提供给 ColorFunction 的参数归一化 LabelingFunction Automatic 如何标注扇区 LabelingSize Automatic 标注和标签的最大尺寸 LegendAppearance Automatic 图例的整体外观 PerformanceGoal $PerformanceGoal 优化的目标 PlotInteractivity $PlotInteractivity 是否允许绘制互动元素 PlotLabels None 扇区的分类标签 PlotLayout Automatic 使用的整体布局 PlotLegends None 数据元素和数据集的图例 PlotRange Automatic 包含数值的范围 PlotStyle Automatic 扇区的样式 PlotTheme $PlotTheme 饼图的整体外观样式 PolarAxes False 是否绘制极轴 PolarAxesOrigin Automatic 极轴的位置 PolarGridLines None 绘制极网格线 PolarTicks Automatic 极轴刻度 SectorOrigin Automatic 初始角度和扇区弧度 SectorSpacing Automatic 扇区间的间距 TargetUnits Automatic 显示在图中的单位 - 在单个显示面板中显示多个数据集的 ChartLayout 的可能设置包括:
-

"Grouped" 分离每个数据集的数据 
"Stacked" 叠加每个数据集的数据 - 在不同面板中显示单个数据集的 ChartLayout 的可能设置包括:
-
"Column" 在一列面板中使用单独的图表 "Row" 在一行面板中使用单独的图表 {"Column",k},{"Row",k} 使用 k 列或行 {"Column",UpTo[k]},{"Row",UpTo[k]} 使用至多 k 列或行 - PlotLegends 的常见设置包括:
-
None 没有图例 Automatic 自动确定图例 {lbl1,lbl2,…} 用 lbl1, lbl2, … 作为图例的标签 Placed[lspec,…] 指定图例的位置 - PlotStylesty 指定每组数据使用的样式. 可能的设置包括:
-
{sty1,sty2,…} 针对每组数据的一系列样式 <|"key"val,…|> 针对不同层级的数据的样式元素 - 接受的键有:
-
"Base" 所有扇区的整体样式 "Elements" 针对每个组中的元素 yi 的样式列表 "Groups" 每个数据组 datai 的样式列表 - ColorData["DefaultChartColors"] 给出 PlotStyle 使用的默认颜色序列.
- ChartElementFunction 的参数是扇区区域 {{θmin,θmax},{rmin,rmax}},值 yi 和数据集的嵌套列表中每层的元数据 {m1,m2,…}.
- ChartElementFunction 的内置列表可以从 ChartElementData["PieChart"] 得到.
- 提供给 ColorFunction 的参数是 yi.
- PieChart 中选项和其它结构的样式或其它设置按照 ChartStyle、ColorFunction、Style、其它封装和 ChartElementFunction 顺序作用,后面的设置会屏蔽之前的设置.
所有选项的列表
范例
打开所有单元 关闭所有单元基本范例 (4)
PieChart[{1, 2, 3, 4}]PieChart[{1, 2, 3, 4}, SectorOrigin -> {Automatic, 1}]PieChart[{{1, 2, 3}, {2, 2, 1}}]PieChart[{{1, 2, 3}, {2, 2, 1}}, ChartLayout -> "Row"]PieChart[Range[5], PlotStyle -> {RGBColor[0.237736, 0.340215, 0.575113], RGBColor[0.277947, 0.45009699999999997, 0.32815550000000004], RGBColor[0.624866, 0.673302, 0.264296], RGBColor[0.8453409999999999, 0.6248695, 0.3151775], RGBColor[0.72987, 0.239399, 0.230961]}]范围 (33)
数据和布局 (13)
PieChart[{{1, 1, 1}, {2, 2, 2}, {3, 3, 3}}]PieChart[{{1, 2}, {1, 2, 3}, {1, 2, 3, 4}}]PieChart[{{1, Missing[], 3}, {4, 2, 1 + I, 2}, {foo, 2, 4}}]PieChart[{{1, 1, 1, 1}, {Quantity[1, "Meters"], Quantity[1, "Feet"], Quantity[1, "Yards"], Quantity[1, "Inches"]}}]PieChart[{Quantity[1, "Meters"], Quantity[1, "Feet"], Quantity[1, "Yards"], Quantity[1, "Inches"]}, TargetUnits -> "Meters", PolarAxes -> {True, False}]忽略 TimeSeries、EventSeries 和 TemporalData 中的时间戳:
PieChart[TimeSeries[{19, 16, 9, 3, 7, 2, 17}, {"May 24, 1982"}]]PieChart[<|"a" -> 1, "b" -> 2, "c" -> 5, "d" -> 3|>]PieChart[<|"a" -> 1, "b" -> 2, "c" -> 5, "d" -> 3|>, PlotLabels -> Automatic]PieChart[<|"a" -> 1, "b" -> 2, "c" -> 5, "d" -> 3|>, PlotLabels -> Callout[Automatic]]PieChart[<|"a" -> 1, "b" -> 2, "c" -> 5, "d" -> 3|>, PlotStyle -> {Hue[0.61, 0.7, 1], Hue[0.17, 0.4, 0.65], Hue[0.64, 0.5, 0.75], Hue[0.45, 0.4, 0.7]}, PlotLegends -> Automatic]PieChart[<|"group a" -> <|"a" -> 1, "b" -> 2, "c" -> 5, "d" -> 3|>, "group b" -> <|"a" -> 4, "b" -> 1, "c" -> 3, "d" -> 2|>|>, PlotLegends -> Automatic]忽略 WeightedData 中的权重:
PieChart[WeightedData[{1, 2, 3, 4, 5}, {0.5, 0.2, 0.1, 0.2, 0.3}]]忽略 EventData 中的删失和截断信息:
PieChart[EventData[{8, 3, 5, 4, 9}, {0, 1, 1, 0, 0}]]Table[PieChart[{{1, 2, 3}, {1, 3, 2, 4}}, ChartLayout -> l], {l, {"Grouped", "Stacked"}}]Table[PieChart[{1, 2, 3}, SectorOrigin -> o, PlotLabel -> o], {o, {{Pi / 6, "Clockwise"}, {Pi / 6, "Counterclockwise"}}}]Table[PieChart[{1, 2, 3}, SectorOrigin -> o, PlotLabel -> o], {o, {0, Pi / 2}}]Table[PieChart[{1, 2, 3}, SectorOrigin -> o, PlotLabel -> o], {o, {{{0, "Clockwise"}, 0}, {{0, "Clockwise"}, 1}}}]Table[PieChart[{Range[4], Range[4]}, SectorSpacing -> s, PlotLabel -> s], {s, {Automatic, {0, 1}, {0.1, 1}}}]表格数据 (3)
获取表格数据,按 "class" 和 "survived" 列计数:
titanic = ResourceData["Sample Tabular Data: Titanic"]AggregateRows[titanic, "count" -> Function[Length[#class]], "class"]PieChart[% -> "count", PlotLabels -> {"1st", "2nd", "3rd"}]AggregateRows[titanic, "count" -> Function[Length[#class]], "survived"]PieChart[% -> "count", PlotLabels -> {"survived", "perished"}]pivot = PivotToColumns[AggregateRows[titanic, "count" -> Function[Length[#class]], {"class", "survived"}], "class" -> "count"]绘制 TimeSeries 或 EventSeries 中所有分量的值:
PieChart[TimeSeries[TimeEventSeries`TimestampData[Association["UniformlySpacedQ" -> True, "Count" -> 5,
"Endpoints" -> TabularColumn[Association[
"Data" -> {2, {{NumericArray[{20551, -2147483648}, "Integer32"], {},
DataStructure["BitVec ... rColumn[Association[
"Data" -> {{2, 3, 4, 5, 9}, {}, None}, "ElementType" -> "Integer64"]],
TabularColumn[Association["Data" -> {{15, 15, 13, 11, 10}, {}, None},
"ElementType" -> "Integer64"]]}}]]]], Association[]]]绘制 TimeSeries 或 EventSeries 中一个分量的值:
ts = TimeSeries[TimeEventSeries`TimestampData[Association["UniformlySpacedQ" -> True, "Count" -> 5,
"Endpoints" -> TabularColumn[Association[
"Data" -> {2, {{NumericArray[{20551, -2147483648}, "Integer32"], {},
DataStructure["BitVec ... rColumn[Association[
"Data" -> {{2, 3, 4, 5, 9}, {}, None}, "ElementType" -> "Integer64"]],
TabularColumn[Association["Data" -> {{15, 15, 13, 11, 10}, {}, None},
"ElementType" -> "Integer64"]]}}]]]], Association[]];PieChart[ts -> "fish"]PieChart[ts -> {"cats", "dogs"}]封装 (5)
{PieChart[{{1, Style[2, RGBColor[0.93, 0.27, 0.27]], 3}, {4, 5, 6}}], PieChart[{Style[{1, 2, 3}, RGBColor[0.14, 0.8, 0.14]], {4, 5, 6}}], PieChart[Style[{{1, 2, 3}, {4, 5, 6}}, RGBColor[0.4, 0.6, 1]]]}{PieChart[{{1, Style[2, RGBColor[0.93, 0.27, 0.27]], 3}, {4, 5, 6}}], PieChart[{Style[{1, Style[2, RGBColor[0.93, 0.27, 0.27]], 3}, RGBColor[0.14, 0.8, 0.14]], {4, 5, 6}}], PieChart[Style[{Style[{1, Style[2, RGBColor[0.93, 0.27, 0.27]], 3}, RGBColor[0.14, 0.8, 0.14]], {4, 5, 6}}, RGBColor[0.4, 0.6, 1]]]}PieChart[{1, Tooltip[2, "median"], 3}]PieChart[Table[Tooltip[CountryData[c, "Population"], CountryData[c, "Flag"]], {c, CountryData["G7"]}]]用 PopupWindow 提供其它细目的信息:
PieChart[{1, PopupWindow[2, DateListPlot[FinancialData["IBM", "Jan. 1, 2004"]]], 3}]Button 可以用于触发任何行为:
PieChart[{1, Button[2, Speak[2]], 3}]样式和外观 (5)
PieChart[{1, 2, 3, 4}, PlotStyle -> {RGBColor[0.93, 0.27, 0.27], RGBColor[0.14, 0.8, 0.14], RGBColor[0.4, 0.6, 1], RGBColor[1, 0.75, 0]}]ChartBaseStyle 可以对所有图表元素设置一个初始样式:
PieChart[Range[5], PlotStyle -> EdgeForm[Dashed]]可以用 Style 改写样式:
PieChart[{1, 2, Style[3, RGBColor[0.93, 0.27, 0.27]], 4, 5}, PlotStyle -> 45]ChartElementData["PieChart"]Table[PieChart[{1, 2, 3, 4, 5}, ChartElementFunction -> f, PlotStyle -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.898695, 0.686452, 0.6785475], RGBColor[0.9584254999999999, 0.877884, 0.5906629999999999], RGBColor[0.86116075, 0.930182, 0.758764], RGBColor[0.431296, 0.709773, 0.927077]}], {f, {"NoiseSector", "PlateauSector"}}]PieChart[{1, 2, 3, 4, 5}, ChartElementFunction -> ChartElementDataFunction["GlassSector", "GradientDirection" -> "Angular"], PlotStyle -> "SolarColors"]PieChart[Tuples[{1, 2}, 2], PlotTheme -> "Marketing"]PieChart[Tuples[{1, 2}, 3], PlotTheme -> "Monochrome"]标签和图例 (7)
用 Labeled 对一个气泡增加标签:
PieChart[{1, Labeled[2, "label"], 3}]Table[PieChart[{1, Labeled[2, "label", p], 3}, PlotLabel -> p, SectorOrigin -> {Automatic, 1}], {p, {"RadialInner", "RadialCenter", "RadialOuter"}}]Table[PieChart[{1, Labeled[2, "label", p], 3}, PlotLabel -> p, SectorOrigin -> {Automatic, 1}], {p, {"RadialInside", "RadialOutside"}}]Table[PieChart[{Labeled[1, "label 1", p], Labeled[2, "label 2", p], Labeled[3, "label 3", p]}, PlotLabel -> p, PlotRange -> 1.5], {p, {"RadialCallout", "VerticalCallout"}}]使用 Callout 对扇区添加标签:
PieChart[{1, Callout[2, "label"], 3}]PieChart[{1, Callout[2, "label", Appearance -> "Balloon"], 3}]PieChart[Callout[#, Unique["label"]]& /@ RandomReal[{0, 1}, 6]]用 LabelingFunction 对扇区提供值的标签:
PieChart[{1, 2, 3}, LabelingFunction -> "RadialOutside"]PieChart[{5, 2, 9, 3, 2, 7}, LabelingFunction -> (Callout[Style[#, 10 + 5#], Automatic]&)]选项 (71)
ChartElementFunction (6)
ChartElementFunction 可能的字符值:
ChartElementData["PieChart"]Table[PieChart[{1, 2, 3, 4, 5}, ChartElementFunction -> f, PlotStyle -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.898695, 0.686452, 0.6785475], RGBColor[0.9584254999999999, 0.877884, 0.5906629999999999], RGBColor[0.86116075, 0.930182, 0.758764], RGBColor[0.431296, 0.709773, 0.927077]}, PlotLabel -> f], {f, {"Sector", "PlateauSector"}}]Table[PieChart[{1, 2, 3, 4, 5}, ChartElementFunction -> f, PlotStyle -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.898695, 0.686452, 0.6785475], RGBColor[0.9584254999999999, 0.877884, 0.5906629999999999], RGBColor[0.86116075, 0.930182, 0.758764], RGBColor[0.431296, 0.709773, 0.927077]}, PlotLabel -> f], {f, {"NoiseSector", "OscillatingSector"}}]Table[PieChart[{1, 2, 3, 4, 5}, ChartElementFunction -> f, PlotStyle -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.898695, 0.686452, 0.6785475], RGBColor[0.9584254999999999, 0.877884, 0.5906629999999999], RGBColor[0.86116075, 0.930182, 0.758764], RGBColor[0.431296, 0.709773, 0.927077]}, PlotLabel -> f], {f, {"SquareWaveSector", "TriangleWaveSector"}}]Table[PieChart[{1, 2, 3, 4, 5}, ChartElementFunction -> f, PlotStyle -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.898695, 0.686452, 0.6785475], RGBColor[0.9584254999999999, 0.877884, 0.5906629999999999], RGBColor[0.86116075, 0.930182, 0.758764], RGBColor[0.431296, 0.709773, 0.927077]}, PlotLabel -> f], {f, {"GlassSector", "GradientSector"}}]PieChart[{1, 2, 3, 4}, ChartElementFunction -> Function[{angleRadiusMinMax, yr, meta}, ChartElementData["TriangleWaveSector"][angleRadiusMinMax, yr, meta]]]写入一个定制的 ChartElementFunction:
f[{{t0_, t1_}, {r0_, r1_}}, ___] := Disk[{0, 0}, r1, {t0, t1}]PieChart[{1, 2, 3, 4, 5}, ChartElementFunction -> f]g[{{t0_, t1_}, {r0_, r1_}}, ___] := GraphicsGroup[{Circle[{0, 0}, r0, {t0, t1}], Circle[{0, 0}, r1, {t0, t1}],
Line[{r0{Cos[t0], Sin[t0]}, r1{Cos[t1], Sin[t1]}}]}]PieChart[{1, 2, 3, 4, 5}, PlotStyle -> Directive[{Thick, Blue}], ChartElementFunction -> g]DataDrilldownSector[{{t0_, t1_}, {r0_, r1_}}, y_, {data_List}] :=
PopupWindow[ChartElementData["NoiseSector"][{{t0, t1}, {r0, r1}}, y], BarChart[data]]DataDrilldownSector[{{t0_, t1_}, {r0_, r1_}}, y_, _] :=
ChartElementData["Sector"][{{t0, t1}, {r0, r1}}, y]PieChart[{1 -> Range[5], 2, 3 -> RandomReal[1, 10]}, ChartElementFunction -> DataDrilldownSector]内置基本函数可能有选项,用 面板 ▶ 图表元素方案 设置它们:
ChartElementData["GradientSector", "Options"]Table[PieChart[{1, 2, 3}, ChartElementFunction -> ChartElementData["GradientSector", "ColorScheme" -> "DeepSeaColors", "GradientDirection" -> dir]], {dir, {"Angular", "Radial", "DescendingAngular", "DescendingRadial"}}]ColorFunction (3)
PieChart[Table[Exp[-t ^ 2], {t, -2, 2, 0.25}], ColorFunction -> "Rainbow"]用 ColorFunctionScaling->False,获得未缩放的高度值:
PieChart[{1, 2, 3}, ColorFunction -> (Switch[#, 1, RGBColor[1, 0.75, 0], 2, RGBColor[0.98, 0.56, 0.17], 3, RGBColor[0.93, 0.27, 0.27]]&), ColorFunctionScaling -> False]ColorFunction 会覆盖 PlotStyle 中的样式:
PieChart[{1, 2, 3}, PlotStyle -> {RGBColor[0.93, 0.27, 0.27], RGBColor[0.14, 0.8, 0.14], RGBColor[0.4, 0.6, 1]}, ColorFunction -> (Blend[{LightBlue, LightRed}, #]&)]用 ColorFunction 组合不同样式效果:
PieChart[Table[Exp[-t ^ 2], {t, -2, 2, 0.25}], ColorFunction -> Function[{angle}, Opacity[angle]], PlotStyle -> RGBColor[0.8, 0.3, 0.8]]ColorFunctionScaling (3)
PieChart[{1, 2, 3}, ColorFunction -> (Blend[{LightBlue, LightRed}, #]&)]把 ColorFunctionScaling 设为 False 以允许把原始值传递给颜色函数:
PieChart[Range@25, ColorFunction -> Function[{y}, ColorData[2][y]], ColorFunctionScaling -> False]使用 ColorFunctionScaling->False,获得未调整的高度值:
PieChart[{1, 2, 3}, ColorFunction -> (Switch[#, 1, RGBColor[1, 0.75, 0], 2, RGBColor[0.98, 0.56, 0.17], 3, RGBColor[0.93, 0.27, 0.27]]&), ColorFunctionScaling -> False]ImageSize (7)
使用有名称的尺寸,如 Tiny、Small、Medium 和 Large:
{PieChart[{1, 2, 3, 4}, ImageSize -> Tiny], PieChart[{1, 2, 3, 4}, ImageSize -> Small]}PieChart[{1, 2, 3, 4}, ImageSize -> 150]PieChart[{1, 2, 3, 4}, ImageSize -> {Automatic, 150}]PieChart[{1, 2, 3, 4}, ImageSize -> UpTo[200]]PieChart[{1, 2, 3, 4}, ImageSize -> {250, 200}, Background -> LightBlue]PieChart[{1, 2, 3, 4}, ImageSize -> {UpTo[150], UpTo[100]}]设置 ImageSizeFull 可填充对象中的可用空间:
chart = PieChart[{1, 2, 3, 4}, ImageSize -> Full];{Framed[Pane[chart, {100, 100}]], Framed[Pane[chart, {200, 200}]]}Framed[Pane[PieChart[{1, 2, 3, 4}, ImageSize -> {Scaled[0.5], Scaled[0.5]}, Background -> LightBlue], {200, 100}]]LabelingFunction (6)
Tooltip 和 StatusArea 使用自动标签值:
PieChart[{1, 2, 3}, LabelingFunction -> Automatic]PieChart[{1, 2, 3}, LabelingFunction -> None]用 Placed 控制标签坐标:
Table[PieChart[{1, 2, 3}, LabelingFunction -> p, PlotLabel -> p, Ticks -> None], {p, {"RadialInner", "RadialCenter", "RadialOuter"}}]Table[PieChart[{1, 2, 3}, SectorOrigin -> {Automatic, 1}, LabelingFunction -> p, PlotLabel -> p, Ticks -> None], {p, {"RadialInside", "RadialOutside", "RadialEdge"}}]Table[PieChart[{1, 2, 3, 4, 5}, SectorOrigin -> {Automatic, 1}, LabelingFunction -> p, PlotLabel -> p, Ticks -> None], {p, {"RadialCallout", "VerticalCallout"}}]Table[PieChart[{1, 2, 3}, SectorOrigin -> {Automatic, 1}, LabelingFunction -> p, PlotLabel -> p], {p, {{0.1, 0.1}, {1 / 2, 1 / 2}, {1, 1}}}]使用 Callout 自动放置标签:
PieChart[RandomReal[{1, 10}, 5], LabelingFunction -> (Callout[Row[{"$", NumberForm[#, {2, 2}]}], Automatic]&)]PieChart[{1, 2, 3}, LabelingFunction -> (Placed[Row[{"$", #}], "RadialOutside"]&)]LabelingSize (4)
PieChart[{1, 2, 3, 3, 5, 6}, PlotLabels -> {"healthfulness", "obstreperous", "spectrogram", "vestige", "coinage", "limey"}]PieChart[{1, 2, 3, 3, 5, 6}, PlotLabels -> {[image], [image], [image], [image], [image], [image], [image]}]PieChart[{1, 2, 3, 3, 5, 6}, PlotLabels -> {"healthfulness", "obstreperous", "spectrogram", "vestige", "coinage", "limey"}, LabelingSize -> 50]PieChart[{1, 2, 3, 3, 5, 6}, PlotLabels -> {[image], [image], [image], [image], [image], [image], [image]}, LabelingSize -> 50]PieChart[{1, 2, 3, 3, 5, 6}, PlotLabels -> {[image], [image], [image], [image], [image], [image], [image]}, LabelingSize -> Full, ImageSize -> Medium]PerformanceGoal (3)
PieChart[Range[10], PerformanceGoal -> "Quality"]PieChart[Range[10], PerformanceGoal -> "Speed"]Table[ByteCount@PieChart[Range[10], PerformanceGoal -> p], {p, {"Quality", "Speed"}}]PlotInteractivity (4)
PieChart[{1, 2, 3}]PieChart[{1, 2, 3}, PlotInteractivity -> False]PieChart[{1, 2, Tooltip[3, "Hello"]}, PlotInteractivity -> False]PieChart[{1, 2, Tooltip[3, "Hello"]}, PlotInteractivity -> <|"User" -> True, "System" -> False|>]PlotLabels (9)
PieChart[{1, 2, 3}, PlotLabels -> {"a", "b", "c"}]PieChart[{{1, 2, 3}, {1, 2}}, PlotLabels -> {"a", "b"}]数据中 Labeled 封装将放置额外的标签:
PieChart[{1, Labeled[2, "label", "RadialOutside"], 3}, PlotLabels -> {"a", "b", "c"}]用 Placed 控制标签的放置:
Table[PieChart[{1, 2, 3}, PlotLabels -> Placed[{"a", "b", "c"}, p], PlotLabel -> p], {p, {"RadialInner", "RadialCenter", "RadialOuter"}}]Table[PieChart[{1, 2, 3}, SectorOrigin -> {Automatic, 1}, PlotLabels -> Placed[{"a", "b", "c"}, p], PlotLabel -> p, Ticks -> None], {p, {"RadialInside", "RadialOutside", "RadialEdge"}}]Table[PieChart[{1, 2, 3, 4, 5}, SectorOrigin -> {Automatic, 1}, PlotLabels -> Placed[{"a", "b", "c", "d", "e"}, p], PlotLabel -> p, Ticks -> None], {p, {"RadialCallout", "VerticalCallout"}}]用 Callout 连接标签与扇区:
PieChart[{5, 4, 7}, PlotLabels -> Callout[{"c1", "c2", "c3"}, Automatic]]用 Callout 自动优化标签的位置:
PieChart[ReverseSort@RandomReal[10, 20], PlotLabels -> Callout[Range[20], Automatic]]Table[PieChart[{1, 2, 3}, SectorOrigin -> {Automatic, 1}, PlotLabels -> Placed[{"aa", "bb", "cc"}, p], Ticks -> None, PlotLabel -> p], {p, {{0.1, 0.1}, {1 / 2, 1 / 2}, {1, 1}}}]Table[PieChart[{1, 2, 3}, PlotRange -> 2.8, SectorOrigin -> {Automatic, 1}, PlotLabels -> Placed[Framed /@ {"aa", "bb", "cc"}, {{1, 1}, p}], Ticks -> None, PlotLabel -> p], {p, {{0.1, 0.1}, {1 / 2, 1 / 2}, {1, 1}}}]用 Placed 的第三个参数控制格式:
PieChart[{1, 2, 3}, PlotLabels -> Placed[{"aaa", "bbb", "ccc"}, "RadialCenter", Rotate[#, 45Degree]&]]PieChart[{1, 2, 3}, PlotLabels -> Placed[{"aaa", "bbb", "ccc"}, "RadialCenter", Panel[#, FrameMargins -> 0]&]]PieChart[{1, 2, 3}, PlotLabels -> Placed[{"aaa", "bbb", "ccc"}, "RadialCenter", Hyperlink[#, "http://www.wolfram.com"]&]]PieChart[{{1, 2, 3}, {4, 5, 6}}, PlotLabels -> {"r1", "r2"}]PieChart[{{1, 2, 3}, {4, 5, 6}}, PlotLabels -> <|"Elements" -> {"c1", "c2", "c3"}|>]PieChart[{{1, 2, 3}, {4, 5, 6}}, PlotLabels -> <|"Groups" -> {"r1", "r2"}, "Elements" -> {"c1", "c2", "c3"}|>]用 Placed 来改变放置的位置:
PieChart[{{1, 2, 3}, {4, 5, 6}}, PlotLabels -> <|"Groups" -> Placed[{"r1", "r2"}, "VerticalCallout"], "Elements" -> Placed[{"c1", "c2", "c3"}, "RadialCenter"]|>]PieChart[{1, 2, 3}, PlotLabels -> Placed[{{"a", "b", "c"}, {"x", "y", "z"}}, {"RadialCenter", "RadialCallout"}]]PlotLayout (4)
PlotLayout 默认按同心环分组:
PieChart[{{1, 2, 3}, {2, 2, 1}}]PieChart[{{1, 2, 3}, {2, 2, 1}}, PlotLayout -> "Grouped"]PieChart[{{1, 2, 3}, {2, 2, 1}}, PlotLayout -> "Stacked"]PieChart[RandomReal[1, {10, 5}], PlotLayout -> "Stacked"]PieChart[{{1, 2, 3}, {2, 2, 1}}, PlotLayout -> "Column"]PieChart[{{1, 2, 3}, {2, 2, 1}}, ImageSize -> Medium, PlotLayout -> "Row"]PieChart[{{1, 2, 3}, {2, 2, 1}, {4, 1, 3}, {5, 6, 3}, {4, 3, 3}, {5, 2, 3}}, ImageSize -> Small, PlotLayout -> {"Column", 4}]PieChart[{{1, 2, 3}, {2, 2, 1}, {4, 1, 3}, {5, 6, 3}, {4, 3, 3}, {5, 2, 3}}, ImageSize -> Small, PlotLayout -> {"Column", UpTo[4]}]PlotLegends (7)
PieChart[{{1, 2, 3}, {1, 2}}, PlotLegends -> <|"Elements" -> {"ccc1", "ccc2", "ccc3"}|>, PlotStyle -> <|"Elements" -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.9584254999999999, 0.877884, 0.5906629999999999], RGBColor[0.431296, 0.709773, 0.927077]}|>]PieChart[{{1, 2, 3}, {4, 5}}, PlotLegends -> <|"Groups" -> {"rr1", "rr2"}|>, PlotStyle -> <|"Groups" -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.431296, 0.709773, 0.927077]}|>]用 Legended 添加其他图例:
PieChart[{{1, Legended[Style[2, RGBColor[0.93, 0.27, 0.27]], "aa"], 3}, {4, 2}}, PlotStyle -> <|"Elements" -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.9584254999999999, 0.877884, 0.5906629999999999], RGBColor[0.431296, 0.709773, 0.927077]}|>, PlotLegends -> <|"Elements" -> {"ccc1", "ccc2", "ccc3"}|>]用 Legended 指定几个图例:
PieChart[{1, Legended[2, "aa"], 3, 4, Legended[5, "bb"], 6}, PlotStyle -> <|"Elements" -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.8750956, 0.6580038, 0.746929], RGBColor[0.9440982, 0.7955892, 0.5942686], RGBColor[0.9537862, 0.937389, 0.6180996], RGBColor[0.7952328000000001, 0.8988539999999999, 0.8302508], RGBColor[0.431296, 0.709773, 0.927077]}|>]PieChart[{{1, 2, 3}, {4, 5, 6}}, PlotLegends -> {"Group A", "Group B"}, PlotStyle -> <|"Groups" -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.431296, 0.709773, 0.927077]}|>]PieChart[{{1, 2, 3}, {4, 5, 6}}, PlotLegends -> {"Group A", "Group B", "Group C"}, PlotStyle -> <|"Groups" -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.431296, 0.709773, 0.927077]}|>]PieChart[{{1, 2, 3}, {4, 5, 6}}, PlotLegends -> <|"Groups" -> {"Test A", "Test B"}, "Elements" -> {"John", "Mary", "Bob"}|>, PlotStyle -> <|"Groups" -> {EdgeForm[Directive[RGBColor[0.93, 0.27, 0.27], Thickness[0.01]]], EdgeForm[Dashed]}, "Elements" -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.9584254999999999, 0.877884, 0.5906629999999999], RGBColor[0.431296, 0.709773, 0.927077]}|>]用 Placed 控制图例的放置:
Table[PieChart[{{1, 2, 3}, {4, 5, 6}}, PlotLegends -> Placed[{"John", "Mary", "Bob"}, pos], PlotStyle -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.431296, 0.709773, 0.927077]}], {pos, {Before, Below}}]PlotStyle (5)
用 PlotStyle 设计扇区的样式:
PieChart[{1, 2, 3, 4}, PlotStyle -> {RGBColor[0.93, 0.27, 0.27], RGBColor[0.14, 0.8, 0.14], RGBColor[0.4, 0.6, 1], RGBColor[1, 0.75, 0]}]PieChart[{1, 2, 3}, PlotStyle -> Directive[Opacity[0.7], EdgeForm[Dashed]]]PieChart[{{1, 2, 3}, {1, 2}}, PlotStyle -> {RGBColor[0.93, 0.27, 0.27], RGBColor[0.4, 0.6, 1]}]PieChart[{{1, 2, 3}, {4, 5, 6}}, PlotStyle -> <|"Elements" -> {RGBColor[0.93, 0.27, 0.27], RGBColor[0.14, 0.8, 0.14], RGBColor[0.4, 0.6, 1]}|>]PieChart[{{1, 2, 3}, {4, 5, 6}}, PlotStyle -> <|"Groups" -> {RGBColor[0.93, 0.27, 0.27], RGBColor[0.14, 0.8, 0.14]}|>]PieChart[{{1, 2, 3}, {4, 5, 6}}, PlotStyle -> <|"Base" -> EdgeForm[{Thick, Dashed}], "Groups" -> {Opacity[0.5], Opacity[0.9]}, "Elements" -> {RGBColor[0.93, 0.27, 0.27], RGBColor[0.14, 0.8, 0.14], RGBColor[0.4, 0.6, 1]}|>]PieChart[{1, Style[2, EdgeForm[Dashed]], 3}, PlotStyle -> {RGBColor[0.93, 0.27, 0.27], RGBColor[0.14, 0.8, 0.14], RGBColor[0.4, 0.6, 1]}]PieChart[{1, Style[2, EdgeForm[None]], 3}, PlotStyle -> EdgeForm[{Thick, Dashed}]]"Elements" 或 "Groups" 的设置可能会覆盖 "Base" 的设置:
PieChart[{1, 2, 3}, PlotStyle -> <|"Base" -> EdgeForm[None], "Elements" -> EdgeForm[Dashed]|>]用 ColorFunction 来组合不同的样式效果:
PieChart[{1, 2, 3}, PlotStyle -> EdgeForm /@ {Dashed, Dotted, DotDashed}, ColorFunction -> (Blend[{RGBColor[0.4, 0.6, 1], RGBColor[0.93, 0.27, 0.27]}, #]&)]PieChart[{{1, 2, 3, 4, 5, 6, 7, 8}, {9, 10, 11, 12, 13, 14, 15, 16}, {17, 18, 19, 20, 21, 22, 23, 24}}, PlotStyle -> <|"Groups" -> {RGBColor[0.471412, 0.108766, 0.527016], RGBColor[0.2484884, 0.3863264, 0.813373], RGBColor[0.38822480000000004, 0.674195, 0.6035436]}|>, ChartLayout -> "Grouped", ColorFunction -> Function[{height}, Opacity[height]]]PieChart[{{1, 2, 3, 4, 5}, {1, 2, 3}}, ChartElementFunction -> "TriangleWaveSector", PlotStyle -> {RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.431296, 0.709773, 0.927077]}]PlotTheme (1)
SectorOrigin (4)
{PieChart[{Labeled[1, "Begin"], 2, 3, 4}], PieChart[{Labeled[1, "Begin"], 2,
3, 4}, SectorOrigin -> {{Pi, "Clockwise"}, 0}]}PieChart[{Labeled[1, "Begin"], 2, 3, 4}, SectorOrigin -> {{Pi, "Clockwise"}, 1}]PieChart[{Labeled[1, "Begin"], 2, 3, 4}, SectorOrigin -> {{Pi / 6, "Counterclockwise"}, 1}]PieChart[{Labeled[1, "Begin"], 2, 3, 4}, SectorOrigin -> {{Pi / 6, "Clockwise"}, 1}]SectorSpacing (5)
PieChart[{{1, 3, 4}, {3, 3, 2}}, SectorSpacing -> Automatic]PieChart[{{1, 3, 4}, {3, 3, 2}}, SectorSpacing -> None]Table[PieChart[{{1, 3, 4}, {3, 3, 2}}, SectorSpacing -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]Table[PieChart[{{1, 3, 4}, {3, 3, 2}}, SectorSpacing -> s, PlotLabel -> s], {s, {Automatic, 0.3, 1}}]Table[PieChart[{{1, 3, 4}, {3, 3, 2}}, SectorSpacing -> s, PlotLabel -> s], {s, {Automatic, {0.1, 1}, {0.05, 0.2}}}]应用 (13)
Histogram[RandomReal[NormalDistribution[0, 1], 100], {-2, 2, 0.25}, Function[{b, c}, bins = b;counts = c]]PieChart[counts, PlotLabels -> Callout[Table[Row[b, "to"], {b, bins}]], PlotRange -> All]countries = CountryData["G7"];
data = Table[With[{country = c, v = Round@CountryData[c, "GDPPerCapita"]}, Button[v, Speak[StringJoin[country, ", $", ToString[v]]]]], {c, countries}];PieChart[data, PlotLabel -> "GDP Per Capita", PlotLabels -> Placed[countries, "RadialOutside"]]flag = CountryData["UnitedStates", "FlagImage"]{color, data} = Transpose[DominantColors[flag, 3, {"Color", "Count"}]]PieChart[N[data / Total[data]], PlotStyle -> color, LabelingFunction -> (Callout[Row[{NumberForm[100#, {3, 1}], "%"}]]&)
]PieChart[CountryData[#, "GDP"]& /@ CountryData["G7"], LabelingFunction -> (Placed[NumberForm[#, 2, NumberPadding -> {"$", ""}], Tooltip]&), PlotLabels -> Callout[CountryData["G7"]], PlotRange -> All]elem = SortBy[Tally[Flatten[Table[ElementData[z, "DiscoveryCountries"], {z, 1, 108}]]], Last];elemPercentage = Apply[Callout[#1, #2]&, Transpose[{N[(elem[[All, 2]] / Total[elem[[All, 2]]])], elem[[All, 1]]}], 1];PieChart[elemPercentage, LabelingFunction -> (Placed[Row[{NumberForm[100 #, 2], "%"}, " "], Tooltip]&), ColorFunction -> "LightTerrain", PlotRange -> All]s = "making with charts is fun";
sn = Tally[Characters[s]];PieChart[sn[[All, 2]], PlotLabels -> Callout[Row[{Style[#[[1]], Bold, StandardGray, Italic], " = ", Style[#[[2]], StandardGray]}]& /@ sn, LabelStyle -> 13]]sales = {15, 6, 13, 5, 9, 11, 4};
products = CharacterRange["A", "G"];
percent[v_] := Row[{NumberForm[100N[v / Total[sales]], {3, 2}], "%"}]labeler[v_, {1, c_}, ___] := Placed[{percent[v], Row[{products[[c]]}]}, {Tooltip, "RadialOuter"}]
labeler[v_, {2, c_}, ___] := Placed[Column[{{"hardware", "software", "services"}[[c]], percent[v]}], "RadialEdge"]PieChart[{Style[sales, LightGray], Total /@ {sales[[1 ;; 2]], sales[[3 ;; 5]], sales[[6 ;; 7]]}}, LabelingFunction -> labeler, SectorSpacing -> 0, ColorFunction -> "SolarColors", SectorOrigin -> {Automatic, 1}, Epilog -> Text["Products"],
PlotRange -> All]portfolioData["Technology"] = {"AAPL", "MSFT", "GOOGL", "INTC", "CSCO"};
portfolioData["Banking"] = {"JPM", "BAC", "GS", "WFC", "C"};
portfolioData["Oil"] = {"XOM", "PSX", "OXY", "SLB", "RIG"};
sectors = {"Banking", "Technology", "Oil"};portfolioData["MarketCap"] = 0;
Table[portfolioData["MarketCap"] += (portfolioData[s, "MarketCap"] = Total@Table[FinancialData[c, "MarketCap"], {c, portfolioData[s]}]), {s, sectors}];labelStyle[label_] := Style[label, 12, FontFamily -> "Helvetica"]drilldown[sector_] := PieChart[Table[FinancialData[company, "MarketCap"], {company, portfolioData[sector]}], ColorFunction -> "ArmyColors", PlotLabels -> labelStyle /@ portfolioData[sector], ChartElementFunction -> "PlateauSector"]chartOptions = {ColorFunction -> "IslandColors", PlotLabels -> labelStyle /@ sectors, SectorOrigin -> {{0, 1}, 0.5}, PlotLabel -> Style["Portfolio MarketCap", "Title", 14]};PieChart[Tooltip[portfolioData[#, "MarketCap"], drilldown[#]]& /@ sectors, chartOptions]PieChart[PopupWindow[portfolioData[#, "MarketCap"], drilldown[#], WindowTitle -> #]& /@ sectors, chartOptions]countries = CountryData["G15"];
properties = {"OilConsumption", "OilProduction", "OilReserves", "OilExports", "OilImports"};
data = Table[CountryData[c, p], {c, countries}, {p, properties}];BubbleChart[data[[All, 1 ;; 3]], ChartElements -> Table[PieChart[d, LabelingFunction -> None], {d, data[[All, 4 ;; 5]]}], BubbleSizes -> {0.05, 0.15}, PlotLabels -> Placed[countries, Tooltip], FrameLabel -> properties[[1 ;; 2]]]data = {70, 30, 10};Clear[sector]
sector[{{t0_, t1_}, {r0_, r1_}}, y_, {False}] := {}
sector[{t : {t0_, t1_}, {r0_, r1_}}, ___] := Disk[{0, 0}, r1, {t0, t1} - Mean[t]]GraphicsRow[Table[PieChart[{data[[d]], (Total[data] - data[[d]]) -> False}, PlotLabel -> {"2000", "2001", "2002"}[[d]], SectorOrigin -> Top, ChartElementFunction -> sector, PlotLabels -> Placed[PercentForm[N@data[[d]] / Total[data]], "RadialInner"], ImageSize -> Medium], {d, Length@data}], ImageSize -> Medium]data = If[DateObjectQ[#], First@DateList[#], #]& /@ Table[ElementData[en, "DiscoveryYear"], {en, ElementData[]}];定义一个图表元素函数,用 Sow 来存储组距和统计数据:
sowingBar[{x : {x0_, x1_}, {y0_, y1_}}, __] := (Sow[{x, (y1 - y0)}];Rectangle[{x0, y0}, {x1, y1}]){histogram, {newdata}} = Reap[Histogram[data, {1700, 2000, 25}, "Probability", ChartElementFunction -> sowingBar]];PieChart[newdata[[All, 2]], PlotLabels -> Callout[Row[#, "-"]& /@ newdata[[All, 1]]], SectorOrigin -> {Pi / 2, "Clockwise"}, PlotRange -> All]chemicalComposition[chemical_String] := Block[{chemData, plotStyle},
chemData = ChemicalData[chemical, "ElementTally"];
plotStyle = ColorData["Atoms", #]& /@ chemData[[All, 1]];
PieChart[Tooltip[chemData[[All, 2]], ChemicalData[chemical, "ColorStructureDiagram"], TooltipStyle -> {Background -> White, CellFrameColor -> Blue}], PlotLabels -> Placed[ElementData /@ chemData[[All, 1]], "RadialCallout", Style[#, 9, Bold, Italic, FontFamily -> "Courier"]&], LabelingFunction -> (Placed[Style[#, 11], "RadialCenter"]&), PlotLabel -> Style[Column[{chemical, ChemicalData[chemical, "Formula"]}, Alignment -> Center], 12, Bold, FontFamily -> "Courier"], PlotStyle -> plotStyle, ChartElementFunction -> "PlateauSector", PlotRange -> All]
]Grid[{{chemicalComposition["Caffeine"], chemicalComposition["MethylMagnesiumChloride"]}, {chemicalComposition["SulfuricAcid"], chemicalComposition["AcryloylChloride"]}, {chemicalComposition["Aspirin"], chemicalComposition["VinylCarbamate"]}}, Frame -> All]data = EarthquakeData[All, {6, 10}, {{2011, 1, 1}, {2013, 1, 1}}, "Position"]GeoGraphics[GeoMarker[#, "Scale" -> 4]& /@ data["Values"]]continents = CountryData["Continents"]oceans = {Entity["Ocean", "AtlanticOcean"], Entity["Ocean", "ArcticOcean"], Entity["Ocean", "IndianOcean"], Entity["Ocean", "PacificOcean"], Entity["Ocean", "SouthernOcean"]};res1 = Map[{Last@First[#["Continent"]], Count[GeoWithinQ[#, Normal@data["Values"]], True]}&, continents]res2 = Map[{#["Name"]//ToString, Count[GeoWithinQ[#, Normal@data["Values"]], True]}&, oceans]res = Select[Join[res1, res2], Last[#] > 0&];PieChart[res[[All, 2]], PlotLabels -> Placed[res[[All, 1]], "VerticalCallout"], PlotRange -> All]属性和关系 (4)
用 PieChart3D 得到一个三维饼图:
PieChart3D[Range[5]]PieChart 是 SectorChart 的一个特例:
{PieChart[{1, 2, 3}], SectorChart[{{1, 1}, {2, 1}, {3, 1}}]}用 BarChart 和 BarChart3D 绘制数据列表:
{BarChart[{1, 2, 3, 4}], BarChart3D[{1, 2, 3, 4}]}用 ListPlot 和 ListLinePlot 产生线图形:
{ListPlot[{1, 2, 3, 4}, Filling -> Axis], ListLinePlot[{1, 2, 3, 4}]}文本
Wolfram Research (2008),PieChart,Wolfram 语言函数,https://reference.wolfram.com/language/ref/PieChart.html (更新于 2025 年).
CMS
Wolfram 语言. 2008. "PieChart." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2025. https://reference.wolfram.com/language/ref/PieChart.html.
APA
Wolfram 语言. (2008). PieChart. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/PieChart.html 年
BibTeX
@misc{reference.wolfram_2026_piechart, author="Wolfram Research", title="{PieChart}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/PieChart.html}", note=[Accessed: 31-October-2026]}
BibLaTeX
@online{reference.wolfram_2026_piechart, organization={Wolfram Research}, title={PieChart}, year={2025}, url={https://reference.wolfram.com/language/ref/PieChart.html}, note=[Accessed: 31-October-2026]}