【问题标题】:How to print percentages outside the pie with python如何使用python打印饼图外的百分比
【发布时间】:2021-05-19 20:14:48
【问题描述】:

我想在饼图之外有百分比值。也许你可以帮忙

这是我的代码:

import matplotlib.pyplot as plt
import pandas as pd

dict={'a':45, 'b': 123, 'c':2, 'd':1755, 'e':13}
ser = pd.Series(dict)

print(ser)

ser.plot(kind='pie', shadow=True, autopct='%1.2f%%')
plt.show()

正如您在我的案例中看到的,百分比值不可见

【问题讨论】:

    标签: python-3.x series pie-chart


    【解决方案1】:

    根据docspctdistance控制“每个饼图的中心与autopct生成的文本开头的比例”,它有一个默认值0.6,这导致了百分比值进入馅饼。

    尝试pctdistance> 1

    >>> ser.plot(kind='pie', shadow=True, autopct='%1.2f%%', pctdistance=1.15)
    

    (上面会导致百分比和标签重叠的“丑陋”图。您可以通过使用labeldistance“移动”标签来解决此问题。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-15
      • 1970-01-01
      • 1970-01-01
      • 2015-04-15
      • 1970-01-01
      • 2022-06-18
      • 1970-01-01
      相关资源
      最近更新 更多