Matplotlib 流线图,具有不中断或结束的流线 [英] Matplotlib streamplot with streamlines that don't break or end

查看:40
本文介绍了Matplotlib 流线图,具有不中断或结束的流线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个流线图,当它们彼此靠得太近时,这些线不会停止.我希望每个流线都在两个方向上进行计算,直到它到达窗口的边缘为止.结果是在某些区域它们会混在一起.但这就是我想要的.

I'd like to make a streamplot with lines that don't stop when they get too close together. I'd rather each streamline be calculated in both directions until it hits the edge of the window. The result is there'd be some areas where they'd all jumble up. But that's what I want.

无论如何,我有在matplotlib中执行此操作吗?如果没有,我是否可以使用其他工具来与python/numpy进行交互?

I there anyway to do this in matplotlib? If not, is there another tool I can use for this that could interface with python/numpy?

import numpy as np
import matplotlib.pyplot as plt
Y,X = np.mgrid[-10:10:.01, -10:10:.01]
U, V = Y**2, X**2
plt.streamplot(X,Y, U,V, density=1)
plt.show(False)

推荐答案

好吧,我发现我可以通过多次调高 密度 并使用自定义起点来获得我想要的大部分内容.我仍然对是否有更好的方法或其他方法感兴趣.

Ok, I've figured out I can get mostly what I want by turning up the density a lot and using custom start points. I'm still interested if there is a better or alternate way to do this.

这是我的解决方案.是不是看起来好多了?

Here's my solution. Doesn't it look so much better?

import numpy as np
import matplotlib.pyplot as plt
Y,X = np.mgrid[-10:10:.01, -10:10:.01]
y,x = Y[:,0], X[0,:]
U, V = Y**2, X**2
stream_points = np.array(zip(np.arange(-9,9,.5), -np.arange(-9,9,.5)))
plt.streamplot(x,y, U,V, start_points=stream_points, density=35)
plt.show(False)

顺便说一句, streamplot 中似乎存在一些错误,因此 start_points 关键字仅在将1d数组用于网格数据.请参见提供起点的Python Matplotlib Streamplot

By the way, there seems to be some bug in streamplot such that start_points keyword only works if you use 1d arrays for the grid data. See Python Matplotlib Streamplot providing start points

这篇关于Matplotlib 流线图,具有不中断或结束的流线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆