【问题标题】:Obtaining the coordinates of streamlines in python在python中获取流线的坐标
【发布时间】:2017-11-28 08:55:23
【问题描述】:

我正在尝试在存在磁场(由永磁体产生)的情况下执行等离子体的数值计算。我使用 streamplot 命令从数据中绘制了磁场:

现在,我想沿着场线手动创建一个网格,我需要用于绘制它们的点的坐标。这对我很重要,因为等离子体将沿着或穿过场线流动,我希望代码开发变得更容易。

我试图分析 streamplot 命令的输出,但无法获得坐标。

stream = ax.streamplot(Z, R, B_Z, B_R, color=color, linewidth=1,
         cmap=plt.cm.inferno,density=2.5, arrowstyle='->', arrowsize=1)

我知道我可以通过对字段数据进行数值积分来找到流函数,然后用它来绘制和存储流线的坐标,但这会很麻烦。

请指导我寻找更简单的替代方案。

【问题讨论】:

    标签: python python-2.7 matplotlib


    【解决方案1】:

    您可以通过调用.get_paths().get_segments()获取流线段。

    stream = ax.streamplot(...)
    paths = strm.lines.get_paths()
    segments = strm.lines.get_segments()
    

    但是,这些是线条的单个片段,通常不清楚哪个片段属于屏幕上看到的哪个线条。

    由于您似乎需要数据进行定量分析,因此我建议不要依赖流图本身(旨在提供良好的可视化表示),而是根据您的数据计算数量。

    【讨论】:

      【解决方案2】:

      在@ImportanceOfBeingErnest 之后,我能够通过

      实现这个目标
      density = 100 # defaults to 30- increased for more precision in the streamline
      starting_point = np.array([[-180, -1980]])
      
      strm = plt.streamplot(X, Y, U, V, density=density, start_points=starting_point)
      num_pts = len(strm.lines.get_segments())
      flow_line = np.full((num_pts, 2), np.nan)
      for i in range(num_pts):
          flow_line[i,:] = strm.lines.get_segments()[i][0,:]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-09-26
        • 1970-01-01
        • 2017-07-11
        • 1970-01-01
        • 2012-09-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多