简体   繁体   English

matplotlib极性流图的范围错误

[英]Bad range of polar streamplot with matplotlib

I'm trying to plot streamlines in polar coordinates with matplotlib. 我正在尝试使用matplotlib在极坐标中绘制流线。 However, some issues seem to appear on the ranges of the polar plot. 但是,极坐标图的范围似乎出现了一些问题。 Here is one short example to illustrate the problem: 这是一个简短的示例来说明此问题:

import numpy as np
import matplotlib.pyplot as plt

r1 = np.linspace(0.5, 1, 50)
r2 = np.logspace(np.log10(0.5), np.log10(1.), 50)
t = np.linspace(0, 2*np.pi, 360)
r = r1

tt, rr = np.meshgrid(t, r)
v = 0*rr
u = rr

fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(1,1,1, projection='polar')
ax.streamplot(t, r, v, u, density=1., color='k', linewidth=3)
plt.show()
plt.close()

With r=r1 (linspace), there is no problem. 使用r=r1 (线性空间)时,没有问题。 But with r=r2 , the radial range of the plot is wrong and varies in [0.5, 0.82] instead of [0.5, 1.]. 但是,当r=r2 ,曲线图的径向范围是错误的,并且以[0.5,0.82]而不是[0.5,1.]变化。

What is wrong with my code ? 我的代码有什么问题?

From matplotlib.pyplot.streamplot 's doc , both x, y have to be evenly spaced. matplotlib.pyplot.streamplotdoc中x, y必须均匀间隔。 So you can interpolate your data using scipy's interpolants for instance. 因此,您可以使用scipy的插值对数据进行插值 griddata might fit your needs. griddata可能适合您的需求。

[EDIT] This was solved in this SO question with interpolation. [编辑]这是在解决这一所以用插值问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM