Python draw pie chart interval pie chart donut pie chart

1. Ordinary pie chart

insert image description here

import pandas as pd
import matplotlib.pyplot as plt

# 使用好看的样式
plt.style.use('fivethirtyeight')

fig = plt.figure(figsize=(12,12))
ax = fig.add_subplot()

data = [2,4,5,1,6]
labels = ['TS','STS','TY','STY','SSTY']


wedges, texts, autotexts = ax.pie(
    data,
    # 显示百分比,保留一位小数
    autopct='%1.1f%%',
)

ax.set_title(str(2000),fontsize=25)

ax.legend(
    wedges,
    labels,
    title="",
    prop={
    
    'size': 15},
    frameon=False
)



Second, emphasize a certain module.

Pass parameter explode=(0.01, 0.05, 0.01, 0.01, 0.01) in ax.pie(), you can change the interval
Insert picture description here
insert image description here




3. Ring pie chart

insert image description here


import pandas as pd
import matplotlib.pyplot as plt

plt.style.use('fivethirtyeight')

fig = plt.figure(figsize=(12,12))
ax = fig.add_subplot()
explode = (0.03, 0.03, 0.03, 0.03, 0.03,)


data = [2,4,5,1,6]
labels = ['TS','STS','TY','STY','SSTY']

wedges, texts, autotexts = ax.pie(
    data,
    autopct='%1.1f%%',
    # 设置各块之间的间隙
    explode=explode,
    # 设置30%的环形图,间距颜色为白色
    wedgeprops=dict(width=0.3, edgecolor='w')
)

ax.set_title(str(2000),fontsize=25)

ax.legend(
    wedges,
    labels,
    title="",
    prop={
    
    'size': 15},
    frameon=False
)

Guess you like

Origin blog.csdn.net/qq_35240689/article/details/127095979