• 《Python数据可视化之matplotlib实践》 源码 第四篇 扩展 第十二章


    图  12.1

     

    import matplotlib.pyplot as plt
    import numpy as np
    
    barSlices=12
    
    theta=np.linspace(0.0, 2*np.pi, barSlices, endpoint=False)
    radii=30*np.random.rand(barSlices)
    width=2*np.pi/barSlices
    colors=np.array(["c", "m", "y", "b", "#C67171", "#C1CDCD", "#FFEC8B", 
                     "#A0522D", "red", "burlywood", "chartreuse", "green"])
    
    
    fig=plt.figure()
    ax=fig.add_subplot(111, polar=True)
    
    
    bars=ax.bar(theta, radii, width=width, color=colors, bottom=0.0)
    
    
    plt.show()
    View Code

    ---------------------------------------------------------

    图  12.3

     

    import matplotlib.pyplot as plt
    import numpy as np
    
    
    hexHtml=["#d73027", "#f46d43", "#fdae61", "#fee090",
             "#ffffbf", "#e0f3f8", "#abd9e9", "#74add2", "#4575b4"]
    
    sample=10000
    
    fig, ax = plt.subplots(1, 1)
    
    
    for j in range(len(hexHtml)):
        y=np.random.normal(0, 0.1, size=sample).cumsum()
        x=np.arange(sample)
        ax.scatter(x, y, label=str(j), linewidths=0.2, 
                   edgecolors="grey", facecolor=hexHtml[j])
    
    ax.legend()
    
    
    plt.show()
    View Code

    ---------------------------------------------------------

     

    图  12.4

     

    import matplotlib.pyplot as plt
    import numpy as np
    
    
    rd=np.random.rand(10, 10)
    
    plt.pcolor(rd, cmap="BuPu")
    plt.colorbar()
    
    
    plt.show()
    View Code

    ---------------------------------------------------------

     

    图  12.5

     

    import matplotlib.pyplot as plt
    import matplotlib as mpl
    import numpy as np
    
    
    a = np.random.rand(100)
    b = np.random.rand(100)
    exponent = 2
    
    
    
    
    
    plt.subplot(131)
    plt.scatter(a, b, np.sqrt(np.power(a, exponent)+np.power(b, exponent))*100, 
                c=np.random.rand(100), cmap=mpl.cm.jet, marker="o", zorder=1)
    
    
    
    
    plt.subplot(132)
    plt.scatter(a, b, 50, marker="o", zorder=10)
    
    
    
    
    plt.subplot(133)
    plt.scatter(a, b, 50, c=np.random.rand(100), cmap=mpl.cm.BuPu,
                marker="+", zorder=100)
    
    
    
    plt.show()
    View Code

    ---------------------------------------------------------

     

    图  12.6

     

    import matplotlib.pyplot as plt
    import matplotlib as mpl
    import numpy as np
    
    
    barSlices=12
    theta=np.linspace(0.0, 2*np.pi, barSlices, endpoint=False)
    radii=30*np.random.rand(barSlices)
    width=np.pi/4*np.random.rand(barSlices)
    
    
    fig=plt.figure()
    ax=fig.add_subplot(111, polar=True)
    
    
    bars=ax.bar(theta, radii, width=width, bottom=0.0)
    
    
    for r, bar in zip(radii, bars):
        bar.set_facecolor(mpl.cm.Accent(r/30.0))
        bar.set_alpha(r/30.0)
    
    
    plt.show()
    View Code

    ---------------------------------------------------------

    图  12.7

     

    import matplotlib.pyplot as plt
    import matplotlib as mpl
    import numpy as np
    
    
    
    
    s=np.linspace(-0.5, 0.5, 1000)
    
    x, y=np.meshgrid(s, s)
    
    z=x**2+y**2+np.power(x**2+y**2, 2)
    
    
    
    
    fig, ax=plt.subplots(1, 1)
    
    
    
    
    cs=plt.contour(x, y, z, cmap=mpl.cm.hot)
    
    plt.clabel(cs, fmt="%3.2f")
    
    plt.colorbar(cs)
    
    
    
    
    plt.show()
    View Code

    ---------------------------------------------------------

     

    图  12.8

     

    import matplotlib.pyplot as plt
    import matplotlib as mpl
    import scipy.misc
    
    
    ascent=scipy.misc.ascent()
    
    
    plt.imshow(ascent, cmap=mpl.cm.gray)
    
    
    plt.colorbar()
    
    
    plt.show()
    View Code

    ---------------------------------------------------------

     

    本博客是博主个人学习时的一些记录,不保证是为原创,个别文章加入了转载的源地址还有个别文章是汇总网上多份资料所成,在这之中也必有疏漏未加标注者,如有侵权请与博主联系。
  • 相关阅读:
    MSSQL Extension For Visual Studio Code
    钉钉开发系列(三)API的调用
    DataTable转换为Model
    钉钉开发系列(十一)钉钉网页扫码登录
    EntityFramework获取数据库的时间
    EntityFramework连接串的调用时传入
    钉钉开发系列(十)SaltUI与WebApi交互
    钉钉开发系列(九)SaltUI在VS中的开发
    钉钉开发系列(八)二维码扫描登录的实现
    钉钉开发系列(七)媒体文件的上传与下载
  • 原文地址:https://www.cnblogs.com/devilmaycry812839668/p/13260233.html
Copyright © 2020-2023  润新知