使用 gnuplot 的向量场

发布于 2024-10-27 05:37:49 字数 74 浏览 1 评论 0原文

如何绘制矢量场,其中每个点 (x, y) 的方向由 tangent(alpha) = f(x, y) 给出?

How do I plot a vector field, where the direction at each point (x, y) is given by tangent(alpha) = f(x, y)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心的位置 2024-11-03 05:37:49

据我所知,gnuplot 只能在从文件读取数据时绘制向量场。您的文件必须有 4 列,x、y、deltax 和 delta y,然后 gnuplot 将为文件中的每一行绘制从 (x,y) 到 (x+deltax, y+deltay) 的向量

plot "file.dat" using 1:2:3:4 with vectors head filled lt 2

:不坚持使用 gnuplot,还有其他工具可以更好或至少更容易地做到这一点。我个人使用 asymptote此处有一个在渐近线中绘制的矢量场示例。

As far as I can tell, gnuplot can only plot vector fields when reading data from a file. Your file will have to have 4 columns, x, y, deltax and delta y, and gnuplot will then plot a vector from (x,y) to (x+deltax, y+deltay) for each line in the file:

plot "file.dat" using 1:2:3:4 with vectors head filled lt 2

If you are not insisting on using gnuplot, there are other tools that can to this better or at least easier. I personally use asymptote. There is an example of a vectorfield plotted in asymptote here.

寂寞清仓 2024-11-03 05:37:49

看来这个问题/答案有点旧了,因为我相信 gnuplot 在最新版本中发生了一些变化,所以可能应该更新答案。

我在这里找到了一个很好且紧凑的解决方案:
http://gnuplot.10905.n7.nabble.com/Vector-Fields -td3627.html

为了方便起见,我将报告它:

set xrange [-5:5]
set yrange [-5:5]
# only integer x-cordinates
set samples 11
# only integer y-cordinates
set isosamples 11
# we need data, so we use the special filename "++", which
# produces x,y-pairs
plot "++" using 1:2:1:(2.*$2) with vectors

这里,最初的问题是如何绘制矢量场F(x,y) =
诀窍在于绘图“++”,它是一个特殊的文件名,允许使用 using 说明符中的函数。

因此,正如 @Jan 在他的回答中所说,gnuplot 需要数据文件中的 4 个字段来绘制矢量场,但这里的字段是合成的并由两个函数生成。

使用已定义函数的等效公式可以是:

set xrange [-5:5]
set yrange [-5:5]
dx(x) = x
dy(x) = 2*x
plot "++" using 1:2:(dx($1)):(dy($2)) w vec

有关更多详细信息,请参阅helpspecial-filenames

HIH

It seems this question/answer is a bit old, and since I believe that gnuplot is changed a bit in the latest versions, probably the answer should be updated.

I found a nice and compact solution here, by thse:
http://gnuplot.10905.n7.nabble.com/Vector-Fields-td3627.html

which I will report for convenience:

set xrange [-5:5]
set yrange [-5:5]
# only integer x-cordinates
set samples 11
# only integer y-cordinates
set isosamples 11
# we need data, so we use the special filename "++", which
# produces x,y-pairs
plot "++" using 1:2:1:(2.*$2) with vectors

Here, the original question was how to plot the vector field F(x,y) = <x, 2y>.
The trick is in the plot "++", which is a special file name which allows to use functions in the using specifier.

So, as @Jan said in his answer, gnuplot needs 4 fields in the data file to plot a vector field, but here the fields are synthetic and produced with two functions.

An equivalent formulation using defined functions could be:

set xrange [-5:5]
set yrange [-5:5]
dx(x) = x
dy(x) = 2*x
plot "++" using 1:2:(dx($1)):(dy($2)) w vec

See help special-filenames for further details.

HIH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文