python可视化---饼图添加图例
Posted 车路历程
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python可视化---饼图添加图例相关的知识,希望对你有一定的参考价值。
import matplotlib.pyplot as plt import matplotlib as mpl mpl.rcParams["font.sans-serif"] = ["SimHei"] mpl.rcParams["axes.unicode_minus"] = False elements = ["面粉", "砂糖", "奶油", "草莓酱", "坚果"] weight = [40, 15, 20, 10, 15] colors = ["#377eb8", "#4daf4a", "#984ea3", "#ff7f00", "#e6ab02"] wedges, texts, autotexts = plt.pie(weight, autopct="%3.1f%%", textprops=dict(color="w"), colors=colors) plt.legend(wedges, elements, fontsize=12, title="配料图", loc="center left", bbox_to_anchor=(0.91, 0, 0.3, 1)) plt.setp(autotexts, size=15, weight="bold") plt.setp(texts, size=12) plt.title("果酱面料配料比例表") plt.show()
以上是关于python可视化---饼图添加图例的主要内容,如果未能解决你的问题,请参考以下文章