python資料視覺效果——matplotlib 使用者手冊入門:pyplot 畫圖

來源:互聯網
上載者:User

標籤:href   latex   plt   tar   first   art   port   tor   bin   

參考matplotlib官方指南:

https://matplotlib.org/tutorials/introductory/pyplot.html#sphx-glr-tutorials-introductory-pyplot-py

pyplot是常用的畫圖模組,功能非常強大,下面就來見識下它的能力吧

1.快速畫出常見圖形

 

 

 2.使用關鍵字字串作圖

 

3.使用類別變數畫圖

4.建立多圖

 

 1 import matplotlib.pyplot as plt 2 %matplotlib inline 3 plt.figure(1)                # the first figure 4 plt.subplot(211)             # the first subplot in the first figure 5 plt.plot([1, 2, 3]) 6 plt.subplot(212)             # the second subplot in the first figure 7 plt.plot([4, 5, 6]) 8  9 10 plt.figure(2)                # a second figure11 plt.plot([4, 5, 6])          # creates a subplot(111) by default12 13 plt.figure(1)                # figure 1 current; subplot(212) still current14 plt.subplot(211)             # make subplot(211) in figure1 current15 plt.title(‘Easy as 1, 2, 3‘) # subplot 211 title

 

 1 import matplotlib.pyplot as plt 2 import numpy as np 3  4 np.random.seed(19680801) 5 data = np.random.randn(2, 100) 6  7 fig, axs = plt.subplots(2, 2, figsize=(5, 5)) 8 axs[0, 0].hist(data[0]) 9 axs[1, 0].scatter(data[0], data[1])10 axs[0, 1].plot(data[0], data[1])11 axs[1, 1].hist2d(data[0], data[1])12 13 plt.show()

5.添加文本:軸線標籤,屬性標籤

 1 import matplotlib.pyplot as plt 2 import numpy as np 3 mu, sigma = 100, 15 4 x = mu + sigma * np.random.randn(10000) 5  6 # the histogram of the data 7 n, bins, patches = plt.hist(x, 50, normed=True, facecolor=‘g‘, alpha=0.75) 8  9 10 plt.xlabel(‘Smarts‘)11 plt.ylabel(‘Probability‘)12 plt.title(‘Histogram of IQ‘)13 plt.text(60, .025, r‘$\mu=100,\ \sigma=15$‘)   # 支援 LaTex格式14 plt.axis([40, 160, 0, 0.03])15 plt.grid(True)16 plt.show()

python資料視覺效果——matplotlib 使用者手冊入門:pyplot 畫圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.