深入简出matplotlib画嵌套饼状图的细节操作

标题 深入简出matplotlib画嵌套饼状图的细节操作

##直接代码,有这些灵机一动的操作,望指教

# import torch
import matplotlib.pyplot as plt
import numpy as np 
# 设置图片大小
plt.figure(figsize = (10, 8))

# 生成数据
labels_outer = 'global warming ',' acidification ','eutrophication','dust'
labels_core = 'global warming '
labels = ['CO2', 'CH4', 'HCl', 'SO2', 'H2S', 'NOx', 'Dust']
share_laptop = [2, 3, 1, 1]
share_pc = [1, 1, 1, 1, 1, 1, 1]
core=[1]
cmap = plt.get_cmap("tab20c")
outer_colors = cmap(np.arange(4)*4)
inner_colors = cmap(np.array([1, 2, 5, 6, 9, 10,11]))
core_colors = cmap(np.array([13]))

# 外环
wedges1, text1, autotexts1 = plt.pie(share_laptop,
    labels =labels_outer,labeldistance=0.75,
    autopct = '%3.1f%%',
    radius = 1,
    pctdistance = 0.85,
    colors = outer_colors,
    startangle = 0,
    shadow=True,
    textprops = {'color': 'black', 'fontsize':'12'},#改变标签颜色
    wedgeprops = {'width': 0.3, 'edgecolor': 'w'}
)

print(autotexts1)

# 内环
wedges2, texts2, autotexts2 = plt.pie(share_pc,
    autopct = '%3.1f%%',
    radius = 0.7,
    pctdistance = 0.75,
    colors = inner_colors,
    startangle = 0,
    shadow=True,
    textprops = {'color': 'w'},
    wedgeprops = {'width': 0.3, 'edgecolor': 'w'}
)
wedges3, texts3, autotexts3 = plt.pie(core,
#     labels =labels_core,labeldistance=0,
    autopct = '%3.1f%%',
    radius = 0.4,
    pctdistance = 0,
    colors = core_colors,
    startangle = 0,
    shadow=True,
    textprops = {'color': 'w'},
    wedgeprops = {'width': 0.4, 'edgecolor': 'w'}
)
print(autotexts3)
# autotexts3=[Text(0.0, 0.0, 'eva')]
print(autotexts3)
# 图例
plt.legend(wedges2,
          labels,
          fontsize = 12,
          title = 'Environmental Impact Project',
          loc = 'center right',
          bbox_to_anchor = (1.2, 0.95))

# 设置文本样式# weight='bold'
plt.setp(autotexts1, size=0)
plt.setp(autotexts2, size=0)
plt.setp(autotexts3, size=0)
plt.setp(texts2, size=15,weight='bold')

# labels_outer = ['global warming ',' Soil acidification ','Water eutrophication','Dust']
# quants = [0.5299663049140826, 0.6645567813631229,-0.8499999999999963, -7.958274335777502e-08,
#          0.18914289916010302, -0.8286887013211361,0.7658235993771495, -0.36880105021139403]

# draw_pie(labels_outer,quants)

x=0.435
y=0.5
s='Environmental load '
plt.figtext(x, y, s, fontsize=12)
# 标题
plt.title('Environmental load relation pie chart ', fontsize=15)

plt.show()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值