python實(shí)現(xiàn)二維插值的三維顯示
更新時(shí)間:2018年12月17日 15:32:48 作者:TOliverQueen
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)二維插值的三維顯示,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了二維插值的三維顯示具體代碼,供大家參考,具體內(nèi)容如下
# -*- coding: utf-8 -*- """ 演示二維插值。 """ # -*- coding: utf-8 -*- import numpy as np from mpl_toolkits.mplot3d import Axes3D import matplotlib as mpl from scipy import interpolate import matplotlib.cm as cm import matplotlib.pyplot as plt def func(x, y): return (x + y) * np.exp(-5.0 * (x ** 2 + y ** 2)) # X-Y軸分為20*20的網(wǎng)格 x = np.linspace(-1, 1, 20) y = np.linspace(-1, 1, 20) x, y = np.meshgrid(x, y) # 20*20的網(wǎng)格數(shù)據(jù) fvals = func(x, y) # 計(jì)算每個(gè)網(wǎng)格點(diǎn)上的函數(shù)值 15*15的值 fig = plt.figure(figsize=(9, 6)) #設(shè)置圖的大小 # Draw sub-graph1 ax = plt.subplot(1, 2, 1, projection='3d') #設(shè)置圖的位置 surf = ax.plot_surface(x, y, fvals, rstride=2, cstride=2, cmap=cm.coolwarm, linewidth=0.5, antialiased=True) #第四個(gè)第五個(gè)參數(shù)表示隔多少個(gè)取樣點(diǎn)畫一個(gè)小面,第六個(gè)表示畫圖類型,第七個(gè)是畫圖的線寬,第八個(gè)表示抗鋸齒 ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('f(x, y)') #標(biāo)簽 plt.colorbar(surf, shrink=0.5, aspect=5) # 標(biāo)注 # 二維插值 newfunc = interpolate.interp2d(x, y, fvals, kind='cubic') # newfunc為一個(gè)函數(shù) # 計(jì)算100*100的網(wǎng)格上的插值 xnew = np.linspace(-1, 1, 100) # x ynew = np.linspace(-1, 1, 100) # y fnew = newfunc(xnew, ynew) # 僅僅是y值 100*100的值 np.shape(fnew) is 100*100 xnew, ynew = np.meshgrid(xnew, ynew) ax2 = plt.subplot(1, 2, 2, projection='3d') surf2 = ax2.plot_surface(xnew, ynew, fnew, rstride=2, cstride=2, cmap=cm.coolwarm, linewidth=0.5, antialiased=True) ax2.set_xlabel('xnew') ax2.set_ylabel('ynew') ax2.set_zlabel('fnew(x, y)') plt.colorbar(surf2, shrink=0.5, aspect=5) # 標(biāo)注 plt.show()
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
PyTorch加載數(shù)據(jù)集梯度下降優(yōu)化
這篇文章主要介紹了PyTorch加載數(shù)據(jù)集梯度下降優(yōu)化,使用DataLoader方法,并繼承DataSet抽象類,可實(shí)現(xiàn)對(duì)數(shù)據(jù)集進(jìn)行mini_batch梯度下降優(yōu)化,需要的小伙伴可以參考一下2022-03-03Python延時(shí)操作實(shí)現(xiàn)方法示例
這篇文章主要介紹了Python延時(shí)操作實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了Python基于sched庫與time庫實(shí)現(xiàn)延時(shí)操作的方法,需要的朋友可以參考下2018-08-08Numpy數(shù)據(jù)轉(zhuǎn)換成image并保存的實(shí)現(xiàn)示例
本文主要介紹了Numpy數(shù)據(jù)轉(zhuǎn)換成image并保存的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-12-12使用Python編寫Linux系統(tǒng)守護(hù)進(jìn)程實(shí)例
這篇文章主要介紹了使用Python編寫Linux系統(tǒng)守護(hù)進(jìn)程實(shí)例,本文先是講解了什么是守護(hù)進(jìn)程,然后給出了一個(gè)Python語言的簡單實(shí)現(xiàn),需要的朋友可以參考下2015-02-02