On Wednesday, January 16, 2013 10:22:34 am Judge_Dredd wrote:
> Hello. I want to plot field lines in 3d. I have googled and searched on the
> list for the subject and found no satisfactory info so i assumed that
> gnuplot isn't able to draw field lines.
I realized that you asked about "field lines" rather "vector field",
but let me offer an option that gnuplot already supports.
The gnuplot demo collection has an example of drawing vector fields in 2D
The commands for drawing vectors in 3D are essentially the same except that
the syntax is
splot 'vectors' using (x):(y):(z):(DelX):(DelY):(DelZ) with vectors
But it is true that gnuplot does not provide an auto-sampling mode for
a 3D grid, so if you wanted to fill 3-space with a vector field with a
single command you would have to iterate over 2D layers. E.g.
splot for [Z=0:10] '++' using (X):(Y):(Z):(DelX):(DelY):(DelZ) with vectors
Here is an example that generates a totally boring 3D uniform vector field:
set xr [0:4]
set yr [0:4]
set samples 5,5
set isosamples 5,5
set style data vectors
splot for [Z=1:4] '++' using ($1):($2):(Z):(.1):(.1):(.1)
If you had a set of functions that returned the X, Y, or Z component of
the field at a given point then you could replace that command by
splot for [Z=1:4] '++' using \
($1) : ($2) : (Z) : (Vx($1,$2,Z)) : (Vy($1,$2,Z)) : (Vz($1,$2,Z))
> I wish to take a little part in dev
> and have already read some of the relevant gnuplot source code. I found it
> complicated to implement a standard algo for drawing field lines (it would
> have been much easier if points were on a 3d grid, but a user can define
> vectors which are placed randomly) to get a nice picture.
Right. The example above uses a regular grid because that is what gnuplot
can generate for you inside the plot command itself. But there is no such
limitation if you are reading arbitrary 3D vectors from a file.
> It is not fully
> clear to me how gnuplot determines validity of the input file and how it
> plots a function (not a data file). Can I get help here in navigating in
> source code?
> I would like to thank all contributers. Gnuplot is a functional and easy to
> use tool.