So I’m trying to draw a streamlines of a Rankine oval using gnuplot. I have one .gp file to generate the datapoints and dump them in cont.dat
set table "cont.dat"
U = 1
s = 1
a = 1
f(x,y)= U*y - U*s*atan((2*a*y)/(x**2+y**2-a**2))
set angles radians
set xrange [-4:4]
set yrange [-2:2]
set zrange [*:*]
set cont base
set view 0,0
set isosample 200,200
set cntrparam levels incre -2*pi,0.25*pi,2*pi
unset surface
splot f(x,y)
Then one .gp file to plot these datapoints in a file called fig.tex
set terminal tikz size 3.5in,2.4in
set output "myfig.tex"
set xrange [-4:4]
set yrange [-2:2]
set size 2,1
plot "cont.dat" w l
using input{myfig} into my main tex document, I get the following output:
The zigzag parts are not supposed to be there and I can’t figure out what’s wrong. Is it some weird behaviour due to a divide by zero inside the atan? If so how can I fix it?
For reference the streamlines are supposed to look something like this
Any help would be wonderful
Nevermind, I just discovered atan2(y,x).
Replacing atan(y/x) with atan2(y,x) fixes it. Leaving this up in case someone else has the same problem.
1
You’ve already found the solution yourself. Just two minor comments/additions:
-
you don’t necessarily need two different scripts to generate and plot the data. And since gnuplot 5.0 you can put your data also into a datablock (check
help datablock
), no need for an extra datafile on disk. -
I assume you want to set the unit length for x- and y-axis the same. In your case the sizes of x- and y-axes are 8 and 4, respectively. So, the aspect ratio of the plot should be 2 (or 0.5 depending how you call it). But
set size 2,1
will set the size of the graph twice the x-size of the canvas which doesn’t really make sense (maybe doesn’t matter withtikz
-terminal). The intended way in this case would beset size ratio -1
, checkhelp size
.
Script:
### plot some contour lines
reset session
set table $Data
U = 1
s = 1
a = 1
f(x,y)= U*y - U*s*atan2(2*a*y, x**2+y**2-a**2)
set angles radians
set xrange [-4:4]
set yrange [-2:2]
set zrange [*:*]
set cont base
set view 0,0
set isosample 200,200
set cntrparam levels incr -2*pi,0.25*pi,2*pi
unset surface
splot f(x,y)
unset table
set xrange [-4:4]
set yrange [-2:2]
set size ratio -1
set key noautotitle
plot $Data w l
### end of script
Result: