Python は円グラフを描画します 間隔円グラフ ドーナツ円グラフ

1. 通常の円グラフ

ここに画像の説明を挿入

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
)



次に、特定のモジュールを強調します。

ax.pie() でパラメータexplode=(0.01, 0.05, 0.01, 0.01, 0.01)を渡すと、間隔を変更できます
ここに画像の説明を挿入します
ここに画像の説明を挿入




3. リング円グラフ

ここに画像の説明を挿入


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
)

おすすめ

転載: blog.csdn.net/qq_35240689/article/details/127095979