首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >多个饼图的通用图例

多个饼图的通用图例
EN

Stack Overflow用户
提问于 2021-07-25 03:58:13
回答 1查看 39关注 0票数 0

如何在图表底部为两个图表设置普通图例。我尝试使用fig.legend,但不知道如何正确编写它。谢谢!!

代码语言:javascript
运行
复制
import pandas as pd

# Intialise data to Dicts of series.
d = {'Oil' : pd.Series([1.0, 17.0, 0.3, 81.7],
                       index =['Others', 'Commercial', 'Industrial', 'Domestic']),
        'Coal' : pd.Series([3, 34.8,  38.6, 23.6],
                        index =['Others', 'Commercial', 'Industrial', 'Domestic'])}
  
# creates Dataframe.
df = pd.DataFrame(d)

fig, axes = plt.subplots(1,2, figsize=(15,4.5))

fig.suptitle('Customers Profile and Energy Sold per Sector', fontweight='bold', fontsize=20)
for ax, col in zip(axes, df.columns):
    ax.pie(df[col], wedgeprops=dict(linewidth = 3, edgecolor = 'white'), colors=['#EE8434','#C95D63', '#AE8799','#717EC3'],startangle=90, autopct='%.2f%%', pctdistance=1.2)
     
#fig.legend(ax, df.index, 'upper left')
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-25 04:29:22

答案在@henryecker建议的链接中找到

代码语言:javascript
运行
复制
for ax, col in zip(axes, df.columns):
    chart = ax.pie(df[col])
     
fig.legend(chart[0], df.index, 'lower center')
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68513392

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档