【问题标题】:Plotting vector fields in python (matplotlib)在 python (matplotlib) 中绘制向量场
【发布时间】:2023-03-06 10:51:01
【问题描述】:

我在http://matplotlib.sourceforge.net/examples/pylab_examples/quiver_demo.html找到了这个代码

from pylab import *
from numpy import ma

X,Y = meshgrid( arange(0,2*pi,.2),arange(0,2*pi,.2) )
U = cos(X)
V = sin(Y)

#1
figure()
Q = quiver( U, V)
qk = quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W',
               fontproperties={'weight': 'bold'})
l,r,b,t = axis()
dx, dy = r-l, t-b
axis([l-0.05*dx, r+0.05*dx, b-0.05*dy, t+0.05*dy])

title('Minimal arguments, no kwargs')

现在,我怎样才能看到这个图形?更好的是,我怎样才能将它保存到一个文件中,比如说,JPEG?代码似乎可以运行,但我看不到任何事情发生。

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    你需要callshow()savefig()

    【讨论】:

      【解决方案2】:

      在脚本末尾粘贴show()。或者将其保存到 jpg 文件中,放入

      savefig('output.jpg')
      show()
      

      请务必将savefig() 命令放在show() 之前。

      【讨论】:

        【解决方案3】:

        理想情况下,您可以在交互式 shell(如 EPD Python 的 PyLab)中键入它。否则,需要显式调用show() 命令

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-07-06
          • 1970-01-01
          • 2015-12-30
          • 2018-12-30
          • 1970-01-01
          • 2016-10-05
          • 2021-12-30
          相关资源
          最近更新 更多