一、饼状图应用原理 二、demos from sklearn.datasets import load_iris import matplotlib.pyplot as plt import numpy as np iris = load_iris() data = iris.data target = list(iris.target) import numpy as np import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(6, 3), subplot_kw=dict(aspect="equal")) # recipe = ["375 g flour", # "75 g sugar", # "250 g butter", # "300 g berries"] # data = [float(x.split()[0]) for x in recipe] # ingredients = [x.split()[-1] for x in recipe] def func(pct, allvals): absolute = int(pct/100.*np.sum(allvals)) return "{:.1f}%\n({:d} g)".format(pct, absolute) wedges, texts, autotexts = ax.pie([target.count(0), target.count(1), target.count(2)], autopct=lambda pct: func(pct, data), textprops=dict(color="w")) ax.legend(wedges, [0, 1, 2], title="Ingredie
Python 饼图
最新推荐文章于 2024-04-20 23:47:27 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)