Adding explode affect to a pandas pie chart

試著忘記壹切 提交于 2020-03-06 09:29:08

问题


Following this question I want to add the exploded effect to the pie chart. Consider the below code:

import pandas as pd

df = pd.DataFrame(["man", "woman", "man", "other",
                     "other", "man", "woman"], columns=["gender"])
df['gender'].value_counts(normalize=True).plot(
    kind='pie', shadow=True, autopct='%1.1f%%')

which result in

                     

Now I want to add the explode=explode feature to the plot but I can't (e.g., here). The commands

df['gender'].value_counts(normalize=True).plot(
    kind='pie', shadow=True, autopct='%1.1f%%', explode=explode)

and

ax = df['gender'].value_counts(normalize=True).plot(
    kind='pie', shadow=True, autopct='%1.1f%%')

ax.pie(explode=explode)

results in

NameError: name 'explode' is not defined

来源:https://stackoverflow.com/questions/60234927/adding-explode-affect-to-a-pandas-pie-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!