Python3繪圖之Matplotlib(03)

來源:互聯網
上載者:User

標籤:tab   targe   info   ops   grid   isp   ext   ima   display   

餅圖 = pie散佈圖 = scatter plots極化圖 = polar charts箭頭 = Annotations 本節程式碼範例
import matplotlib.pyplot as pltplt.figure(figsize=(3, 3))x = [45, 35, 20]labels = [‘Cats‘, ‘Dogs‘, ‘Fishes‘]plt.pie(x, labels=labels)plt.show()import matplotlib.pyplot as pltplt.figure(figsize=(3, 3))x = [4, 9, 21, 55, 30, 18]labels = [‘Swiss‘, ‘Austria‘, ‘Spain‘, ‘Italy‘, ‘France‘, ‘Benelux‘]explode = [0.2, 0.1, 0, 0, 0.1, 0]plt.pie(x, labels=labels, explode=explode, autopct=‘%1.1f%%‘)plt.show()# Scatter plotsimport matplotlib.pyplot as pltimport numpy as npx = np.random.randn(1000)y = np.random.randn(1000)plt.scatter(x, y)plt.show()size = 50 * np.random.randn(1000)colors = np.random.rand(1000)plt.scatter(x, y, s=size, c=colors)plt.show()# Polar chartsimport matplotlib.pyplot as pltimport numpy as nptheta = np.arange(0., 2., 1./180.) * np.piplt.polar(3 * theta, theta / 5)plt.polar(theta, np.cos(4*theta))plt.polar(theta, [1.4]*len(theta))plt.show()import matplotlib.pyplot as pltimport numpy as nptheta = np.arange(0., 2., 1./180.) * np.pir = np.abs(np.sin(5*theta) - 2.*np.cos(theta))plt.polar(theta, r)plt.thetagrids(list(range(45, 360, 90)))plt.rgrids(np.arange(0.2, 3.1, .7), angle=0)plt.show()import matplotlib.pyplot as pltimport numpy as npx = np.arange(0, 2*np.pi, .01)y = np.sin(x)plt.plot(x, y)plt.text(0.1, -0.04, ‘sin(0)=0‘)plt.show()# Annotationsimport matplotlib.pyplot as plty = [13, 11, 13, 12, 13, 10, 30, 12, 11, 13, 12, 12, 12, 11, 12]plt.plot(y)plt.ylim(ymax=35)plt.annotate(‘This plot must really\nmean somothing‘,            xy=(6, 30), xytext=(8, 31.5),              arrowprops=dict(facecolor=‘black‘, shrink=.05))plt.show()import matplotlib.pyplot as pltplt.axis([0, 10, 0, 20])arrstyles = [‘-‘, ‘->‘, ‘-[‘, ‘<-‘, ‘<->‘, ‘fancy‘, ‘simple‘, ‘wedge‘]for i, style in enumerate(arrstyles):    plt.annotate(style, xytext=(1, 2+2*i), xy=(4, 1+2*i),                arrowprops=dict(arrowstyle=style))connstyles = [‘arc‘, ‘arc, angleA=10, armA=30, rad=15‘,             ‘arc3, rad=.2‘, ‘arc3, rad=-.2‘, ‘angle‘, ‘angle3‘]for i, style in enumerate(connstyles):    plt.annotate("", xytext=(6, 2+2*i), xy=(8, 1+2*i),                arrowprops=dict(arrowstyle=‘->‘, connectionstyle=style))plt.show()
    

Python3繪圖之Matplotlib(03)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.