美文网首页
甜甜圈图

甜甜圈图

作者: Aerosols | 来源:发表于2019-04-10 21:54 被阅读0次

    Origin加%
    https://www.wxwenku.com/d/106883670#tuit

    焦老板新版图

    %matplotlib inline
    # -*- coding: UTF-8 -*-
    import numpy as np
    import matplotlib.pyplot as plt
    from pylab import mpl
    mpl.rcParams['font.sans-serif']=['SimHei']
    
    fig, ax = plt.subplots(figsize=(15, 12), subplot_kw=dict(aspect="equal"))
    
    recipe = ['优:17天', '良:213天', '轻度污染:95天', '中度污染:18天','重度污染:13天','严重污染:4天']
    ingredients = [x.split(':')[0] for x in recipe]
    
    data = [5.7, 59.2, 26.4, 5.0,3.6,1.1]
    colors = ['lime', 'yellow', 'darkorange', 'red','purple','maroon']
    wedges, texts, texts2 = ax.pie(data, wedgeprops=dict(width=0.5), startangle=200, colors=colors, 
                                    autopct='%1.0f%%', pctdistance=0.8)
    
    ax.legend(wedges, ingredients,fancybox=False, framealpha=0., shadow=False,fontsize=20,
              loc='lower center',ncol=6,handlelength=1, borderpad=None)
              #bbox_to_anchor=(1, 0, 0.6, 1))
    
    plt.setp(texts2,size=30,weight="bold")
    
    
    bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72)
    kw = dict(xycoords='data', textcoords='data', arrowprops=dict(arrowstyle="-"),
              bbox=None, zorder=0, 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))
        horizontalalignment = {-1: "right", 1: "left"}[int(np.sign(x))]
        connectionstyle = "angle,angleA=0,angleB={}".format(ang)
        kw["arrowprops"].update({"connectionstyle": connectionstyle})
        ax.annotate(recipe[i], xy=(x, y), xytext=(1.25*np.sign(x), 1.3*y),size=30,
                     horizontalalignment=horizontalalignment, **kw)
    
    #ax.set_title("Matplotlib bakery: A donut")
    
    #plt.show()
    plt.savefig('jiaopie2.pdf')
    
    air.png

    相关文章

      网友评论

          本文标题:甜甜圈图

          本文链接:https://www.haomeiwen.com/subject/xsdaiqtx.html