Gnuplot Drawing II

Source: Internet
Author: User
Tags cos sin
For people working under Linux, if you often want to draw a number of two-dimensional and simple three-dimensional diagram, then, gnuplot is undoubtedly a very good choice, not only beautiful graphics, but also easy to operate. When
However, if you need a higher-quality three-dimensional diagram, please use some other professional graphics software. It is recommended that you learn to use gnuplot. This little software is usually redhat.
Linux has its own, but its own version is 3.7, it is recommended to upgrade to 4.0, the new version has many new features. The latest version can be
http://www.gnuplot.info/
Download.
One
Some of the most basic operation please read the instructions. Here to summarize some of the problems I encountered in the use of the process and the solution, the purpose is to let those who have not previously or unskilled to quickly get started, will draw their own
Figure, because the original manual is very long, more difficult to target quickly find the information you want. The simple summary here can't be exhaustive, so don't complain about my incomplete, more comprehensive understanding or please read it.
Ming Book, the information on the Internet is also many. In fact, this is what we collected from the Internet 1.1 points and groped out. I believe that after reading, should usually the most common problems can be found in the answer here. If everyone is making
Using the process to find I did not write the skills and experience, or have other suggestions, please tell me to continue to improve this summary, thank you.
first, the basic article:
Run the gnuplot command at the Linux command prompt and enter quit or Q or exit.
1, Plot command
gnuplot> plot sin (x) with line Linetype 3 LineWidth 2 or
gnuplot> plot sin (x) w L LT 3 lw 2 with a line drawing, the type of line (including the type of color and dotted line) is 3, the line width is 2, the function sin (x) is plotted
gnuplot> plot sin (x) with point Pointtype 3 pointsize 2 or
gnuplot> plot sin (x) W p PT 3 PS 2 with dots, the type of point (including the type of color and point) is 3, the point size is 2
gnuplot> plot sin (x) title ' F (x) ' W LP LT 3 LW 2 Pt 3 PS 2% with dots and lines at the same time, here title ' F (x) ' represents the legend superscript ' F (x) ', with default option if not used
gnuplot> plot sin (x)% all options are at this time with the default value. If an item is missing, the default value is used
gnuplot> plot ' a.dat ' u 2:3 w L LT 3 lw 2 drawing using the second and third columns in the data file A.dat
Incidentally, as shown in the first two examples here, in gnuplot, if a certain two words are the same in alphabetical order, the previous letters are the same, and the following are different, then you can just write a different letter. As with, because there are no other words that start with W, so you can use W instead, line can also be replaced with L.
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 The two curves are separated by commas. When you draw more than one curve, you can use commas to separate the curves.
In the above example, the function is plotted, if the data file is plotted, the function name can be changed to the data file name, but it should be enclosed in single quotes.
3, about the location of the legend
The default location is above the right.
Gnuplot> set key left% on the left-hand side, with leave and right two options
gnuplot> set key bottom% below, only this option; default on top
Gnuplot> set key outside on the outside, but only on the right.
The above three options can be combined. Such as:
Gnuplot> set key left bottom% indicates bottom left-hand
You can also use coordinates to accurately represent the position of the legend, as
Gnuplot> set key 0.5,0.6% place legend in 0.5,0.6 position
4. About Axes
Gnuplot> set Xlabel ' x '%x axis labeled ' x '
gnuplot> set Ylabel ' y '%y axis labeled ' y '
gnuplot> set Ylabel ' dos ' TC LT 3 where TC Lt 3 means ' dos ' colors in a third color.
The main scale of the gnuplot> set Xtics 1.0%x axis is 1.0, and can also be defined for the Y axis ytics
The gnuplot> set mxtics the 3 tick marks on each master scale on the 3%x axis, which can also be defined for the y-axis mytics
Gnuplot> Set Border 3 LT 3 LW 2 is set to a third boundary with a color type of 3 and a line width of 2
You can also set the top x axis (called X2) and the right y (called y2) axis, which is x2tics,mx2tics,y2tics,my2tics.
Gnuplot> Set Xtics nomirror
gnuplot> unset x2tics% above two commands remove the scale of the top X2 axis
Gnuplot> set Ytics nomirror
gnuplot> unset y2tics% above two commands remove the tick on the right Y axis
5, insert text in the diagram
gnuplot> set label ' sin (x) ' at 0.5,0.5% joins the string ' sin (x) ' at coordinates (0.5,0.5).
When the output is a. ps or. eps file, if the enhanced selection is added to the statement in set term, you can insert the superscript, Greek letters, and special symbols. The insertion and latex of the subscript are the same as in the method.
6. Add lines and arrows to the diagram
Gnuplot> set arrow from 0.0,0.0 to 0.6,0.8 the (0.0,0.0) to (0.6,0.8) draw an arrow
Gnuplot> set arrow from 0.0,0.0 to 0.6,0.8 LT 3 LW 2 This 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 uses Nohead to remove the head of the arrowhead, which is the way to add a line.
Note that in gnuplot, for inserting multiple labels and arrow, and so on, the system defaults to numbering each label or arrow separately, starting at 1. If you want to remove a label or arrow later, just use the unset command to remove the corresponding. Such as:
Gnuplot> unset Arrow 2
The second arrow will be removed.
7, the size and position of the figure
Gnuplot>set size 0.5,0.5% is half the default width, recommended for this value, especially when drawing into PS or EPS graphics
Gnuplot>set origin The position of the point in the graphics panel in the lower-left corner of the 0.0,0.5% set diagram. Here the diagram will appear in the upper-left corner.
8. Draw three-dimensional diagram
Gnuplot>splot ' filename ' u 2:4:5% in the second and fourth columns as x and y coordinates, and V as Z coordinates.
9. Output graphics to a file
In
In Gnuplot, the format of the output file is controlled by terminal. By default, all is output to the screen, that is, the terminal mode is X11. If you want to output to a file, you must
Terminal is set up. To learn about those terminal types, you can enter a set
Terminal after the carriage return, all supported terminal modes (or file formats) are listed. As far as I am concerned, the output file format is used most of the PS and EPS files. This is running the paint command
The following two commands must be run before plot or splot:
Gnuplot>set term post EPS color solid enh
Gnuplot>set output ' a.eps '
Its
The first command in the set terminal mode, post is PostScript mode, which is required for output to PS or EPS files. Behind the Eps,color,solid and
ENH options can be available or not, depending on your needs. EPS represents the output as an EPS file, no output as PS file; color indicates that the output graphic is colored and will not be saved in black and white
Solid indicates that all the lines in the output graph are solid, except that the first line is a solid line, and the others are dotted with different dashes; use the ENH (enhanced) option to insert the above
Subscript, Greek letters, and special symbols, which are not necessary to implement these functions. The following options can be selected according to your own needs or a few.
The second command represents the name of the file to be exported for the setting of output. Note, however, that after you run this command, you are simply defining the name of the output file, and in fact, the diagram has not been drawn to this file. So running these two commands is just the necessary setting. Then run the following command
Gnuplot>plot sin (x) w L
Or
Gnuplot>replot (if plot or Replot commands have been previously run)
At this point, the graphic is in the file specified above.
To output to another format, for example, to output to JPG, run the following command before running the paint command:
Gnuplot>set term JPEG
Gnuplot>set output ' a.jpg '
If you want to return the output to the screen by another mode, run the following command:
Gnuplot>set term X11
second, improve the article:

1. How to draw multiple graphs at the same time in the same
picture

Gnuplot>set Multiplot% set to multi-graph mode
Gnuplot>set Origin 0.0,0.5% sets the position of the origin of the first diagram
Gnuplot>set size 0.5,0.5% set first figure
Gnuplot>plot "A1.dat"
Gnuplot>set origin 0.5,0.5% set the position of the origin of the second diagram
Gnuplot>set size 0.5,0.5% set the second figure
Gnuplot>plot "A2.dat"
Gnuplot>set origin 0.0,0.0% set the position of the origin of the third diagram
Gnuplot>set size 0.5,0.5% set a third figure
Gnuplot>plot "A3.dat"
Gnuplot>set origin 0.5,0.0% set the position of the origin of the fourth diagram
Gnuplot>set size 0.5,0.5% set fourth figure
Gnuplot>plot "A4.dat"
Of course, if a certain amount in the latter figure is the same as the previous one, then the set of this amount in the latter one can be omitted. For example, the settings for the size of the second, third, and fourth graphs. The setting of a quantity in the previous diagram also works in the latter diagram. If you want to cancel the action in the later diagram, you must use the following command, such as canceling the label, using the
Gnuplot>unset Label
2, as a two-dimensional diagram, how to make both sides of the axis of the unit length and so long
gnuplot> set size square% so that the graphic is square
gnuplot> set size 0.5,0.5% make graphics the size you want
Gnuplot> Set XRANGE[-A:A]
gnuplot> set YRANGE[-A:A]% two axis scale range
gnuplot> plot ' A.dat '
3, how to use the same diagram in the left and right side of the Y axis paint
gnuplot> set xtics nomirror% to remove the scale of the above axis x2
gnuplot> set ytics nomirror% remove the tick on the right axis y2
Gnuplot> set X2tics% to make the above axis x2 scale automatically generated
Gnuplot> set Y2tics% automatically produces the scale of the right axis y2
gnuplot> plot sin (x), cos (x) axes x1y2%cos (x) with x1y2 coordinates, axes x1y2 representation with x1y2 axes
gnuplot> plot sin (x), cos (x) axes x2y2%cos (x) with x2y2 coordinates, axes x2y2 representation with x2y2 axes
gnuplot> set X2RANGE[-20:20]% sets the range of X2 coordinates
Gnuplot> Replot
gnuplot> set Xrange[-5:5]% sets the x-coordinate range
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 sets the color of the axis name
4. How to insert Greek letters and special symbols
Typically only in PS and EPs graphs, and you must specify the enhanced option. cannot be displayed in the X11 terminal (that is, the monitor).
Gnuplot> set Terminal PostScript enhanced then the Greek alphabet can be entered through {/symbol a}. For example
Gnuplot> set label ' {/symbol A} '
The input methods of various Greek letters and special symbols see the ps_guide.ps file in the Gnuplot-4.0.0/docs/psdoc directory in the installation package.
You can also see:
http://t16web.lanl.gov/Kawano/gnuplot/label-e.html#4.3
5. How to insert the symbol of Angstrom (gnuplot) (a small circle above)
In the script, join before inserting
Gnuplot>set encoding Iso_8859_1
This command, and then you can join by "{\305}". If the horizontal axis should be marked "K (1/?)" :
Gnuplot>set Xlabel ' K (1/{\305})
In the case of Multiplot mode, this command must be placed in the
Gnuplot>set Multiplot
The front.
If you want to insert another escape character later, add the following command after inserting the character:
Set encoding Default
The ' E ' in the table in the Gnuplot-4.0.0/docs/psdoc/ps_guide.ps file in the installation package represents all the symbols for that column in this method.
6, gnuplot drawing and other High Line drawings
Gnuplot>splot ' filename. dat ' u 1:2:3 w l% do three-dimensional diagram
Gnuplot>set Dgrid3d 100,100 Sets the number of meshes on the surface of a three-dimensional graph
Gnuplot>replot
Gnuplot>set Contour% Set drawing contour
Gnuplot>set cntrparam levels incremental-0.2,0.01,0.2% sets the density and range of contour lines, which draw a line every 0.01 from 0.2 to 0.2.
Gnuplot>unset surface Remove the three-dimensional graphics above
Finally use the mouse to drag the graphics, choose a reasonable angle can be. or the direct setting (0,0) perspective can also be:
Gnuplot>set View 0,0
Gnuplot>replot
Notice here that the data file for the three-dimensional graph must be divided, that is, x each change a value, y changes in the range of a week, so as a piece, and then take an x value, y again change a week, as the next block, and so on. Blocks and blocks are opened with a blank line.
7, how to draw a beautiful Pm3d map
Gnuplot> Set Pm3d% sets Pm3d mode
gnuplot> set isosamples 50,50% set grid point
Gnuplot> splot x**2+y**2% drawing three-dimensional picture
Gnuplot> splot x**2+y**2 w pm3d% painted into Pm3d mode, pay attention to comparative changes
gnuplot> set view 0,0% set view, (0,0) will be projected in the end face up
Gnuplot> Splot x**2+y**2 W Pm3d to repaint, pay attention to change
gnuplot> unset ztics% to remove the numbers on the z axis
Gnuplot> set Isosamples 200,200 to make the mesh thinner
gnuplot> Replot% Redraw, pay attention to change, mainly transition smoother
8, use the script file to avoid duplicate input
Sometimes when you make a picture of a data file, you may want to use the data file to draw the next time, but some or some settings need to be changed slightly. At this time, can be the first time when the drawing of the command all written to a file, such as A.PLT, as long as the appropriate settings to make changes, with the following command will automatically run the file all the commands and finally get the figure you want:
Gnuplot>load ' A.PLT '
As an example, suppose the file name is A.PLT and the contents are:
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 you start gnuplot, just run the following command:
Gnuplot>load ' A.PLT '
If we're going to get just. ps or. eps graphs, you can also run the following commands directly from the Linux command prompt:
[Zxh@theory Zxh] $gnuplot a.plt
9. Run Linux command in gnuplot mode
You can also run Linux commands at the gnuplot prompt, but you must precede the corresponding command! Resolution For example, suppose that many parameters have been set up, but you need to modify a data file A.dat and then paint, you can use the following method
Gnuplot>!vi A.dat
In this way, all Linux commands can be run in a gnuplot environment.
In addition, you can enter the shell after the gnuplot prompt, temporary exit gnuplot, into the Linux environment, finish what to do, run Exit command, and back to the gnuplot environment.
Gnuplot>shell
[Zxh@theory Zxh] $vi A.F
[Zxh@theory Zxh] $f A.F
[Zxh@theory Zxh] $a. Out (assuming the A.dat data file is generated)
[Zxh@theory Zxh] $exit
Gnuplot>plot ' A.dat ' w l






This article from the Chinaunix blog, if you view the original please point:Http://blog.chinaunix.net/u3/94593/showart_2002166.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.