【发布时间】:2021-03-03 05:42:45
【问题描述】:
我是编程和 Python 方面的新手。我正在研究一些教科书天线图案的东西,有一种叫做“正弦空间”的东西,其中天线图案被投影到 x-y 平面。生成的图案应包含在单位圆内)。当我使用 matplotlib.pcolormesh 时,我能够得到我预期的模式。但我不知道如何让它与 Plotly 一起使用。
我试图在 Jupyter Notebook 中说明我的问题。使用 matplotlib.pcolormesh,你可以看到我得到了预期的情节。我故意没有包括实际的天线方向图计算,因为它们太长了,而且对于说明这个问题没有必要。
# Import libraries
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
# Setup Sinespace
## - define theta and phi
theta = np.linspace(0, np.pi/2, 100)
phi = np.linspace(0, 2*np.pi, 100)
## - reshape theta and phi
thetaReshape = np.reshape(theta, (100, 1))
phiReshape = np.reshape(phi, (1, 100))
## - now when you multiply with thetaReshape and phiReshape you get a 100 x 100 array
u = np.sin(thetaReshape) * np.cos(phiReshape)
v = np.sin(thetaReshape) * np.sin(phiReshape)
# Generate a random array
Z = np.random.randn(100, 100)
# Setup and plot the figure
fig, ax = plt.subplots(1, 1)
ax.pcolormesh(u, v, Z)
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
ax.set_aspect(1)
fig.set_size_inches(4, 4)
上面的情节是我期望看到的。当我使用 plotly 时,我做了以下操作:
import plotly.graph_objects as go
fig = go.Figure(data=go.Heatmap(
z=Z,
x=u,
y=v
))
fig.show()
这导致下面的这个情节没有任何意义:
go.Contour 也得到了几乎相同的结果。
我非常感谢任何帮助。谢谢!
【问题讨论】:
标签: python matplotlib plotly heatmap contour