首页 > 解决方案 > Python,球形图 - 颜色缩放

问题描述

我对python很陌生。在过去的两天里,我一直试图弄清楚如何使用 matplotlib 缩放 3d 图(天线辐射图案)的颜色。看起来缩放在 xyz 轴之一中起作用,但在缩放从原点(半径)开始时不起作用。非常感谢任何帮助。

这不是我的代码,但我发现它非常有用。

这是代码:

当前情节

标签: pythonmatplotlibcolorsspherical-coordinate

解决方案


我有以下代码来考虑色标的半径。成功的方法是使用颜色图来获取标准化 R 的颜色值(这里是颜色权重)。

X = np.ones((phiSize, thetaSize))                                                                           # Prepare arrays to hold the cartesian coordinate data.
Y = np.ones((phiSize, thetaSize))
Z = np.ones((phiSize, thetaSize))
color_weight = np.ones((phiSize, thetaSize))

min_dBi = np.abs(df["dBi"].min())

for phi_idx, phi in enumerate(np.unique(df["Phi"])):
    for theta_idx, theta in enumerate(np.unique(df["Theta"])):
        e = df.query(f"Phi=={phi} and Theta=={theta}").iloc[0]["dBi"]
        e = min_dBi + e # so we dont have any negative numbers
        xe, ye, ze = sph2cart1(e, math.radians(theta), math.radians(phi))                                   # Calculate cartesian coordinates

        X[phi_idx, theta_idx] = xe                                                                                  # Store cartesian coordinates
        Y[phi_idx, theta_idx] = ye
        Z[phi_idx, theta_idx] = ze
        color_weight[phi_idx, theta_idx] = e

ax.plot_surface(X, Y, Z, color='b')                                                                         # Plot surface
plt.ylabel('Y')
plt.xlabel('X')                                                                                             # Plot formatting
plt.show()

我的数据中唯一的 phis 和 theta 的数量phisizethetaSize我的天线的 dBi 存储在 dBi 列中的 pandas 中。


推荐阅读