日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【绘图】3D点图 及绘图关系matplotlib中plt系列

發(fā)布時(shí)間:2024/3/13 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【绘图】3D点图 及绘图关系matplotlib中plt系列 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

  • 1. 報(bào)錯(cuò)及解決方案:
  • 2. matplotlib中plt繪圖關(guān)系描述
    • 2.1 plt.figure()
    • 2.2 plt.subplot()
    • 2.3 plt.subplots()
    • 2.4 add_subplots
    • 2.5 add_axes
  • 3. 圖層疊加

1. 報(bào)錯(cuò)及解決方案:

報(bào)錯(cuò):

首先需要知道,這是由于沒有使用繪制3D圖,但沒有加入3D庫(kù)引起的。
所以需要添加如下的庫(kù):

from mpl_toolkits.mplot3d import Axes3D

觸發(fā)語句:

ax = fig.add_subplot(111, projection='3d')

2. matplotlib中plt繪圖關(guān)系描述

然后發(fā)現(xiàn)其實(shí)自己也沒有搞明白繪圖當(dāng)中的一些關(guān)系,所以干脆順便學(xué)習(xí)了一下,分享在這里:
庫(kù)matplotlib中的plt相關(guān)繪圖

2.1 plt.figure()

作用:繪制一張圖
函數(shù)
figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True)
參數(shù)說明

  • num:圖像編號(hào)或名稱,數(shù)字為編號(hào) ,字符串為名稱
  • figsize:指定figure的寬和高,單位為英寸
  • dpi參數(shù)指定繪圖對(duì)象的分辨率,即每英寸多少個(gè)像素,缺省值為80
  • facecolor:背景顏色
  • edgecolor:邊框顏色
  • frameon:是否顯示邊框

一般用法

import matplotlib.pyplot as plt fig=plt.figure() plt.show()

2.2 plt.subplot()

作用:創(chuàng)建單個(gè)子圖
函數(shù):subplot(nrows,ncols,sharex,sharey,subplot_kw,**fig_kw)
參數(shù)說明

  • nrows:子圖的行數(shù)
  • ncols:子圖的列數(shù)
  • sharex:所有子圖使用相同的X軸刻度(調(diào)節(jié)xlim將會(huì)影響所有的subplot)
  • sharey:所有子圖使用相同的Y軸刻度(調(diào)節(jié)ylim將會(huì)影響所有subplot)
  • subplot_kw:用于創(chuàng)建個(gè)子圖的關(guān)鍵字字典
  • **fig_kw:創(chuàng)建figure時(shí)的其他關(guān)鍵字。

一般用法

# 繪制一行兩個(gè)子圖,一個(gè)是y=2x,一個(gè)是y=x import matplotlib.pyplot as plt import numpy as np x = np.arange(0,10) y = 2 * x plt.subplot(121) plt.plot(x, y) plt.subplot(122) plt.plot(x, x) plt.show()

2.3 plt.subplots()

作用:創(chuàng)建多個(gè)子圖
說明:subplots參數(shù)與subplots類似。區(qū)別在于每條subplot命令只會(huì)創(chuàng)建一個(gè)子圖,而一條subplots就可以將所有子圖創(chuàng)建好。
一般用法

import numpy as np import matplotlib.pyplot as plt x = np.arange(0, 10) y = 2 * x #劃分子圖 fig,axes=plt.subplots(1,2) ax1=axes[0,0]# 左圖 ax2=axes[0,1]# 右圖 #作圖1 ax1.plot(x, y) #作圖2 ax2.plot(x, x) plt.show()

2.4 add_subplots

作用:給figure新添加子圖,與subpot類似,一般可以配合生成3D數(shù)據(jù)。
用法

import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # 為了3D繪圖 x = np.arange(0, 10) y = 2 * x z = 2 * y fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # 這里需要加參數(shù)projection='3d' ax.scatter(x, y, z, marker='+', color='blue', label='Real') plt.show()

2.5 add_axes

作用:新添加子區(qū)域
函數(shù): fig.add_axes([left, bottom, width, height])
參數(shù)說明:left 與bottom表示左邊以及下邊的起始位置,width和height表示寬高占原fig的比例。
用法

import matplotlib.pyplot as plt #創(chuàng)建figure fig = plt.figure() x = np.arange(0, 10) y = 2 * x #新建區(qū)域ax1 #figure的百分比,從figure 10%的位置開始繪制, 寬高是figure的80% left, bottom, width, height = 0.1, 0.1, 0.8, 0.8 # 獲得繪制的句柄 ax1 = fig.add_axes([left, bottom, width, height]) ax1.plot(x, y, 'r') ax1.set_title('area1')#新增區(qū)域ax2,嵌套在ax1內(nèi) left, bottom, width, height = 0.2, 0.6, 0.25, 0.25 # 獲得繪制的句柄 ax2 = fig.add_axes([left, bottom, width, height]) ax2.plot(x,y, 'b') ax2.set_title('area2') plt.show()

3. 圖層疊加

參數(shù):zorder
或者使用matplotlib的set_zorder這個(gè)屬性.
但是發(fā)現(xiàn)如果使用Axes3D,其竟然是失效的。。。甚是無語啊,所以看到一種方法是放棄使用該方法使用mayavi庫(kù)。

參考

https://blog.csdn.net/C_chuxin/article/details/83994457
多圖層:
https://blog.csdn.net/sunsoda/article/details/82431770

總結(jié)

以上是生活随笔為你收集整理的【绘图】3D点图 及绘图关系matplotlib中plt系列的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。