国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

鄭州微網(wǎng)站制作東莞seo網(wǎng)站管理

鄭州微網(wǎng)站制作,東莞seo網(wǎng)站管理,中國建筑人才招聘官網(wǎng),網(wǎng)站如何做才可以微信直接登錄Python中采用.add_subplot繪制子圖的方法簡要舉例介紹 目錄 Python中采用.add_subplot繪制子圖的方法簡要舉例介紹一、Python中繪制子圖的方法1.1 add_subplot函數(shù)1.2 基本語法(1)add_subplot的核心語法(2)add_subplot在中編程中的…

Python中采用.add_subplot繪制子圖的方法簡要舉例介紹

目錄

  • Python中采用.add_subplot繪制子圖的方法簡要舉例介紹
    • 一、Python中繪制子圖的方法
      • 1.1 add_subplot函數(shù)
      • 1.2 基本語法
        • (1)add_subplot的核心語法
        • (2)add_subplot在中編程中的主要程序段
    • 二、使用.add_subplot繪制子圖舉例
      • 2.1 問題描述
      • 2.2 程序代碼
      • 2.3 運行結(jié)果

在Python中中繪圖常會用到Matplotlib庫,本文講簡要舉例說明利用Matplotlib 庫中的函數(shù)add_subplot實現(xiàn)子圖的繪制,并說明其用法。

一、Python中繪制子圖的方法

1.1 add_subplot函數(shù)

作為Matplotlib 庫中的一個函數(shù)add_subplot,用于在畫布(figure)上添加子圖(subplot)。這個方法比較有用,可以幫助使用者在想要在一個圖中創(chuàng)建多個子圖。

1.2 基本語法

關(guān)于如何使用 add_subplot ,本小節(jié)給出了使用主要方法:

(1)add_subplot的核心語法
ax= fig.add_subplot(nrows, ncols, plot_number)

其中:
nrows: 表示網(wǎng)格中的行數(shù)。
ncols: 表示網(wǎng)格中的列數(shù)。
plot_number: 指定子圖的位置。

例如,fig.add_subplot(2, 3, 5)表示在2x3網(wǎng)格中的左下角放置一個子圖,則plot_number應為5。

(2)add_subplot在中編程中的主要程序段
import matplotlib.pyplot as plt
fig = plt.figure()
ax_n = fig.add_subplot(nrows, ncols, plot_number)
ax_n.plot(x_n, y_n)
plt.show()

二、使用.add_subplot繪制子圖舉例

2.1 問題描述

為了 在2*2的圖中繪制如下函數(shù)所表示的4個子圖,
{ y 1 = sin ? x + x y 2 = sin ? x 2 + 2 x y 3 = sin ? x 3 + 3 x y 4 = sin ? x 4 + 4 x \begin{cases} y_{1}=\sin x +x \\ y_{2}=\sin x^2 +2x \\ y_{3}=\sin x^3 +3x \\ y_{4}=\sin x^4 +4x\end{cases} ? ? ??y1?=sinx+xy2?=sinx2+2xy3?=sinx3+3xy4?=sinx4+4x?,其中 0 ≤ x < 2 π 0\le x <2\pi 0x<2π.
將使用Matplotlib工具庫中add_subplot的進行繪圖。

2.2 程序代碼

示例代碼
假設(shè)我們想在一個2x2的網(wǎng)格中繪制四個不同的圖表:

import matplotlib.pyplot as plt
import numpy as np# 1.數(shù)據(jù)準備x = np.linspace(0, 2* np.pi, 400)
y1 = np.sin(x )+x
y2 = np.sin(x ** 2)+2*x
y3 = np.sin(x ** 3)+3*x
y4 = np.sin(x ** 4)+4*x# 2.創(chuàng)建一個新的圖形對象
fig = plt.figure()# 2.1 在2x2的網(wǎng)格中添加子圖
ax1 = fig.add_subplot(2, 2, 1) # 左上
ax2 = fig.add_subplot(2, 2, 2) # 右上
ax3 = fig.add_subplot(2, 2, 3) # 左下
ax4 = fig.add_subplot(2, 2, 4) # 右下# 2.2.再各個子圖中繪制數(shù)據(jù)ax1.plot(x, y1)
ax1.set_title('Subplot 1')ax2.plot(x, y2)
ax2.set_title('Subplot 2')ax3.plot(x, y3)
ax3.set_title('Subplot 3')ax4.plot(x, y4)
ax4.set_title('Subplot 4')plt.show()

2.3 運行結(jié)果

比如將上述程序,在PyCharm中運行結(jié)果如下:

在這里插入圖片描述
圖1 采用.add_subplot繪制子圖的運行結(jié)果

http://aloenet.com.cn/news/39649.html

相關(guān)文章:

  • 做網(wǎng)站和seo流程網(wǎng)絡營銷主要干什么
  • 沈陽看男科哪家醫(yī)院好廣州seo排名收費
  • 東營網(wǎng)新聞精準網(wǎng)站seo診斷報告
  • 網(wǎng)上免費做網(wǎng)站seo 頁面鏈接優(yōu)化
  • 鎮(zhèn)江網(wǎng)站建設(shè) 的公司熱點新聞事件
  • 彩票推廣網(wǎng)站如何做杭州網(wǎng)站建設(shè)
  • 內(nèi)蒙古城鄉(xiāng)建設(shè)網(wǎng)站換名字了網(wǎng)絡推廣渠道都有哪些
  • 網(wǎng)站開發(fā)工程師的要求站長工具站長之家官網(wǎng)
  • 成都網(wǎng)站開發(fā)排名廈門關(guān)鍵詞排名優(yōu)化
  • 北京網(wǎng)站設(shè)計首選 新鴻儒360免費建站教程
  • wordpress標簽生成圖片基礎(chǔ)建站如何提升和優(yōu)化
  • wordpress 連接后臺關(guān)鍵詞優(yōu)化公司費用多少
  • 網(wǎng)站內(nèi)移動的圖片怎么做的深圳網(wǎng)絡優(yōu)化公司
  • 公司備案網(wǎng)站負責人是誰網(wǎng)站推廣軟件哪個好
  • 淄博張店做網(wǎng)站的公司百度網(wǎng)站客服電話
  • 網(wǎng)站建設(shè)新聞發(fā)布注意事項互聯(lián)網(wǎng)怎么賺錢
  • 建設(shè)網(wǎng)站的英語怎么說做網(wǎng)站的網(wǎng)絡公司
  • 微信小程序頁面模板seo文章是什么
  • 廣水市建設(shè)局網(wǎng)站線上培訓
  • 建設(shè)網(wǎng)站的方案什么叫做優(yōu)化
  • rust做網(wǎng)站微商引流被加方法精準客源
  • 如何建設(shè)成為營銷網(wǎng)站百度客服電話24小時人工服務熱線
  • 向日葵域名怎么做網(wǎng)站成都網(wǎng)站搭建優(yōu)化推廣
  • 手機動態(tài)網(wǎng)站開發(fā)教程網(wǎng)絡營銷的四大特點
  • 如何做網(wǎng)站本地服務器嗎廣告投放策略
  • 江蘇省建設(shè)人才網(wǎng)站軟文文案案例
  • 蘭州新站seo如何找推廣平臺
  • 假網(wǎng)站怎么做呢百度信息流投放技巧
  • 怎么提高網(wǎng)站曝光武漢seo優(yōu)化服務
  • 高能建站系統(tǒng)怎么收費查詢網(wǎng)站流量的網(wǎng)址