Showing posts with label gnuplot. Show all posts
Showing posts with label gnuplot. Show all posts

Tuesday, 3 July 2018

Dash it all: Custom line styles

Lines in gnuplot can come in different styles;  solid lines, dashed lines, or dotted lines, for example.  Probably the easiest way to set these is to use the dashtype pattern specifier, in gnuplot 5 and above.  The gnuplot help guide says:

       dashtype "pattern"  # string containing a combination of the characters
                           # dot (.) hyphen (-) underscore(_) and space.

and some examples are shown below:


set term pdfcairo font "Chalkduster,15"
set out 'dashes.pdf'
set key samplen 12 opaque box
PI = acos(-1.)
set xrange [0:2*PI]
plot sin(x) dashtype '-' lw 3 t 'Sin(x)', \
  sin(2*x) dashtype '.' lw 3 t 'Sin(2x)', \
  sin(3*x) dashtype '. -   _' lw 3 t 'Sin(3x)', \
0 not

Here we set up a pdf output, with a somewhat silly choice of font -- and one that I checked existed on my system.  I set up the key to include a very long length line in the legend, because I am making up an example with a complicated dash type.

The plot line plots the functions sin(nx), n=1,2,3 and assigns each a different dash type:  '-', '.' and '. -  _'for dashes, dots, and a more complicated pattern.  The results are shown below:


Friday, 19 February 2016

A pm3d surface plot

Here is a quick example of visualising a function of two variables using the pm3d "palette-mapped" 3d plot.  It comes from a module I teach on computational techniques and is the end result of a solution of the Laplace equation for the electrical potential, in a square region in which the potential along the upper boundary of the square is held at +100V and is 0V along the other boundaries.  The data, in the file pot.dat, is here.
# set up the terminal to be the interactive wxt display, 
# but with equal width and height
set term wxt size 400,400

# we will be plotting a function of two variables, but we 
# don't want the default surface plot
unset surface

# view from above
set view 0,90

# set the coloured "pm3d" plot (rather than the surface, 
# which we unset above)
set pm3d

# viewing from above, we don't want to have the z-axis
# tick marks shown all bunched up
unset ztics

# now plot, with a title
splot 'pot.dat' title "Potential"
The result, loaded into gnuplot with a load './pot.gpl' command is shown below:


It's not perfect.  With a bit of tweaking with placement, the title could be centrally above the square of the plot and the whitespace more even in the frame, but it visualises the potential quite well.