Python使用add_subplot與subplot畫子圖操作

來源:互聯網
上載者:User
這篇文章主要介紹了Python使用add_subplot與subplot畫子圖操作,涉及Python使用matplotlib模組進行圖形繪製的相關操作技巧,需要的朋友可以參考下

本文執行個體講述了Python使用add_subplot與subplot畫子圖操作。分享給大家供大家參考,具體如下:

子圖:就是在一張figure裡面產生多張子圖。

Matplotlib對象簡介

FigureCanvas 畫布
Figure 圖
Axes 座標軸(實際畫圖的地方)

注意,pyplot的方式中plt.subplot()參數和物件導向中的add_subplot()參數和含義都相同。

使用物件導向的方式

#!/usr/bin/python#coding: utf-8import numpy as npimport matplotlib.pyplot as pltx = np.arange(0, 100)fig = plt.figure()ax1 = fig.add_subplot(221)ax1.plot(x, x)ax2 = fig.add_subplot(222)ax2.plot(x, -x)ax3 = fig.add_subplot(223)ax3.plot(x, x ** 2)ax4 = fig.add_subplot(224)ax4.plot(x, np.log(x))plt.show()

pyplot的方式

#!/usr/bin/python#coding: utf-8import numpy as npimport matplotlib.pyplot as pltx = np.arange(0, 100)plt.subplot(221)plt.plot(x, x)plt.subplot(222)plt.plot(x, -x)plt.subplot(223)plt.plot(x, x ** 2)plt.subplot(224)plt.plot(x, np.log(x))plt.show()

運行結果:

聯繫我們

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