python绘图速度_当我知道速度的u和v分量(numpy 2d数组)时,如何使用python中的绘图程序绘制流线?...

i hope the title itself was quite clear , i am solving 2D lid-driven cavity(square domain) problem using fractional step method , finite difference formulation (Navier-Stokes primitive variable form) , i have got u and v components of velocity over the entire domain , without manually calculating streamlines , is there a command or plotting tool which does the job for me?

i hope this question is relevant enough to programming , as i need a tool for plotting streamlines without explicitly calculating them.

I have solved the same problem in stream-vorticity NS form , i just had to take contour plot of stream function to get the streamlines.

I hope that tool or plotter is a python library, and morevover installable in fedora (i can compromise and use mint)without much fuss!!

i would be grateful if someone points out the library and relevant command (would save a lot of time)

解决方案

If you have problems with speed, it might be more efficient to use some of scipy's integration functionality instead of the pure-numpy integration functions used in both of these examples. I haven't tried it, though, and these deliberately avoid a dependency on scipy. (scipy is a rather heavy dependency compared to numpy)

From it's example plot:

import matplotlib.pyplot as plt

import numpy as np

from streamplot import streamplot

x = np.linspace(-3,3,100)

y = np.linspace(-3,3,100)

u = -1-x**2+y[:,np.newaxis]

v = 1+x-y[:,np.newaxis]**2

speed = np.sqrt(u*u + v*v)

plt.figure()

plt.subplot(121)

streamplot(x, y, u, v, density=1, INTEGRATOR='RK4', color='b')

plt.subplot(122)

streamplot(x, y, u, v, density=(1,1), INTEGRATOR='RK4', color=u,

linewidth=5*speed/speed.max())

plt.show()

Another option is to use VTK. It's accelerated 3D plotting, so making a 2D plot will require setting the camera properly (which isn't too hard), and you won't be able to get vector output.

Mayavi, tvtk, and mlab provide pythonic wrappers for VTK. It has lots of functionality along these lines.

The easiest way to use VTK to plot streamlines from numpy arrays is to use mayavi.mlab.flow. I'll skip an example for the moment, but if you want to explore using VTK to do this, I can add one.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值