Matplotlib饼图注释
生活随笔
收集整理的這篇文章主要介紹了
Matplotlib饼图注释
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import numpy as np
import matplotlib.pyplot as pltplt.figure(figsize=(9,9))# 環形餅圖元素
recipe = ["225g flour","90g sugar","1 egg","60g butter","100ml milk","1/2package of yeast"]# ?例
data = [225, 90, 50, 60, 100, 5]wedges, texts = plt.pie(data,startangle=40)
bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72)kw = dict(arrowprops=dict(arrowstyle="-"),bbox=bbox_props,va="center")for i, p in enumerate(wedges):ang = (p.theta2 - p.theta1)/2. + p.theta1 # ?度計算# ?度轉弧度----->弧度轉坐標y = np.sin(np.deg2rad(ang))x = np.cos(np.deg2rad(ang))ha = {-1: "right", 1: "left"}[int(np.sign(x))] # ?平對??式connectionstyle = "angle,angleA=0,angleB={}".format(ang) # 箭頭連接樣式kw["arrowprops"].update({"connectionstyle": connectionstyle}) # 更新箭頭連接?式plt.annotate(recipe[i], xy=(x, y), xytext=(1.35*np.sign(x), 1.4*y),ha=ha,**kw,fontsize = 18,weight = 'bold')plt.title("Matplotlib bakery: A donut",fontsize = 18,pad = 25)
plt.tight_layout()
總結
以上是生活随笔為你收集整理的Matplotlib饼图注释的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据库基础:IndexedDB
- 下一篇: 七、文章管理页面及功能实现《iVX低代码