python - matplotlib.pyplot.streamplot 中的轴错误

标签 python matplotlib

我正在尝试绘制流程的流线图。它将是一个直径为 D = 1 的圆柱体,处于均匀流中。 dominium x 从 0 到 37.5,y 从 21.1 到 0,圆柱体的中心位于 P(10.5,12)

matplotlib.pyplot.streamplot(x, y, uC, vC, \\
 density=4, linewidth=0.5, color='k', arrowsize=0.1)

但是我得到了下图:

flow

为什么轴限制与我的 dominium 值不匹配?

我想绘制圆柱体,但它大约会进入 (-3,25)。不在 (10.5,12) 中,因为它确实应该如此。

编辑:正如一些用户所说的 x 和 y 一定是错的,这里你有相同的 x,y 和箭袋。如您所见,这不是问题所在。

plt.quiver(x, y, uC, vC)

quiver

x = array([  0.0875    ,   0.2625    ,   0.4375    ,   0.6125    ,
     0.78702903,   0.96108708,   1.13514513,   1.30920318,
     1.48263691,   1.65544633,   1.82825575,   2.00106516,
     2.17305096,   2.34421315,   2.51537534,   2.68653753,
     2.85662006,   3.02562294,   3.19462581,   3.36362868,
     3.53122797,   3.69742367,   3.86361938,   4.02981508,
     4.19420566,   4.35679112,   4.51937658,   4.68196204,
     4.84225792,   5.00026421,   5.15827051,   5.31627681,
     5.47142954,   5.6237287 ,   5.77602786,   5.92832702,
     6.07714645,   6.22248615,   6.36782585,   6.51316555,
     6.65437309,   6.79144846,   6.92852384,   7.06559921,
     7.19791953,   7.32548479,   7.45305006,   7.58061532,
     7.7029027 ,   7.8199122 ,   7.93692171,   8.05393121,
     8.16531214,   8.27106448,   8.37681682,   8.48256916,
     8.58256916,   8.67681682,   8.77106448,   8.86531214,
     8.95393121,   9.03692171,   9.1199122 ,   9.2029027 ,
     9.28061532,   9.35305006,   9.42548479,   9.49791953,
     9.56559921,   9.62852384,   9.69144846,   9.75437309,
     9.81316555,   9.86782585,   9.92248615,   9.97714645,
    10.02832702,  10.07602786,  10.1237287 ,  10.17142954,
    10.21627681,  10.25827051,  10.30026421,  10.34225792,
    10.38196204,  10.41937658,  10.45679112,  10.49420566,
    10.52981508,  10.56361938,  10.59742367,  10.63122797,
    10.66362868,  10.69462581,  10.72562294,  10.75662006,
    10.78653753,  10.81537534,  10.84421315,  10.87305096,
    10.90106516,  10.92825575,  10.95544633,  10.98263691,
    11.00920318,  11.03514513,  11.06108708,  11.08702903,
    11.1125    ,  11.1375    ,  11.1625    ,  11.1875    ,
    11.2125    ,  11.2375    ,  11.2625    ,  11.2875    ,
    11.3125    ,  11.3375    ,  11.3625    ,  11.3875    ,
    11.4125    ,  11.4375    ,  11.4625    ,  11.4875    ,
    11.5125    ,  11.5375    ,  11.5625    ,  11.5875    ,
    11.6125    ,  11.6375    ,  11.6625    ,  11.6875    ,
    11.7125    ,  11.7375    ,  11.7625    ,  11.7875    ,
    11.8125    ,  11.8375    ,  11.8625    ,  11.8875    ,
    11.9125    ,  11.9375    ,  11.9625    ,  11.9875    ,
    12.0125    ,  12.0375    ,  12.0625    ,  12.0875    ,
    12.1125    ,  12.1375    ,  12.1625    ,  12.1875    ,
    12.2125    ,  12.2375    ,  12.2625    ,  12.2875    ,
    12.3125    ,  12.3375    ,  12.3625    ,  12.3875    ,
    12.4125    ,  12.4375    ,  12.4625    ,  12.4875    ,
    12.5125    ,  12.5375    ,  12.5625    ,  12.5875    ,
    12.6125    ,  12.6375    ,  12.6625    ,  12.6875    ,
    12.7125    ,  12.7375    ,  12.7625    ,  12.7875    ,
    12.8125    ,  12.8375    ,  12.8625    ,  12.8875    ,
    12.9125    ,  12.9375    ,  12.9625    ,  12.9875    ,
    13.0125    ,  13.0375    ,  13.0625    ,  13.0875    ,
    13.1125    ,  13.1375    ,  13.1625    ,  13.1875    ,
    13.21269549,  13.23808648,  13.26347746,  13.28886845,
    13.31448159,  13.34031688,  13.36615217,  13.39198747,
    13.41807502,  13.44441483,  13.47075465,  13.49709446,
    13.52372047,  13.55063268,  13.57754489,  13.6044571 ,
    13.63169369,  13.65925466,  13.68681564,  13.71437661,
    13.74230483,  13.7706003 ,  13.79889578,  13.82719125,
    13.85590198,  13.88502798,  13.91415397,  13.94327996,
    13.97287483,  14.00293858,  14.03300233,  14.06306608,
    14.09365839,  14.12477927,  14.15590015,  14.18702103,
    14.21873667,  14.25104709,  14.28335751,  14.31566792,
    14.34864624,  14.38229246,  14.41593868,  14.4495849 ,
    14.48397943,  14.51912227,  14.5542651 ,  14.58940794,
    14.62538702,  14.66220233,  14.69901765,  14.73583297,
    14.77358012,  14.8122591 ,  14.85093808,  14.88961706,
    14.92933106,  14.9700801 ,  15.01082914,  15.05157818,
    15.0934728 ,  15.136513  ,  15.1795532 ,  15.2225934 ,
    15.26689657,  15.31246271,  15.35802885,  15.40359499,
    15.45054749,  15.49888635,  15.54722522,  15.59556409,
    15.64541755,  15.69678561,  15.74815367,  15.79952173,
    15.85253591,  15.90719621,  15.96185651,  16.01651681,
    16.07295611,  16.1311744 ,  16.1893927 ,  16.24761099,
    16.3077402 ,  16.36978031,  16.43182043,  16.49386055,
    16.55793988,  16.62405842,  16.69017697,  16.75629551,
    16.82457503,  16.89501553,  16.96545603,  17.03589653,
    17.10861016,  17.18359692,  17.25858368,  17.33357044,
    17.41092975,  17.49066163,  17.5703935 ,  17.65012537,
    17.73231355,  17.81695802,  17.9016025 ,  17.98624697,
    18.07341316,  18.16310105,  18.25278893,  18.34247682,
    18.43473132,  18.52955241,  18.62437351,  18.71919461,
    18.81660515,  18.91660515,  19.01660515,  19.11660515,
    19.21919461,  19.32437351,  19.42955241,  19.53473132,
    19.64247682,  19.75278893,  19.86310105,  19.97341316,
    20.08624697,  20.2016025 ,  20.31695802,  20.43231355,
    20.55012537,  20.6703935 ,  20.79066163,  20.91092975,
    21.03357044,  21.15858368,  21.28359692,  21.40861016,
    21.53589653,  21.66545603,  21.79501553,  21.92457503,
    22.05629551,  22.19017697,  22.32405842,  22.45793988,
    22.59386055,  22.73182043,  22.86978031,  23.0077402 ,
    23.14761099,  23.2893927 ,  23.4311744 ,  23.57295611,
    23.71651681,  23.86185651,  24.00719621,  24.15253591,
    24.29952173,  24.44815367,  24.59678561,  24.74541755,
    24.89556409,  25.04722522,  25.19888635,  25.35054749,
    25.50359499,  25.65802885,  25.81246271,  25.96689657,
    26.1225934 ,  26.2795532 ,  26.436513  ,  26.5934728 ,
    26.75157818,  26.91082914,  27.0700801 ,  27.22933106,
    27.38961706,  27.55093808,  27.7122591 ,  27.87358012,
    28.03583297,  28.19901765,  28.36220233,  28.52538702,
    28.68940794,  28.8542651 ,  29.01912227,  29.18397943,
    29.3495849 ,  29.51593868,  29.68229246,  29.84864624,
    30.01566792,  30.18335751,  30.35104709,  30.51873667,
    30.68702103,  30.85590015,  31.02477927,  31.19365839,
    31.36306608,  31.53300233,  31.70293858,  31.87287483,
    32.04327996,  32.21415397,  32.38502798,  32.55590198,
    32.72719125,  32.89889578,  33.0706003 ,  33.24230483,
    33.41437661,  33.58681564,  33.75925466,  33.93169369,
    34.1044571 ,  34.27754489,  34.45063268,  34.62372047,
    34.79709446,  34.97075465,  35.14441483,  35.31807502,
    35.49198747,  35.66615217,  35.84031688,  36.01448159,
    36.18886845,  36.36347746,  36.53808648,  36.71269549,
    36.8875    ,  37.0625    ,  37.2375    ,  37.4125    ])

y = array([ 21.0125    ,  20.8375    ,  20.6625    ,  20.4875    ,
    20.31306738,  20.13920213,  19.96533688,  19.79147163,
    19.61839551,  19.44610852,  19.27382153,  19.10153455,
    18.93033727,  18.76022971,  18.59012215,  18.42001459,
    18.251397  ,  18.08426939,  17.91714178,  17.75001416,
    17.58489649,  17.42178875,  17.25868101,  17.09557327,
    16.93512806,  16.77734538,  16.61956269,  16.46178001,
    16.30744068,  16.15654472,  16.00564876,  15.8547528 ,
    15.70817439,  15.56591355,  15.4236527 ,  15.28139185,
    15.14433954,  15.01249576,  14.88065198,  14.7488082 ,
    14.62296276,  14.50311566,  14.38326856,  14.26342146,
    14.15012386,  14.04337576,  13.93662767,  13.82987957,
    13.72987957,  13.63662767,  13.54337576,  13.45012386,
    13.36342146,  13.28326856,  13.20311566,  13.12296276,
    13.0488082 ,  12.98065198,  12.91249576,  12.84433954,
    12.78139185,  12.7236527 ,  12.66591355,  12.60817439,
    12.5547528 ,  12.50564876,  12.45654472,  12.40744068,
    12.36178001,  12.31956269,  12.27734538,  12.23512806,
    12.19557327,  12.15868101,  12.12178875,  12.08489649,
    12.05001416,  12.01714178,  11.98426939,  11.951397  ,
    11.92001459,  11.89012215,  11.86022971,  11.83033727,
    11.80153455,  11.77382153,  11.74610852,  11.71839551,
    11.69147163,  11.66533688,  11.63920213,  11.61306738,
    11.5875    ,  11.5625    ,  11.5375    ,  11.5125    ,
    11.4875    ,  11.4625    ,  11.4375    ,  11.4125    ,
    11.3875    ,  11.3625    ,  11.3375    ,  11.3125    ,
    11.2875    ,  11.2625    ,  11.2375    ,  11.2125    ,
    11.1875    ,  11.1625    ,  11.1375    ,  11.1125    ,
    11.0875    ,  11.0625    ,  11.0375    ,  11.0125    ,
    10.9875    ,  10.9625    ,  10.9375    ,  10.9125    ,
    10.8875    ,  10.8625    ,  10.8375    ,  10.8125    ,
    10.7875    ,  10.7625    ,  10.7375    ,  10.7125    ,
    10.6875    ,  10.6625    ,  10.6375    ,  10.6125    ,
    10.5875    ,  10.5625    ,  10.5375    ,  10.5125    ,
    10.4875    ,  10.4625    ,  10.4375    ,  10.4125    ,
    10.3875    ,  10.3625    ,  10.3375    ,  10.3125    ,
    10.2875    ,  10.2625    ,  10.2375    ,  10.2125    ,
    10.1875    ,  10.1625    ,  10.1375    ,  10.1125    ,
    10.0875    ,  10.0625    ,  10.0375    ,  10.0125    ,
     9.9875    ,   9.9625    ,   9.9375    ,   9.9125    ,
     9.8875    ,   9.8625    ,   9.8375    ,   9.8125    ,
     9.7875    ,   9.7625    ,   9.7375    ,   9.7125    ,
     9.6875    ,   9.6625    ,   9.6375    ,   9.6125    ,
     9.5875    ,   9.5625    ,   9.5375    ,   9.5125    ,
     9.48693262,   9.46079787,   9.43466312,   9.40852837,
     9.38160449,   9.35389148,   9.32617847,   9.29846545,
     9.26966273,   9.23977029,   9.20987785,   9.17998541,
     9.148603  ,   9.11573061,   9.08285822,   9.04998584,
     9.01510351,   8.97821125,   8.94131899,   8.90442673,
     8.86487194,   8.82265462,   8.78043731,   8.73821999,
     8.69255932,   8.64345528,   8.59435124,   8.5452472 ,
     8.49182561,   8.43408645,   8.3763473 ,   8.31860815,
     8.25566046,   8.18750424,   8.11934802,   8.0511918 ,
     7.97703724,   7.89688434,   7.81673144,   7.73657854,
     7.64987614,   7.55662424,   7.46337233,   7.37012043,
     7.27012043,   7.16337233,   7.05662424,   6.94987614,
     6.83657854,   6.71673144,   6.59688434,   6.47703724,
     6.3511918 ,   6.21934802,   6.08750424,   5.95566046,
     5.81860815,   5.6763473 ,   5.53408645,   5.39182561,
     5.2452472 ,   5.09435124,   4.94345528,   4.79255932,
     4.63821999,   4.48043731,   4.32265462,   4.16487194,
     4.00442673,   3.84131899,   3.67821125,   3.51510351,
     3.34998584,   3.18285822,   3.01573061,   2.848603  ,
     2.67998541,   2.50987785,   2.33977029,   2.16966273,
     1.99846545,   1.82617847,   1.65389148,   1.48160449,
     1.30852837,   1.13466312,   0.96079787,   0.78693262,
     0.6125    ,   0.4375    ,   0.2625    ,   0.0875    ])

最佳答案

正如我所怀疑的,问题出在您的 xy 数组上。来自 the streamplot documentation :

x, y :1d arrays

an evenly spaced grid.

您的 xy 坐标不是均匀分布的(对于您的 y 坐标,它们也单调递减而不是递增).

为了使用 streamplot 绘制您的数据,您需要将其重新采样到常规的二维网格上。例如,您可以使用 scipy.interpolate.interp2d :

from scipy.interpolate import interp2d

# regularly spaced grid spanning the domain of x and y 
xi = np.linspace(x.min(), x.max(), x.size)
yi = np.linspace(y.min(), y.max(), y.size)

# bicubic interpolation
uCi = interp2d(x, y, uC)(xi, yi)
vCi = interp2d(x, y, vC)(xi, yi)

plt.streamplot(xi, yi, uCi, vCi)

关于python - matplotlib.pyplot.streamplot 中的轴错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34711705/

相关文章:

Python AWS lambda 函数连接到 RDS mysql : Timeout error

python - 如何使用 seaborn 的 lmplot 显示色调的颜色而不是精确值?

python - 如何在 matplotlib 中反射(reflect)矩阵?

python - 在python中向贝塞尔图添加多条线

python : Printing contents of a file to the terminal

python - `__init__` 能做什么而 `__new__` 不能?

python - MySQLdb 使用字段名称和值 python 列表插入数据库

先前缩放时 Matplotlib 不方便 "reset to original view"

python - 面向对象的 matplotlib 使用神秘地生成没有 mustache 或中线的箱线图

python - 用于捕获仅有时出现的组的正则表达式