Instructions for using gnuplot¶
annotation
For details, please check the documentation: gnuplot introductory tutorial and related documents. The official manual of gnuplot, the official website of gnuplot
-
Talk about the drawing mode of gnuplot
-
Overview
This stuff is completely based on the command line mode operation. There is no stuff like C setting structure. If you want to set multiple items, you need to set one command and one command. If you don't modify it, the previous settings will always be valid, so of course It is necessary to have a default configuration from the beginning.
In the default configuration of gnuplot, the axial selection will be made by itself, so that the graphics are as human-readable as possible. However, after automatic selection, the automatic selection may be invalid when drawing again. At this time, it is necessary to manually select a series of axis ranges, etc. It is set. Using the -e parameter will not have this problem, (starting a process again).
-
Common command line parameters
-e : The following string is the command line of gnuplot, for example: gnuplot -e 'set term png;set output "/tmp/a.png";plot sin(x);'
-c : The following parameter is a gnuplot script file.
-
gnuplot tablet shortcuts
a : (autoscale) display in original, 1:1 scale
[Mouse_Down/UP] : View the lower/upper chart.
Shift + [Mouse_Down/UP] : View right/left graph.
Ctrl + [Mouse_Down/UP] : Zoom out/enlarge the chart.
[Mouse_Mid] : View the coordinates of the position of the pointer and print it on the chart.
r : (regon) Display a cross coordinate line, which is convenient to check the corresponding position of the x and y axes to read the corresponding value, press r again to cancel the display
g : (grid) display grid, press again to cancel display
q : (quit) quit
-
-
How gnuplot plots.
-
Description
Use plot and splot to draw graphics, plot to draw 2d graphics, splot to draw 3d graphics, you can use replot and resplot to draw repeatedly on a graphic,
If you want to save it to a picture, you can use set term png|jpeg… to set the output format, the default is of course set term x11, which is to output to the default screen of x11 by default, after setting the format, set output, set output "file name" after Then splot|plot will draw to the specified file.
There are many similar setting methods, that is to say, this plot and splot are only commands to trigger drawing, the specific drawing method depends on what the previous settings are, and why is it not included in the settings for drawing 2d or 3d , this is because: gnuplot's 2d and 3d settings have nothing to do with drawing, but have something to do with the way the data is specified, because these two commands can use using to set the data used, so these two commands determine the drawing method, which The command determines the data, the command determines the drawing method , and the other is just the display method.
In the command script, use set auto to reset the automatic selection of xrange, yrange ranges.
-
plot and splot syntax
-
Basic usage
-
draw function
plot [xrange] {data on the y-axis, a function of x}, {second graph} For example: plot sin(x) If not specified, the default x is always equal to 0, xrange is optional, use [-pi:pi] This format is specified.
splot [xrange] [yrange] {z-axis data, a function about x, y}, {second} For example: splot sin(x*y); If not specified, the default is equal to 0
-
plot data
plot [xrange] [range] '{data file}' using a:b Use the data in the datafile to draw a 2d graph, a and b are numbers, the number of columns is calculated from 0, there is a 0 by default,
Column 0 represents the number of lines in the data file where the data is located. If you use the format of $2 $2, you can participate in the operation, but you must use () between each:. For example: plot 'datafile' using 1:($1+$2*$3)
-
-
draw graph summary
Roughly divided into two parts, the first part is separated by spaces , using the range specified by [] , followed by xrange, yrange, zrange, and the last data separated by spaces, start the graphics drawing instructions, you can use functions, or "or" beginning with Data files, each graph is used , split each , the graph description between each, can be described using with etc., and the data file is described using index using etc.
-
Graphic Data Options
Use with to describe the option format: with [cmd] args with can be abbreviated as w , for example: plot sin(x) with points pointtype 3, use point to draw, use 3 for the type of point, please check the official website for the specific type description Hey.
The relevant cmd is as follows:
with points pointtype n draws using points, the type is n. pointtype shorthand pt
with lines linetype n Use lines to draw, the type is n. linetype abbreviation lt
with boxes draws the numerical size as a box, which is used to draw a histogram.
-
-
-
Common commands
reset resets all settings.
print {statments} prints a numerical value, which can be used as a calculator. The syntax is basically the same as c (square is **), refer to
gnuplot operators and some functions, see gnuplot functions
set xdata|ydata time|… This is to set the way to parse the data in different axes. The default is float.
set timefmp “%Y%m%d%H%M%S” sets the time format in exactly the same way as the date setting.
set xrange [begin:end] sets the axial range: xrange can be yrange, zrange. For example, set xrange [-pi:pi] uses [:max] to specify the maximum value, and [min:] to specify the minimum value.
set auto Set to automatically select xrange, yrange according to the data size. When using, first set the corresponding range to [0:0]
set xlabel "String" Set the axis label of the axis, this is the displayed character. xlabel can be ylabel, zlabel
set title 'title' sets the title of the chart
set style function|data [linespoints] Set the style of the function or data
set key top left When drawing multiple curves, the position of the legend is set. This can prevent the legend from interfering with the chart. It can be determined that the legend is drawn after the chart is drawn. Position: top, bottom, left, right.
set key box draws a box around the legend.
set grid sets the display grid
set xtics ('label1' {num},'label2' {num2}) Set the coordinates of the x-axis, () is an array in the middle, to divide each element,
The first item is the display label, the second is the value of x. xticx can also be: ytics, ztics
set xtics auto restores the default axes
set xtics {start},{incr},{end} Set the coordinates to start at {start}, step {incr}, and end at {end}.
set format x "%3.3f cm" Set the format of the coordinates, the following format is the same as printf, only f, e, g must be less than 100 words, x can be
x, y, z, xy
show format shows the set format,
set view 0,0 set the viewing angle
unset XXX Cancels a setting.
unset ztics removes the numeric values of the z-axis.
Contour drawing
set dgrid3d 100,100 Set the number of surface networks for 3d graphics
set contour Set to draw contour lines, that is, to draw according to the cutting plane of the z-axis.
set cntrparam levels incremental -0.9,0.1,0.9 Set the range of contour lines, the z-axis starts at -0.9 and ends at 0.9, and draws every 0.1 height
unset surface removes the 3D graphics above
set view 0,0 sets the viewing angle, the center is at the position where x,y is 0,0.
unset key does not display the legend
splot … draws 3d graphics.
Surface graphics drawing
set pm3d set to enable surface graphics drawing
set isosamples 50,50 Set the adoption rate of the x,y axis
splot [add parameters after] 3d graphics drawing.