Gnuplot tips from http://hi.baidu.com/tsuihan/blog/item/eca435a8e386b4b0ca130c7b.html
Usage tips of gnuplot
1. Output Format
Gnuplot> set terminal X11 % output to the screen (Linux)
Gnuplot> set terminal postscript portrait noenhanced monochrome blacktext \
Dashed dashlength 1.0 linewidth 1.0 defaultplex \
Palfuncparam 2000, 0.003 \
Butt "Helvetica" 14'
Gnuplot> set output "test. Ps" % output to the PS file for insertion into the latex file.
Gnuplot> set terminal PNG small color picsize 640
Gnuplot> set output "test.png" % output to the image file for insertion into the HTML file. 2. basic Drawing command gnuplot> plot "test2d. dat "with lines % plot the graph (two-dimensional graph)
Gnuplot> splot "test3d. dat" with lines % draw a curved surface (3D)
The data in test2d. dat is two columns. The first column corresponds to the abscissa, and the second column is the ordinate column (function value)
The data in test3d. dat is three columns, the first and second columns correspond to coordinates, and the third column is the vertical coordinates (function value ),
For example:
X1 Y1 z11
X1 Y2 z12
X1 Y3 z13
// Empty row!
X2 Y1 z11
X2 Y2 z12
X2 Y3 z13
// Empty row!
X3 Y1 z11
X3 Y2 z12
X3 Y3 z13
Gnuplot> unset surface % do not draw a surface map
Gnuplot> set contour % plot the isoplot
Gnuplot> set cntrparam levels discrete. 9%/exp (1),. Custom Contour
Gnuplot> set cntrparam levels Auto 5
Gnuplot> set view. File-related gnuplot Official Website
Gnuconvf gallery4. some examples ### 1
Set hidden3d; Set ticslevel 0; Set parametric
Set isosamples 28, 14
Set urange [0: 2 * Pi]; Set vrange [-Pi: Pi]
Set size 0.8, 1; set view
Set ticslevel 0
Splot cos (u) +. 5 * Cos (u) * Cos (V), sin (u) +. 5 * sin (u) * Cos (V ),. 5 * sin (V ),\
1 + cos (u) +. 5 * Cos (u) * Cos (V ),. 5 * sin (V), sin (u) +. 5 * sin (u) * Cos (V)
Set term table
Set out "Tori. Table"
Replot
! Gnuconvf-S 200-I Tori. Table-O Tori. PPM-r 0.85-x50-Y-100-z50
! Convert-transparency black Tori. ppm tori.jpg ### 2
Set samples 36
Set isosample 36,36
Set hidden3d
Set ticslevel 0
Splot sin (x) * sin (y)/x/y
Set term table
Set output "3dsurf. Table"
Replot
! Gnuconvf-S 200-I 3dsurf. Table-O 3dsurf_p.ppm
! Display./3dsurf_p.ppm
! Gnuconvf-S 200-I 3dsurf. Table-O 3dsurf_f.ppm-F
! Display./3dsurf_f.ppm
! Gnuconvf-S 200-I 3dsurf. Table-O 3dsurf_l.ppm-l
! Display./3dsurf_l.ppm ### 3
Set hidden3d; Set ticslevel 0
Set parametric; set samples 30; Set isosamples 30,30
Set ticslevel 0; set size 0.7, 1
Set urange [0: 3. 1 * Pi]; Set vrange [-Pi: Pi]
X (u, v) = u * (1 + 0.5 * Cos (V) * Cos (u)
Y (u, v) = 0.5 * u * sin (V)
Z (u, v) =-u * (1 + 0.5 * Cos (V) * sin (u)
Splot X (u, v), y (u, v), Z (u, v)
Set term table; set out "3dsurf. Table"
Replot
! Gnuconvf-S 200-I 3dsurf. Table-O 3dsurf7. PPM-c0.7, 0.6, 0.2
! Ppmchange black cadetblue 3dsurf7. ppm> shell. ppm
! Convert shell. ppm shell.jpg ### 4
Set parametric; Set hidden3d
Set vrange [0: 2 * Pi]
Set isosamples 31,31; Set ticslevel 0
A = 1.0; B = 4.0; U0 = atan (A/B)
Set urange [0: U0 * 3]
R (u) = u <U0? B * Tan (u):
X (u, v) = R (u) * Cos (V)
Y (u, v) = R (u) * sin (V)
Z (u) = u <U0? B: A/TAN (u)
Splot X (u, v), y (u, v), Z (u)
Set term table
Set out "cylinder1.table"
Replot
! Gnuconvf-I cylinder1.table-O cylinder1_cnv.ppm-F-X80-Y-80 \
-C0.0, 0.7, 0.7-g-S 200
! Convert cylinder1_cnv.ppm cylinder1_cnv.jpeg
! Display cylinder1_cnv.jpeg
----------------------------------------------------
Gnuplot usage skills
I. Basics:
When running gnuplot, enter quit, Q, or exit to exit.
2. Draw multiple curves at the same time
Gnuplot> plot sin (x) Title 'sin (x) ''w l LT 1 LW 2, cos (x) Title 'cos (X) 'W l lt 2 LW 2% two curves are separated by commas. Multiple curves are separated by commas.
In the above example, we plot the function. If we plot the data file, replace the function name with the data file name, but it should be caused by single quotation marks.
3. Legend location
The default position is in the upper right corner.
Place gnuplot> set key left % on the left, with left and right options
Place gnuplot> set key bottom % below. Only this option is available. The default setting is above.
Gnuplot> set key outside % is placed outside, but only on the right.
The preceding three options can be combined. For example:
Gnuplot> set key left bottom % indicates the left bottom edge
You can also use coordinates to accurately represent the legend position, as shown in figure
Gnuplot> set key 0.5, 0.6% place the legend in the positions of 0.5, 0.6
4. Axis
Gnuplot> set xlabel 'X' % x axis marked as 'X'
Gnuplot> set ylabel 'y' % Y axis marked as 'y'
Gnuplot> set ylabel 'dos 'TC lt 3% where TC lt 3 indicates the third color of 'dos.
Gnuplot> set xtics 1.0% X axis master Scale Width is 1.0, you can also define ytics for the Y axis
Gnuplot> set mxtics 3% draws three scores for each master scale on the X axis. You can also define mytics for the Y axis.
Gnuplot> set border 3 lt 3 LW 2% is set as the third boundary, color type is 3, line width is 2
You can also set the X axis (X2) and Y axis (Y2) on the right, that is, x2tics, mx2tics, y2tics, and my2tics.
Gnuplot> set xtics nomirror
Gnuplot> unset x2tics % the above two commands remove the scale of the above X2 axis
Gnuplot> set ytics nomirror
Gnuplot> unset y2tics % the above two commands remove the scale of the right Y axis
5. Insert text into the Graph
Gnuplot> set label 'sin (x) 'at 0.5, 0.5% Add the string 'sin (x)' to the coordinate (0.5, 0.5 )'.
When the output is a. ps or. EPS file, if enhanced is added to the set term statement, the upper and lower mark, Greek letter, and special symbol can be inserted. The method for inserting the upper and lower mark is the same as that in latex.
6. Add a line and an arrow to the graph.
Gnuplot> set arrow from 0.0, 0.0 to 0.6, 0.8% draw an arrow from (0.0, 0.0) to (0.6, 0.8)
Gnuplot> set arrow from 0.0, 0.0 to 0.6, 0.8 lt 3 LW 2% the arrow color type is 3, the line width type is 2
Gnuplot> set arrow from 0.0, 0.0 to 0.6, 0.8 nohead lt 3 LW 2% use nohead to remove the head of the arrow. This is the method for adding a straight line.
Note: In gnuplot, for inserting Multiple labels and arrow, the system will number each label or arrow in sequence by default, starting from 1. If you want to remove a label or arrow in the future, you only need to use the unset command to remove the label or arrow. For example:
Gnuplot> unset Arrow 2
The second arrow is removed.
7. Graph size and position
Gnuplot> set size 0.5, 0.5% long and width are half of the default width. We recommend that you use this value, especially when drawing a PS or EPS image.
Gnuplot> set origin 0.0, 0.5% sets the position of the bottom left corner of the graph in the graphic panel. The figure appears in the upper left corner.
8. Draw 3D images
Gnuplot> splot 'file name 'U % takes the second and fourth columns as the X and Y coordinates, and the fifth column is the zcoordinate.
9. output the image to a file
In gnuplot, the output file format is controlled by terminal. By default, all are output to the screen, that is, the terminal mode is X11. If you want to output data to a file, you must set terminal. To understand the terminal types, enter set terminal and press Enter. All supported terminal modes (or file formats) are listed. For me, the most common output file formats are PS and EPS files. Before running the drawing command plot or splot, run the following two commands:
Gnuplot> set term post EPS color solid ENH
Gnuplot> set output 'a. ss'
The first command sets the terminal mode, and the Post mode is the postscript mode, which is required for output to PS or EPS files. The following EPS, color, solid, and ENH options can all have or do not exist, depending on your needs. EPS indicates that the output file is an EPS file, and the output file is a PS file if it is not. color indicates that the output image is color and will be saved as black and white if it is not needed. Solid indicates that all cables in the output image are solid wires, no, except for the first line, different dotted lines are used. The ENH (enhanced) option can be used to insert upper and lower labels, Greek letters, and special characters, if you do not need it, you cannot implement these functions. You can select one or more options based on your needs.
The second command sets output to indicate the name of the file to be output. However, after running this command, you only define the name of the output file. In fact, the figure is not shown in this file. Therefore, only necessary settings are required to run these two commands. Run the following command:
Gnuplot> plot sin (x) W L
Or
Gnuplot> replot (if you have run the plot or replot command before)
Then, the image is in the file specified above.
To output the image in other formats, you must also set the image format. For example, to output the image in JPG format, run the following command before running the drawing command:
Gnuplot> set term JPEG
Gnuplot> set output 'a.jpg'
If you want to return the output to the screen in other modes, run the following command:
Gnuplot> set term X11
Ii. improvement:
1. How to draw multiple images at the same time in the same region
Gnuplot> set multiplot % to multi-graph Mode
Gnuplot> set origin 0.0, 0.5% set the origin position of the first graph
Gnuplot> set size 0.5, 0.5% set the size of the first graph
Gnuplot> plot 'a1. dat'
Gnuplot> set origin 0.5, 0.5% set the origin position of the second graph
Gnuplot> set size 0.5, 0.5% set the size of the second image
Gnuplot> plot 'a2. dat'
Gnuplot> set origin 0.0, 0.0% set the origin position of the Third Graph
Gnuplot> set size 0.5, 0.5% set the size of the third Graph
Gnuplot> plot 'a3. dat'
Gnuplot> set origin 0.5, 0.0% set the origin position of the fourth Graph
Gnuplot> set size 0.5, 0.5% set the size of the fourth Graph
Gnuplot> plot 'a4. dat'
Of course, if the setting of a quantity in the next graph is the same as that in the previous graph, the setting of this quantity in the next graph can be omitted. For example, you can set the size of the second, third, and fourth graphs. The setting of a certain amount in the previous graph also takes effect in the next graph. If you want to cancel the function in the following figure, you must use the following command, for example, to cancel the label, use
Gnuplot> unset label
2. How to keep the unit length of the coordinate axes on both sides of a two-dimensional graph?
Gnuplot> set size square % make the image Square
Gnuplot> set size 0.5, 0.5% make the image the size you want
Gnuplot> set xrange [-A: A]
Gnuplot> set yrange [-A: A] % the scale range of the two axes is the same
Gnuplot> plot 'a. dat'
3. How to draw images using the Y axes on both sides of the same worker
Gnuplot> set xtics nomirror % remove the scale of the X 2 coordinate axis above
Gnuplot> set ytics nomirror % remove the scale of the right axis Y2
Gnuplot> set x2tics % to automatically generate the X2 scale of the preceding coordinate axis
Gnuplot> set y2tics % to automatically generate the scale of Y2 on the right axis
Gnuplot> plot sin (x), cos (x) axes x1y2 % cos (x) use the x1y2 coordinate, and axes x1y2 represents the x1y2 coordinate axis
Gnuplot> plot sin (x), cos (x) axes x2y2 % cos (x) are in the x2y2 coordinate, and axes x2y2 is in the x2y2 coordinate axis.
Gnuplot> set x2range [-20:20] % to set the range of X2 coordinates
Gnuplot> replot
Gnuplot> set xrange [-5:5] % to set the range of X coordinates
Gnuplot> replot
Gnuplot> set xlabel 'X'
Gnuplot> set x2label 'T'
Gnuplot> set ylabel 'y'
Gnuplot> set y2label's'
Gnuplot> replot
Gnuplot> set title 'The figure'
Gnuplot> replot
Gnuplot> set x2label 't'textcolor lt 3% textcolor lt 3 or TC lt 3 set the coordinate axis name color
4. How to insert Greek letters and special characters
Generally, the enhanced option can only be specified in the PS and EPS charts. Cannot be displayed on the X11 terminal (Display.
Gnuplot> set terminal postscript enhanced
Then the Greek letter can be entered through {/symbol. For example
Gnuplot> set label 'symbol }'
For the input methods of various Greek letters and special symbols, see the ps_guide.ps file under the gnuplot-4.0.0/docs/psdoc directory in the installation package.
For more information, see:
5. How to insert the Angstrom (e) symbol in gnuplot (a small circle above)
In the script, add
Gnuplot> set encoding iso_8859_1
This command can then be added through "{\ 305. If the abscissa is to be labeled as "K (1/second )":
Gnuplot> set xlabel 'K (1/{\ 305 })
In the multiplot mode, the command must be placed in
Gnuplot> set multiplot
.
If you want to insert other escape characters, add the following command after the characters are inserted:
Set encoding default
'E' in the table in the gnuplot-4.0.0/docs/psdoc/ps_guide.ps file in the installation package indicates that all symbols in that column are input using this method.
6. Draw a contour map using gnuplot
Gnuplot> splot 'file name. dat 'U w l % 3D Graph
Gnuplot> set dgrid3d 100,100% set the number of grids on the 3D chart.
Gnuplot> replot
Gnuplot> set contour % set to draw contour lines
Gnuplot> set cntrparam levels incremental-0.2, 0.01, 0.2% set the density and range of the contour lines, and draw a line every 0.2 between-0.2 and 0.01.
Gnuplot> unset surface removes the 3D image above
Finally, drag the image with the mouse and select a reasonable angle. Or you can directly set the angle of view (0, 0:
Gnuplot> set view 0, 0
Gnuplot> replot
Note that the data file for 3D Graph painting must be segmented, that is, each time x changes a value, y changes within the range of change for one week. In this case, take another X value, Y is changed for another week as the next data block, and so on. Use an empty row to split the block.
7. How to draw beautiful pm3d Images
Gnuplot> set pm3d % set pm3d Mode
Gnuplot> set isosamples 50, 50% Set grid points
Gnuplot> splot x ** 2 + y ** 2% 3D Graph
Gnuplot> splot x ** 2 + y ** 2 W pm3d % is painted in pm3d mode. Pay attention to the changes.
Gnuplot> set View sets the angle of view, (0, 0) will be projected to the end
Gnuplot> splot x ** 2 + y ** 2 W pm3d % re-painting, pay attention to the changes
Gnuplot> unset ztics % remove the number on the Z axis
Gnuplot> set isosamples 200,200% to fine-tune the grid
Gnuplot> replot % re-painting. Pay attention to the changes, mainly because the transition is smoother.
8. Avoid Repeated input using script files
Sometimes, after creating a chart for a data file, you may need to plot it next time, but some or some settings need to be slightly changed. At this time, you can write all the commands for the first drawing into a file, such as. PLT. After modifying the corresponding settings, the following command will automatically run all the commands in the file and finally get the graph you want:
Gnuplot> load 'a. PLT'
For example, if the file name is A. PLT, the content in the file is:
Set pm3d
Set view 0, 0
Unset ztics
Set isosamples 200,200
Splot x ** 2 + y ** 2 W pm3d
Set term post color
Set output 'a. Ps'
Replot
After starting gnuplot, you only need to run the following command:
Gnuplot> load 'a. PLT'
If you want to obtain only the. ps or. EPS graph, you can also directly run the following command at the Linux Command Prompt:
[Zxh @ theory zxh] $ gnuplot A. PLT
9. run Linux commands in gnuplot Mode
You can run the Linux Command at the gnuplot prompt, but you must add it before the corresponding command! . For example, if many parameters have been set, but a data file a. dat needs to be modified before drawing, you can use the following method:
Gnuplot>! Vi a. dat
In this way, all Linux commands can be run in the gnuplot environment.
In addition, you can enter shell at the gnuplot prompt to temporarily exit gnuplot and enter the Linux environment. After you finish the task, run the exit command and return to the gnuplot environment.
Gnuplot> Shell
[Zxh @ theory zxh] $ vi a. f
[Zxh @ theory zxh] $ f77 a. f
[Zxh @ theory zxh] $ A. Out (assuming a. dat data file is generated)
[Zxh @ theory zxh] $ exit
Gnuplot> plot 'a. dat 'W L
--------------------------------------------------------------------------
Http://t16web.lanl.gov/Kawano/gnuplot/label-e.html#4.3
1. Plot command
Gnuplot> plot sin (x) with line linetype 3 linewidth 2 or
Gnuplot> plot sin (x) w l lt 3 LW 2% is drawn by line. The line type (including the color and dotted line type) is 3, and the line width is 2, graph the sin (x) Function
Gnuplot> plot sin (x) with point pointtype 3 pointsize 2 or
Gnuplot> plot sin (x) w p pt 3 Ps 2% point painting, the point type (including color and point type) is 3, the point size is 2
Gnuplot> plot sin (x) Title 'f (x) 'w lp lt 3 LW 2 PT 3 Ps 2% simultaneous point and Line Painting, Here title 'f (X) 'indicates that the legend is labeled 'f (x)'. If not, use the default option.
Gnuplot> plot sin (x) % all options use the default value. If one item is missing, the default value is used.
Gnuplot> plot 'a. dat 'U w l lt 3 LW 2% plot using the second and third columns in the data file a. dat
By the way, as shown in the first two examples, in gnuplot, if two words are in alphabetical order, the first few letters are the same and the latter are different, you only need to write the first different letter. For example, because there are no other words starting with W, W can be used instead of line or L.