簡體   English   中英

箭頭圖箭頭縱橫比

[英]Quiver plot arrow aspect ratio

我在使用Matplotlib的箭袋情節時遇到了一些問題。 給定速度矢量場,我想在流線上繪制速度矢量。 矢量與預期的流函數不相切。

為了計算流函數,我使用了Pankratov博士的Matlab代碼的Python翻譯版本,可在http://www-pord.ucsd.edu/~matlab/stream.htm獲得 (我的很快將在GitHub上提供)。

使用其結果,我使用此代碼:

import numpy
import pylab

# Regular grid coordineates, velocity field and stream function
x, y = numpy.meshgrid(numpy.arange(0, 21), numpy.arange(0, 11))
u = numpy.array([[10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
        27, 28, 29, 30],
       [ 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
        26, 27, 28, 29],
       [ 8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
        25, 26, 27, 28],
       [ 7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
        24, 25, 26, 27],
       [ 6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
        23, 24, 25, 26],
       [ 5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
        22, 23, 24, 25],
       [ 4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
        21, 22, 23, 24],
       [ 3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
        20, 21, 22, 23],
       [ 2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
        19, 20, 21, 22],
       [ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
        18, 19, 20, 21],
       [ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20]])
v = numpy.array([[  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,
         13,  14,  15,  16,  17,  18,  19,  20],
       [ -1,   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,
         12,  13,  14,  15,  16,  17,  18,  19],
       [ -2,  -1,   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,
         11,  12,  13,  14,  15,  16,  17,  18],
       [ -3,  -2,  -1,   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
         10,  11,  12,  13,  14,  15,  16,  17],
       [ -4,  -3,  -2,  -1,   0,   1,   2,   3,   4,   5,   6,   7,   8,
          9,  10,  11,  12,  13,  14,  15,  16],
       [ -5,  -4,  -3,  -2,  -1,   0,   1,   2,   3,   4,   5,   6,   7,
          8,   9,  10,  11,  12,  13,  14,  15],
       [ -6,  -5,  -4,  -3,  -2,  -1,   0,   1,   2,   3,   4,   5,   6,
          7,   8,   9,  10,  11,  12,  13,  14],
       [ -7,  -6,  -5,  -4,  -3,  -2,  -1,   0,   1,   2,   3,   4,   5,
          6,   7,   8,   9,  10,  11,  12,  13],
       [ -8,  -7,  -6,  -5,  -4,  -3,  -2,  -1,   0,   1,   2,   3,   4,
          5,   6,   7,   8,   9,  10,  11,  12],
       [ -9,  -8,  -7,  -6,  -5,  -4,  -3,  -2,  -1,   0,   1,   2,   3,
          4,   5,   6,   7,   8,   9,  10,  11],
       [-10,  -9,  -8,  -7,  -6,  -5,  -4,  -3,  -2,  -1,   0,   1,   2,
          3,   4,   5,   6,   7,   8,   9,  10]])
psi = numpy.array([[   0. ,    0.5,    2. ,    4.5,    8. ,   12.5,   18. ,   24.5,
          32. ,   40.5,   50. ,   60.5,   72. ,   84.5,   98. ,  112.5,
         128. ,  144.5,  162. ,  180.5,  200. ],
       [  -9.5,  -10. ,   -9.5,   -8. ,   -5.5,   -2. ,    2.5,    8. ,
          14.5,   22. ,   30.5,   40. ,   50.5,   62. ,   74.5,   88. ,
         102.5,  118. ,  134.5,  152. ,  170.5],
       [ -18. ,  -19.5,  -20. ,  -19.5,  -18. ,  -15.5,  -12. ,   -7.5,
          -2. ,    4.5,   12. ,   20.5,   30. ,   40.5,   52. ,   64.5,
          78. ,   92.5,  108. ,  124.5,  142. ],
       [ -25.5,  -28. ,  -29.5,  -30. ,  -29.5,  -28. ,  -25.5,  -22. ,
         -17.5,  -12. ,   -5.5,    2. ,   10.5,   20. ,   30.5,   42. ,
          54.5,   68. ,   82.5,   98. ,  114.5],
       [ -32. ,  -35.5,  -38. ,  -39.5,  -40. ,  -39.5,  -38. ,  -35.5,
         -32. ,  -27.5,  -22. ,  -15.5,   -8. ,    0.5,   10. ,   20.5,
          32. ,   44.5,   58. ,   72.5,   88. ],
       [ -37.5,  -42. ,  -45.5,  -48. ,  -49.5,  -50. ,  -49.5,  -48. ,
         -45.5,  -42. ,  -37.5,  -32. ,  -25.5,  -18. ,   -9.5,    0. ,
          10.5,   22. ,   34.5,   48. ,   62.5],
       [ -42. ,  -47.5,  -52. ,  -55.5,  -58. ,  -59.5,  -60. ,  -59.5,
         -58. ,  -55.5,  -52. ,  -47.5,  -42. ,  -35.5,  -28. ,  -19.5,
         -10. ,    0.5,   12. ,   24.5,   38. ],
       [ -45.5,  -52. ,  -57.5,  -62. ,  -65.5,  -68. ,  -69.5,  -70. ,
         -69.5,  -68. ,  -65.5,  -62. ,  -57.5,  -52. ,  -45.5,  -38. ,
         -29.5,  -20. ,   -9.5,    2. ,   14.5],
       [ -48. ,  -55.5,  -62. ,  -67.5,  -72. ,  -75.5,  -78. ,  -79.5,
         -80. ,  -79.5,  -78. ,  -75.5,  -72. ,  -67.5,  -62. ,  -55.5,
         -48. ,  -39.5,  -30. ,  -19.5,   -8. ],
       [ -49.5,  -58. ,  -65.5,  -72. ,  -77.5,  -82. ,  -85.5,  -88. ,
         -89.5,  -90. ,  -89.5,  -88. ,  -85.5,  -82. ,  -77.5,  -72. ,
         -65.5,  -58. ,  -49.5,  -40. ,  -29.5],
       [ -50. ,  -59.5,  -68. ,  -75.5,  -82. ,  -87.5,  -92. ,  -95.5,
         -98. ,  -99.5, -100. ,  -99.5,  -98. ,  -95.5,  -92. ,  -87.5,
         -82. ,  -75.5,  -68. ,  -59.5,  -50. ]])

# The plots!
pylab.close('all')
pylab.ion()
pylab.figure(figsize=[8, 8])
pylab.contour(x, y, psi, 20, colors='k', linestyles='-', linewidth=1.0)
pylab.quiver(x, y, u, v, angles='uv', scale_units='xy', scale=10)

ax = pylab.axes()
ax.set_aspect(1.)

產生以下結果來說明我的問題。

任何速度場及其流函數\\ Psi,具有意外縱橫比的矢量

顯然,計算很好,但速度矢量與流函數不相符,正如預期的那樣。 使用精確的保存值,Matlab會生成一個箭頭圖,可以准確顯示我想要的內容。 在我的例子中,將寬高比設置為1可以得到所需的結果,但強制軸矩形具有特定的寬高比。

ax = pylab.axes()
ax.set_aspect(1.)

我已經嘗試過不同的參數,例如'units','angles'或'scale'。

是否有人知道如何制作適應畫布寬高比並且仍然與我的輪廓線相切的箭頭圖,如預期的那樣?

我期望得到與此類似的結果(注意向量如何與流線相切): 使用Matlab的任何速度場及其流函數\\ Psi,具有預期縱橫比的矢量

非常感謝!

使用繪制你的箭袋(doc)

pylab.quiver(x, y, u, v, angles='xy', scale_units='xy', scale=10)

angles='uv'通過atan2(u,v)設置矢量angles='xy'angles='xy'將矢量從(x,y)繪制到(x+u, y+v)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM