How do you define the representation of plots

navigation

General

  • Gnuplot is free software that can graphically display mathematical functions as well as data such as measured values ​​in a coordinate system
  • it is available for many operating systems
  • gnuplot is a command line oriented interactive tool
  • it is well suited for integration in scripts
Today we look at working on Linux. On Linux, gnuplot is started by calling / usr / bin / gnuplot started in the console, you get the gnuplot prompt gnuplot>

Basics

  • the gnuplot session is controlled by interactive text input
  • the graphical representation is sent to the X server by default
  • Command and function names are given in lower case letters
  • Variables and functions must start with a letter
  • the characters , : ; \ {} [] () have a fixed meaning
  • Comments begin with the pound #
  • Commands can extend over several lines, the last character must then be a \ (backslash)
  • several commands in one line must be separated by semicolons
  • multiple arguments within a command are separated by commas
  • the order of the options and arguments is usually fixed
  • saves the commands in a text file
  • or loads the commands from the text file and executes them immediately
  • Exit gnuplot with or
  • a command history is stored in the home directory
  • if there is a file in the home or working directory .gnuplot, the default settings in it will be loaded
  • You can get help on the commands with the command help.
help # general basics for working with gnuplot are displayed help set term # lists all options help commands # display of all commands help commands plot # help on command plot! Linux shell command! ls # lists the directory content! cat file.dat # content of the The file.dat file is displayed

Preferences

In principle, some predefined standard settings apply via the style of the illustration.
  • the first graphic is shown in red
  • the legend is placed in the upper right corner
    • the arguments are used as identifiers
    • the use of special characters depends on the terminal
  • the assignment of line types is defined
  • Standard value range x = [- 10.10]
Examples:
a simple 2D plot

Frame (border) all around
The scale division (tics) points inwards

splot [0: pi] [0: pi] sin (2 * x) + cos (x)
Surface plot of two functions

no frame
Interaction with the mouse and certain keys is possible
Grid representation of the surface

The valid settings are made with the command show displayed. show all # shows all settings as text test # graphic display of the settings
graphic display of the settings using test

Using the set -Commands can be numerous global settings to be hit.

set term # lists all available terminal types set output # can redirect the output, the default is the screen set style # specify a certain type of plot type set label # specify the position of the legend set xdata time # define the x-axis as the time axis set timefmt # Define time format ... The settings are canceled using unset, With reset you return to the standard settings.
Actions with the mouse are possible with some terminals - this is done when outputting test displayed.
help mouse set mouse # is on by default, if it is supported by the terminal. Furthermore, interactions with the keyboard can be defined. There are a number of preset combinations.
  • g - grid lines on / off
  • e - replot
  • b - turns on / off different reference lines
bind "keyboard shortcut" "gnuplot command (s)"

The plot command

The 2 basic commands for plotting a graph are plot for the 2D plot and splot for the 3D plot (surface plot).

2D plot - define functions and constants

  • A function can be passed to the plot command as an argument. The function can be defined before the plot command, but also within the plot command.
  • The independent variable should be named x. Other names for the independent variable can be specified using set dummy name1 be assigned. plot [min: max] # overwrites global settings (xrange, yrange) function | "File" axes # Information on the axes to be displayed title # Legend entry with # Style of the display
plot a = 1, a * x ** 2, a = 2, a * x ** 2 title "2nd function", a = 4.6, a * x ** 2 with linespoints
several functions in one plot, with given constants
plot g (x) = sin (x) * b * cos (x), b = 1, g (x) with impulses, b = 2, g (x) # Fig.plot g (x) = sin (x) * b * cos (x), b = 1, g (x) with impulses t "Function1", b = 2, g (x) t "Function2" # Legend is given a title
several functions in one plot, with different styles

2D plot - plot data sets, label axes

Measured values ​​that are listed in a file
  • ascii readable file
  • the values ​​can be in the permitted number formats or date and time formats
    • the point must be used as a decimal separator
  • each data point corresponds to one line
  • column-wise arrangement
  • Separators are spaces or the tabulator, this can also be redefined
  • the selection of the dates can be done via index, every, using, smoot being controlled
  • a defined arrangement of blank lines can subdivide a data file into data blocks and data records
  • Missing data points can be replaced by "" or 1/0, other characters can also be defined for empty entries
  • Data can be added by prepending ? be eliminated
Contents of the sample file
# Representation of data points set title "Measured values" set xdata time # x-axis is scaled in date / time format set timefmt "% H:% M:% S" # Format of the present date or time information set format x "% H:% M "# Format for the axis labeling set yrange [0:] # the y-axis starts at zero, upper limit automatically plot" perfmeter.log "using 2: 4 # column 2 is assigned to x, the y-values ​​are assigned to column 4 Taken from plot "perfmeter.log" using 2: 4 with impulses t "CPU values" # Representation of the values ​​using pulses, legend designation "CPU values" set tics out # Set axes to the outside set xlabel "minutes" # Designation of the x- Axis set ylabel "CPU outlet tung "# designation of the y-axis replot set xtics nomirror replot # no display of the axis division on the opposite side set ytics nomirror replot set border 3 # choice of the axes to be displayed plot" perfmeter.log "using 2: 4 with impulses t" CPU- Values ​​"# see Fig.
Plot of measurement data in a time sequence

2D plot Plot multiple data sets, change axis formats

  • The 4 axes can be scaled independently of each other.
  • the intervals for x2 and y2 cannot be set locally, they must be defined globally
  • axes controls which axes are used to display the values
set border 15 # show all axes unset xtics # reset to the standard set xtics # set the axis division set y2label "LOAD behavior" # designation of the y2 axis set y2tics # set the axis division for y2 plot "perfmeter.log" using 2: 4 with impulses t "CPU values", "perfmeter.log" using 2:10 with impulses t "LOAD" # see fig. Plot "perfmeter.log" using 2: 4 with impulses t "CPU values", "perfmeter .log "using 2: ($ 10 * 10) with impulses t" LOAD "
Plot of several measurement data in a diagram in a time sequence
plot "perfmeter.log" using 2: 4 with points t "CPU values", "perfmeter.log" using 2:10 with boxes t "LOAD" axes x1y2 # see Fig.
Plot of several measurement data in one diagram with separate Y-axes
set key top left # place the legend at the top left set key box # draw a frame around the legend plot "perfmeter.log" using 2: 4 with points t "CPU values", "perfmeter.log" using 2:10 with boxes t "LOAD" axes x1y2
Plot of several measurement data in one diagram with separate Y-axes and newly placed legend

3D plot of data sets

  • the syntax is largely the same too plot
  • multiple axis systems cannot be used
  • The standard is to connect the points with lines or grids
  • since version 4, the area can be accessed by pm3d can be displayed with a color or grayscale gradient.
Grid representation
splot "3d.dat" t "3D Plot" with lines
3D plot of measured values ​​in the standard display
Representation through color gradients
set pm3d # coloring the surface set title "3D Plot"; splot "3d.dat" t "3D Plot" # several commands in one line
Coloring the surface with a color or grayscale gradient
another example - Content of the sample file
clear # clear output window splot "3d1.dat" t "3D Plot" with lines
3D plot of measured values, line display
set pm3d splot "3d1.dat" t "3D Plot" with lines
3D plot of measured values, area display
Contents of the sample file
splot "3d2.dat" t "3D Plot" with lines
3D plot of measured values, line display using a different block structure of the measured data

3D plot with irregularly distributed data points

If Gnuplot is to display irregularly distributed data points, the gaps in the data point distribution should first be closed by interpolation.
The command is used for this set dgrid3dwhich creates regular grid points. The parameters are the number of desired intervals in the x and y directions and a weighting factor. Contents of the sample file
unset pm3d set hidden3d # hide hidden lines set dgrid3d 20,20,3 # create regular grid points splot '3d3.dat' with lines
Interpolation of missing grid points

3D plot of a function

  • With hidden3d hidden parts of the surface are not displayed, the top and bottom are given different colors
  • Contours can be drawn on the surface, which can be projected onto the base area
    • a contour runs along a fixed z-value (contour line)
  • the global option isosamples determines the density of the grid
f1 (x, y) = x ** 2 + y ** 2 f2 (x, y) = x ** 2-y ** 2 splot f1 (x, y), f2 (x, y)
Representation of two 3D functions in one plot
set hidden3d # hide hidden edges set contour both # Draw the contour on the surface and in the xy plane splot x ** 2 + y ** 2
3D function with plot of the contours of certain Z-values
Coloring the surface with a color or grayscale gradient
set isosamples 30 # Refine the grid lines splot x ** 2 + y ** 2
Refine the density of the gridlines
set pm3d map # projection in the xy plane with gradient splot x ** 2 + y ** 2 # Fig. set size square # square shape of the projection in the xy plane replot
Projection into the xy plane

Parametric representations

Curves in parameter representation: Standard variables: t (plot) and u, v (splot)
set parametric plot cos (t), sin (t) lw 2 plot cos (t), sin (t) lw 2, 0.5 * cos (t), sin (t) lt -1
Parametric representation
set key outside top replot
Legend outside of the representation

Multiplots

Representation of several plots one above the other or side by side:
set multiplot # start multiplot set size x.x, y.y # size of the plots set origin x.x, y.y # positioning (lower left corner)
set multiplot set size 0.5,1.0 set origin 0.0,0.0 p x ** 2 # p - Abbreviation for plot set origin 0.5,0.0 p x ** 3 unset multiplot
Representation of several plots

Notes on use in batch processing

reread - Parameters can be set again print - Issue of communications Break - Interruption of the program sequence if then else - Constructs can be used to control the process call "File" p1 .. p9 - parameter transfer possible (extension of load)

Example: 3D animation of a parametric function

set parametric set hidden3d unset title unset key unset xtics unset ytics unset ztics set border 0 set isosamples 50,10 set urange [-pi / 2: pi / 2] set vrange [0: 2 * pi] splot cos (u) * cos (v), cos (u) * sin (v), sin (u)
parametric function
Contents of the command file for generating the animation

Further processing of the graphic

The output format, which using terminal can be compared to a special driver. When the program starts, the terminal suitable for the operating system is usually called.
A wide variety of terminals have been written for gnuplot in recent years.
set terminal postscript # set postscript for output set output "file.ps" # name of the PS file replot
set terminal postscript eps set output "file.eps" replot set terminal png ...
set terminal kyo # printer terminals, here for output on Kyocera printers
set table "outfile.dat" # Creation of an ASCII file with the displayed data points replot # Interpolation results and contours can be exported

miscellaneous

set size 0.8,0.8 # change the size of the display gnuplot -persist messd.plt # -persistent - plot window stops gnuplot> load "messd.plt" # * pause -1 * at the end means that the output window is retained chmod + x messd .plt; ./messd.plt