[英]Matplotlib how to center a 2D image at origin on XY surface in 3D plot?
[英]How to create a circular 2D plot with matplotlib where function depends on the distance from the center of the image?
本質上,您需要在笛卡爾網格上評估您的函數。 因此,不是使用半徑r
func(r)
調用您的函數,而是使用從網格節點x
和y
計算的半徑來調用它, func(sqrt(x**2+y**2))
import numpy as np
import matplotlib.pyplot as plt
func = lambda r: np.sin(r)*np.exp(-r/10.)
r = np.linspace(0,50,151)
X,Y = np.meshgrid(np.linspace(-50,50,301),np.linspace(-50,50,301))
rad = lambda x,y: np.sqrt(x**2+y**2)
image = func(rad(X,Y))
fig, (ax,ax2) = plt.subplots(ncols=2)
ax.plot(r, func(r))
ax2.imshow(image, extent=[X.min(),X.max(),Y.min(),Y.max()])
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.