Translating Radial Data To A Cartesian Grid For Surface Plot
I have a list of data whose components correspond to the potential at some radial distance r on a 2D grid. The data corresponds to data points in polar coordinates and is symmetric
Solution 1:
You will need to tranform your data to cartesian coordinates first and create a value array of the same shape as the meshgrid by repeating the value V
for each theta.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
r = np.linspace(1.0, 5.0, 99)
V = np.sqrt(np.sinc(r-0.5)**2) # your data here (same length as r)
theta = np.linspace(0,2*np.pi,50)
R, Theta = np.meshgrid(r,theta)
X = R * np.cos(Theta)
Y = R * np.sin(Theta)
Z = np.tile(V,(len(theta),1))
norm = plt.Normalize(vmin=Z.min(), vmax=Z.max())
ax.plot_surface(X,Y,Z, facecolors=plt.cm.RdYlGn(norm(Z)))
plt.show()
Post a Comment for "Translating Radial Data To A Cartesian Grid For Surface Plot"