SoFunction
Updated on 2024-12-10

Pie charting with Python pyecharts

First, pyecharts plotting pie chart syntax introduction

Pie charts are primarily used to show the percentage of data in the sum of different categories. The arc of each is not a percentage of the data volume
()Usage of methods

add(name, attr, value,
radius=None,
center=None,
rosetype=None, **kwargs)

  • name->str Legend name
  • attr->list property name
  • value->list The value corresponding to the attribute
  • radius->list The radius of the pie chart, the first item of the array is the inner radius and the second item is the outer radius, defaults to [0,75].
  • Default is set as a percentage, half of the smaller of the container's height and width.
  • center-> the center of the pie chart center coordinates, the first item of the array is the horizontal coordinates, the second item is the vertical coordinates, the default is [50,50]
  • Default is set to percentage, when set to percentage the first item is relative to the height of the container, the second item is also relative to the height of the container
  • rosetype->str

Whether to display as a Nightingale diagram. Distinguishing data size by radius hasradiusand area modes. The default isradius

  • radius: Sector rounded corners show the percentage of data, radius shows the size of the data
  • area:: All sectors have the same rounded center angle, only the data size is shown by the radius

II. Plotting ordinary pie charts

attr = ["Shirt.", "Wool sweater.", "Chiffon shirt.", "Pants.", "High heels.", "Socks."]
v1 = [11, 12, 13, 10, 10, 10]
pie1 = Pie("Pie chart example")
("", attr, v1, is_label_show=True,center=[50,50])
(pie1)

III. Plotting circular diagrams

attr = ["Shirt.", "Wool sweater.", "Chiffon shirt.", "Pants.", "High heels.", "Socks."]
v1 = [11, 12, 13, 10, 10, 10]
pie2 = Pie("Pie Chart - Circle Chart Example", title_pos='center')
(
    "",
    attr,
    v1,
    radius=[40, 75],
    label_text_color=None,
    is_label_show=True,
    legend_orient="vertical",
    legend_pos="left",
)
(pie2)


IV. Drawing pie charts - rose diagrams

attr = ["Shirt.", "Wool sweater.", "Chiffon shirt.", "Pants.", "High heels.", "Socks."]
v1 = [11, 12, 13, 10, 10, 10]
v2 = [19, 21, 32, 20, 20, 33]
pie3 = Pie("Pie Chart-Rose Chart Example")
(
    "Commodity A",
    attr,
    v1,
    is_random=True,
    rosetype="radius",
    is_label_show=True,
)
(pie3)

attr = ["Shirt.", "Wool sweater.", "Chiffon shirt.", "Pants.", "High heels.", "Socks."]
v1 = [11, 12, 13, 10, 10, 10]
v2 = [19, 21, 32, 20, 20, 33]
pie4 = Pie("Pie Chart-Rose Chart Example")
(
    "Commodity B",
    attr,
    v2,
    #center=[75, 50],
    is_random=True,
    #radius=[30, 75],
    rosetype="area",
    is_legend_show=True,
    is_label_show=True,
)
(pie4)

To this point this article on the use ofPython pyechartsDrawing pie charts article is introduced to this, more relevantPython pyechartsTo draw the pie chart content please search my previous posts or continue to browse the related posts below I hope you will support me more in the future!