■ gnuplot の試験

memoPicture001.jpg

http://gnuplot.sourceforge.net/demo_4.1/index.html


上記サイトのサンプルを脈略も無く適当に試してみた。一部実行できないプログラムがあった。これは私がインストールしている gnuplot のバージョンが 4.2 のためだろう。


なおこのページは CalendarMemo から gnuplot のコマンドを実行したドキュメントを ⌘+option +H で html に変換したものである。


#gnuplot

# $Id: singulr.dem,v 1.6 2003/10/28 05:35:54 sfeam Exp $

#

# Demo that plots some surfaces with singularities.

# Author: Carsten Steger

#

# (x,y,x^2-y^2,2xy) is the graph of w=z^2 in 4-space.

# Therefore (x^2-y^2,2xy,x,y) is the graph of w=sqrt(z) in 4-space.

# Coordinates 1, 2, and 3 give the real part of either function,

# whereas coordinates 1, 2, and 4 give the imaginary part.

# The same holds for the cube function w=z^3. The graphs are given by

# (x,y,x^3-3xy^2,3x^2y-y^3) and (x^3-3xy^2,3x^2y-y^3,x,y).

# And so on...


set parametric

set hidden3d

set isosamples 21

set autoscale


set view 60,30

set urange [-3:3]

set vrange [-3:3]

set title "Real part of complex square root function"

splot u**2-v**2,2*u*v,u

memoPicture002.jpg


#gnuplot

set parametric

set hidden3d

set isosamples 21

set autoscale

set isosamples 21

set view 60,20

set urange [-3:3]

set vrange [-3:3]

set title "Enneper's surface"

splot u-u**3/3+u*v**2,v-v**3/3+v*u**2,u**2-v**2memoPicture003.jpg


#gnuplot

set parametric

set hidden3d

set isosamples 21

set autoscale

unset key

set xrange [-10:10]

set yrange [-10:10]

set zrange [-3:3]

set urange [0:2*pi]

set vrange [0:2*pi]

set isosamples 39,60

set view 60,120

set title "Klein bottle"

splot  (2*sin(u)*cos(v/2)-sin(2*u)*sin(v/2)+8)*cos(v), \

       (2*sin(u)*cos(v/2)-sin(2*u)*sin(v/2)+8)*sin(v), \

        2*sin(u)*sin(v/2)+sin(2*u)*cos(v/2)

memoPicture004.jpg


#gnuplot

set parametric

set hidden3d

set isosamples 21

set autoscale

set urange [0:2*pi]

set vrange [0:4*pi/3]

set isosamples 39,40

set view 60,20

set title "Klein bottle with look at the 'inside'"

splot  (2*sin(u)*cos(v/2)-sin(2*u)*sin(v/2)+8)*cos(v), \

       (2*sin(u)*cos(v/2)-sin(2*u)*sin(v/2)+8)*sin(v), \

        2*sin(u)*sin(v/2)+sin(2*u)*cos(v/2)

memoPicture005.jpg

#gnuplot

#

# $Id: controls.dem,v 1.3 1999/10/17 19:16:58 lhecking Exp $

#

# warning:  this demo is SLOW on PCs without math coprocessors!

#

# From _Automatic_Control_Systems_, fourth ed., figure 6-14

# transient response of a second-order system to a unit step input function

#

damp(t) = exp(-s*wn*t)/sqrt(1.0-s*s)

per(t) = sin(wn*sqrt(1.0-s**2)*t - atan(-sqrt(1.0-s**2)/s))

c(t) = 1-damp(t)*per(t)

#

# wn is natural undamped frequency

# s is damping factor

#

wn = 1.0

set xrange [0:13]

set samples 50

set dummy t

set key box

#

# plot c(t) for several different damping factors s

#

plot s=.1,c(t),s=.3,c(t),s=.5,c(t),s=.7,c(t),s=.9,c(t),s=1.0,c(t),s=1.5,c(t),s=2.0,c(t)memoPicture006.jpg

.OK.


#gnuplot

# demo for the use of "set object rectangle"

#

# Ethan A Merritt - 2006


if ((GPVAL_VERSION == 4.3 || GPVAL_VERSION == 4.2) \

&&  (!strstrt(GPVAL_COMPILE_OPTIONS,"+OBJECTS"))) \

    print ">>> Skipping demo <<<\n" ; \

    print "This copy of gnuplot was built without support for placing rectangles\n" ; \

    exit ;


set style line 1 bgnd

set style line 2 lt rgb "cyan"


set object 1 rect from 0,0 to 1,4 fc lt 2

set object 2 rect from -1,1 to 0,5 fc rgb "gold"

set object 5 rect from 0, -3 to 2, -2 fc ls 2 fs pattern 1 bo -1


set style fill pattern 2 bo 1


#

# Illustrate putting a different color under the key box

#

set key nobox

set object 7 rect from graph 0.65,graph 0.85 to graph 0.99, graph 0.99 fc ls 1


#

# Illustrate using character widths to put a box around a label

#

LABEL = "Label in a box"

set obj 10 rect at -3,-4 size char strlen(LABEL), char 1

set obj 10 fillstyle empty border -1 front

set label 10 at -3,-4 LABEL front center


set obj 9 rect from -4, -4 to -4, -3 fc lt -1


set obj 20 rect from graph 0, graph 0 to graph 1, graph 1 fs solid 0.15 fc rgb "#FFD700" behind


plot [-5:5] x, -3+sin(x*5)/x lt 3 lw 3

memoPicture007.jpg


#gnuplot

#

# $Id: random.dem,v 1.13 2006/10/23 05:43:53 sfeam Exp $

#

# random.dem

#

# Lattice test for random numbers;

# If you can see any patterns in this plot, the random number generator

# is not very good.

#

# Copyright (c) 1991, Jos van der Woude, jvdwoude@hut.nl


# History:

# -  6. 6. 2006 ds: added univariate and multivariate normal example

# - 10. 5. 2006 ds: added univariate and multivariate normal example

# -  ?. ?  1991 jvdw: 1st version


unset key

set xrange [0: 1]

set yrange [0: 1]

set zrange [0: 1]

set title "Lattice test for random numbers"

set xlabel "rand(n) ->"

set ylabel "rand(n + 1) ->"

set zlabel "rand(n + 2) ->"

set format x "%3.2f"

set format y "%3.2f"

set format z "%3.2f"

set tics

set sample 1000

set style function dots

set parametric

plot rand(0), rand(0)

memoPicture008.jpg

#gnuplot

#

# $Id: pm3dcolors.dem,v 1.3 2006/03/23 17:53:04 mikulik Exp $

#

# Test of new color modes for pm3d palettes.


#

#   Gradient Palettes

#

set pm3d; set palette

set palette color

set pm3d map

set cbrange [-10:10]

set xrange [-10:10]

set yrange [*:*]

unset ztics

unset ytics

set samples 101

set isosamples 2

set xtics 2


set palette model RGB


set palette defined

set title "set palette defined"

splot x

memoPicture009.jpg

#gnuplot

set title "Interlocking Tori - PM3D surface with depth sorting and transparency"

unset border

unset key

set object 1 rect from screen 0, 0, 0 to screen 1, 1, 0 behind

set object 1 rect fc  rgb "gray"  fillstyle solid 1.0  border -1

set view 64, 345, 1.24375, 0.995902

set isosamples 50, 20

unset xtics

unset ytics

unset ztics

set parametric

set dummy u,v

set urange [ -pi : pi ]

set vrange [ -pi : pi ]


set pm3d depthorder hidden3d 2

set palette rgbformulae 8, 9, 7

set style line 2  linetype 2 linecolor rgb "#a0a0f0"  linewidth 0.5

#set style fill transparent solid 0.30 border

splot cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with pm3d, 1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with pm3d

memoPicture010.jpg

.OK.


#gnuplot

#

# $Id: pm3dcolors.dem,v 1.3 2006/03/23 17:53:04 mikulik Exp $

#

# Test of new color modes for pm3d palettes.


#

#   Gradient Palettes

#

set pm3d; set palette

set palette color

set pm3d map

set cbrange [-10:10]

set xrange [-10:10]

set yrange [*:*]

unset ztics

unset ytics

set samples 101

set isosamples 2

set xtics 2


set palette model RGB


set palette defined (0 0 0 0, 1 0 0 1, 3 0 1 0, 4 1 0 0, 6 1 1 1)

set title 'set palette defined (0 0 0 0, 1 0 0 1, 3 0 1 0, 4 1 0 0, 6 1 1 1)'

splot x

memoPicture011.jpg


#gnuplot

#

# $Id: surface1.dem,v 1.11 2004/09/17 05:01:12 sfeam Exp $

#

set samples 21

set isosample 11

set xlabel "X axis" offset -3,-2

set ylabel "Y axis" offset 3,-2

set zlabel "Z axis" offset -5

set title "3D gnuplot demo"

set label 1 "This is the surface boundary" at -10,-5,150 center

set arrow 1 from -10,-5,120 to -10,0,0 nohead

set arrow 2 from -10,-5,120 to 10,0,0 nohead

set arrow 3 from -10,-5,120 to 0,10,0 nohead

set arrow 4 from -10,-5,120 to 0,-10,0 nohead

set xrange [-10:10]

set yrange [-10:10]

splot x*y

memoPicture012.jpg

.OK.


#gnuplot

set samples 21

set isosample 11

set xlabel "X axis" offset -3,-2

set ylabel "Y axis" offset 3,-2

set zlabel "Z axis" offset -5

set title "3D gnuplot demo"

set xrange [-10:10]

set yrange [-10:10]

set grid

splot x**2+y**2, x**2-y**2

memoPicture013.jpg

#gnuplot

set samples 21

set isosample 11

set xlabel "X axis" offset -3,-2

set ylabel "Y axis" offset 3,-2

set zlabel "Z axis" offset -5

set title "3D gnuplot demo"

set xtics ("low" -3, "mid" 0, "high" 3)

set ytics -2,0.5,2

set xrange [-3:3]

set yrange [-3:3]

set log z

set title "Surfaces with z log scale"

splot x**2*y**2 + 2, x**2*y**4 + 2, x**4*y**2 + 2memoPicture014.jpg


#gnuplot

#

# $Id: surface2.dem,v 1.4 1999/10/17 19:17:01 lhecking Exp $

#

set parametric

set isosamples 50,10

set hidden

set key below


set title "Parametric Sphere"

set urange [-pi/2:pi/2]

set vrange [0:2*pi]

set ztics nomirror -1.0,0.25,1.0

set view 45,50

splot cos(u)*cos(v),cos(u)*sin(v),sin(u)

memoPicture015.jpg

.OK.


#gnuplot

set parametric

set isosamples 50,10

set hidden

set key below

set view ,,,1.0

set title "Parametric Torus"

set urange [0:2*pi]

set vrange [0:2*pi]

set zrange [-1:1]        # imitate old 'set view' hack

splot (1-0.2*cos(v))*cos(u),(1-0.2*cos(v))*sin(u),0.2*sin(v)memoPicture016.jpg

#gnuplot

set parametric

set isosamples 50,10

set hidden

set key below

set view ,,1.,1.

set title "Parametric Helix"

set isosamples 100,20

set urange [0:10*pi]

set vrange [0:2*pi]

set autoscale z

splot (1-0.1*cos(v))*cos(u),(1-0.1*cos(v))*sin(u),0.1*(sin(v)+u/1.7-10)memoPicture017.jpg

#gnuplot

set parametric

set isosamples 50,10

set hidden

set key below

set title "Interlocking Tori"


set urange [-pi:pi]

set vrange [-pi:pi]

set isosamples 50,20

splot cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with lines, \

      1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with linesmemoPicture018.jpg


#gnuplot

set parametric

set dummy t

set autoscale

set samples 160

set title ""

set key box

set key below

set autoscale x

set yrange [-1.5:1.5]

set trange [0.0001:10*pi]

plot sin(t)/t,cos(t)/t

memoPicture019.jpg

.OK.


#gnuplot

set title "Some sqrt stripes on filled graph background"

plot [0:10] [-8:6] \

-8 with filledcurve x2 lt 15, \

sqrt(x) with filledcurves y1=-0.5, \

sqrt(10-x)-4.5 with filledcurves y1=-5.5memoPicture020.jpg

.OK.


#gnuplot

#

# $Id: simple.dem,v 1.4 2006/06/30 02:17:22 sfeam Exp $

#

# Requires data files "[123].dat" from this directory,

# so change current working directory to this directory before running.

# gnuplot> set term <term-type>

# gnuplot> load 'simple.dem'

#

set key left box

set samples 50

plot [-10:10] sin(x),atan(x),cos(atan(x))

memoPicture021.jpg

.OK.


#gnuplot

set key right nobox

set samples 100

plot [-pi/2:pi] cos(x),-(sin(x) > sin(x+1) ? sin(x) : sin(x+1))memoPicture022.jpg

.OK.


#gnuplot

set title "Interlocking Tori - PM3D surface with depth sorting"

set parametric

set urange [-pi:pi]

set vrange [-pi:pi]

set isosamples 50,20


unset key

unset xtics

unset ytics

unset ztics

set border 0

set view 60, 30, 1.1, 1.33


set pm3d depthorder

splot cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with pm3d, \

      1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with pm3dmemoPicture023.jpg

.OK.


#gnuplot

set logscale z

set hidden3d

set isosamples 60

set ticslevel 0.

set view 20,340 #HBB: ,1,2

set xlabel "x"

set ylabel "y"

splot [-1.5:1.5] [-0.5:1.5] (1-x)**2 + 100*(y - x**2)**2memoPicture024.jpg

.OK.


#gnuplot

set cntrparam levels auto 10

set title "3D gnuplot demo - contour plot on base grid"

set contour base

splot x**2-y**2

memoPicture025.jpg

.OK.


#gnuplot

set xlabel "x"

set ylabel "y"

set key top

set border 4095

set xrange [-15:15]

set yrange [-15:15]

set zrange [-0.25:1]

set samples 50

set isosamples 40


set title "pm3d demo. Radial sinc function. Default options."

set pm3d; set palette

#show pm3d

#show palette

splot sin(sqrt(x**2+y**2))/sqrt(x**2+y**2)

memoPicture026.jpg

.OK.


#gnuplot

set samples 20

set isosamples 20

set hidden3d

set title "Hidden line removal of explicit surfaces"


set xrange [-3:3]

set yrange [-2:2]

splot 1 / (x*x + y*y + 1)

memoPicture027.jpg

.OK.


#

# Another example of pm3d hidden surface removal,

# this time using pm3d depth-ordering

#


#gnuplot

set title "Interlocking Tori - PM3D surface with no depth sorting"

set parametric

set urange [-pi:pi]

set vrange [-pi:pi]

set isosamples 50,20

unset key

unset xtics

unset ytics


unset ztics

set border 0

set view 60, 30, 1.1, 1.33

set pm3d scansbackward

splot cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with pm3d, \

      1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with pm3d

memoPicture028.jpg

.OK.


http://ayapin.film.s.dendai.ac.jp/~matuda/Gnuplot/Tips/tips.html


#gnuplot

      coef=.6

      x0=1.5

      q1=1

      q2=-1.5

#

      r(x,y)=sqrt(x*x+y*y)

      v1(x,y)=  q1/(r((x-x0),y))

      v2(x,y)=  q2/(r((x+x0),y))

#

      vtot(x,y)=v1(x,y)+v2(x,y)

#

      e1x(x,y)= q1*(x-x0)/r(x-x0,y)**3

      e1y(x,y)= q1*(y)/r(x-x0,y)**3

      e2x(x,y)= q2*(x+x0)/r(x+x0,y)**3

      e2y(x,y)= q2*(y)/r(x+x0,y)**3

      etotx(x,y)=e1x(x,y)+e2x(x,y)

      etoty(x,y)=e1y(x,y)+e2y(x,y)

      enorm(x,y)=sqrt(etotx(x,y)*etotx(x,y)+etoty(x,y)*etoty(x,y))

      dx1(x,y)=coef*etotx(x,y)/enorm(x,y)

      dy1(x,y)=coef*etoty(x,y)/enorm(x,y)

      dx2(x,y)=coef*etotx(x,y)

      dy2(x,y)=coef*etoty(x,y)

#

set xrange [-5:5]; set yrange [-5:5]; set cbrange[-4:4]

set isosamples 49,49

set view 0,0,1.7,1

set size square

red(gray) = atan(10*(gray-0.5))/pi + 0.5

set palette model RGB functions red(gray), 0 , 1-red(gray)

unset colorbox; unset key

unset xtics; unset ytics; unset ztics

###

set term table

set out "potential.dat"

splot vtot(x,y)

###

set contour

set cntrparam cubicspline

set cntrparam levels discrete -3,-2,-1,-0.5,-0.2,-0.1,0,0.1,0.2,0.5,1,2,3

unset surface

set out "contour.dat"

splot vtot(x,y) w lines


###

unset contour

set surface

set term png transparent

set out 'asym-dipole.png'

splot vtot(x,y) w pm3d,\

      "contour.dat" w lines lt 2,\

      "potential.dat" using 1:2:(0):(coef*dx1($1,$2)):(coef*dy1($1,$2)):(0)\

      every 3:3:0 w vec lt 7 lw 1

memoPicture029.jpg

.OK.


#gnuplot

set nokey

vsc=0.3

V0=20; th=pi/3;

V0x=V0*cos(th);

V0y=V0*sin(th);

g=9.8

vx(t)=V0x

vy(t)=V0y-g*t

x(t)=V0x*t

y(t)=V0y*t-0.5*g*t**2

tm=V0y*2/g

set parametric

set trange[0:tm]

set term table

set out "parabr.dat"

plot x(t),y(t)

set out "parabv.dat"

plot vx(t), vy(t)

!paste parabr.dat parabv.dat > parab.dat

set term png tiny size 320,240 transparent xffffff

set out 'parabolic.png'

plot "parab.dat" w lines lt 5,\

     "" every 10:1  using 1:2:($4*vsc):($5*vsc) w vector lw 3


memoPicture030.jpg