【发布时间】:2021-12-18 09:39:23
【问题描述】:
首先,我有二维网格上某个点的速度分量(x 和 y)的数据。我可以用ff.create_quiver(X, Y, UN, VN) 可视化每个速度,其中 UN 和 VN 是每个速度的方向。但是我仍然对如何显示或绘制每个速度speed 的大小以及每个“箭头”感到困惑。代码输出:
import plotly.figure_factory as ff
import plotly.graph_objs as go
import numpy as np
#creating grid
X,Y = np.meshgrid(np.arange(0,11,1),np.arange(0, 11, 1))
#basic vector calculus
Ux = X/np.sqrt(X**2 + Y**2) #velocity in x direction
Uy = Y/np.sqrt(X**2 + Y**2) #velocity in y direction
speed = np.sqrt(Ux**2 + Uy**2) #VELOCITY MAGNITUDE
UN = Ux/speed # velocity direction
VN = Uy/speed # velocity direction
f = ff.create_quiver(X, Y, UN, VN,
scale=.6,
arrow_scale=.5,
name='quiver',
line_width=2, line_color='black')
# u can ignore these codes below (it's for temperature visualization)
temperature = f.data[0]
trace2 = go.Contour(
z= np.random.random((12, 12))+23,
colorbar={"title": 'Temperature'},
colorscale='jet',opacity=0.7
)
data=[temperature,trace2]
fig = go.FigureWidget(data)
fig.update_layout(title='Room airflow velocity and temperature distribution',
title_x=0.5,
title_y=0.85,
xaxis_title="Room length",
yaxis_title='Room width',
font_size=15,font_family="Times New Roman")
fig.show()
【问题讨论】:
标签: python plotly data-visualization plotly-python