import matplotlib.pyplot as plt
import numpy as np
# cartesian coordinates
xx,yy = np.meshgrid(np.linspace(-2,2,100),np.linspace(-2,2,100))
# function value across square domain
Ua = xx**2 + yy**2
# polar coordinates
tt = np.arctan2(yy, xx)
rr = np.sqrt(Ua) # re-using x^2 + y^2 only works for this function
# r coordinate of domain boundary
domain_boundary = 1 + (np.cos(4*tt))**2
# function value across actual domain, with rest set to NaN
Ua[rr > domain_boundary] = np.NaN
# plotting
fig = plt.figure(2)
ax = fig.gca(projection='3d')
ax.plot_wireframe(xx,yy,Ua,rstride=1,cstride=1,linewidth=.5)
首先计算矩形网格上的函数!在
scipy.interpolate.griddata
在凸壳上插值。你可以在the docs里读到。这意味着它也在你的肺叶之间插入。这就是为什么你没有得到正确的域名。插值本身也比只计算网格上的函数更不精确。在plot_wireframe
需要一个已经创建的矩形网格。你需要做的就是计算矩形网格上的函数值。若要仅在域边界上绘制值,请将其外部的所有值设置为np.NaN
(不是-a-number)。在方法如下:
该解决方案并不完美,因为您可以在结果中识别出矩形网格。您可以尝试在极坐标下工作,如this official matplotlib example所示。在
相关问题 更多 >
编程相关推荐