【问题标题】:How To Display Velocity Magnitude in a Vector Field Using Quiver Plot?如何使用 Quiver Plot 在向量场中显示速度大小?
【发布时间】: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


    【解决方案1】:

    我相信 create_quiver 不可能,但你可以做类似的事情

    # from  https://plotly.com/python/cone-plot/ 
    import plotly.graph_objects as go
    import pandas as pd
    
    df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/vortex.csv")
    
    fig = go.Figure(data = go.Cone(
        x = df['x'],
        y = df['y'],
        z = df['z'],
        u = df['u'],
        v = df['v'],
        w = df['w'],
        colorscale = 'Blues',
        sizemode = "absolute",
        sizeref = 40))
    
    fig.update_layout(
        scene = dict(aspectratio = dict(x = 1, y = 1, z = 0.8),
        camera_eye = dict(x = 1.2, y = 1.2, z = 0.6)))
    
    fig.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-04
      • 2022-08-19
      • 2017-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多