这是我找到并稍作修改的代码。如何从原点缩放颜色并从原点设置轴以进行可视化?我试图找到信息,但其中大部分是用于二维图的。
在这里,我添加了两个以 45 度为间隔的数组和一个表示信号功率的随机数数组theta
。phi
该图有效,但信号和间隔并不完全正确。我的目标是从原点添加轴并从原点缩放颜色。
import pandas as pd
import numpy as np
import scipy as sci
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as Axes3D
from matplotlib import cm, colors
from array import *
import random
#theta
vals_theta = array('i',[0,0,0,0,0,0,0,0,0,45,45,45,45,45,45,45,45,45,90,90,90,
90,90,90,90,90,90,135,135,135,135,135,135,135,135,135,
180,180,180,180,180,180,180,180,180])
#phi
vals_phi = array('i',[0,45,90,135,180,225,270,315,360,
0,45,90,135,180,225,270,315,360,
0,45,90,135,180,225,270,315,360,
0,45,90,135,180,225,270,315,360,
0,45,90,135,180,225,270,315,360])
#random numbers simulating the power data
vals_power = np.random.uniform(low=-7.2E-21, high=7.2E-21, size=(45,))
theta1d = vals_theta
theta1d = np.array(theta1d);
theta2d = theta1d.reshape([5,9])
phi1d = vals_phi
phi1d = np.array(phi1d);
phi2d = phi1d.reshape([5,9])
power1d = vals_power
power1d = np.array(power1d);
power2d = power1d.reshape([5,9])
THETA = np.deg2rad(theta2d)
PHI = np.deg2rad(phi2d)
R = power2d
Rmax = np.max(R)
X = R * np.sin(THETA) * np.cos(PHI)
Y = R * np.sin(THETA) * np.sin(PHI)
Z = R * np.cos(THETA)
fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection='3d')
ax.grid(True)
ax.axis('on')
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
N = R / Rmax
ax.plot_surface(
X, Y, Z, rstride=1, cstride=1, cmap=plt.get_cmap('jet'),
linewidth=0, antialiased=False, alpha=0.5, zorder = 0.5)
ax.set_title('Spherical 3D Plot', fontsize=20)
m = cm.ScalarMappable(cmap=cm.jet)
m.set_array(R)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
m = cm.ScalarMappable(cmap=cm.jet)
m.set_array(R)
fig.colorbar(m, shrink=0.8);
ax.view_init(azim=300, elev = 30)
# Add Spherical Grid
phi ,theta = np.linspace(0, 2 * np.pi, 40), np.linspace(0, np.pi, 40)
PHI, THETA = np.meshgrid(phi,theta)
R = Rmax
X = R * np.sin(THETA) * np.cos(PHI)
Y = R * np.sin(THETA) * np.sin(PHI)
Z = R * np.cos(THETA)
ax.plot_wireframe(X, Y, Z, linewidth=0.5, rstride=3, cstride=3)
print(theta1d)
print(theta2d)
print(power2d)
plt.show()
试图得到一个近似于此的结果