https://www.ibm.com/developerworks/cn/linux/l-gnuplot/index.html
http://blog.sciencenet.cn/blog-373392-527507.html
http://blog.sciencenet.cn/blog-373392-529904.html
The syntax is unified: by typing help <command>
can help any command. Then start gnuplot, try the command help set yrange
and help set
(after each command, use q
exit help). Note yrange
that help set
one of the available sub-options under.
At the prompt, enter plot sin(x)
: You should see the familiar sine curve in the pop-up window.
set xrange [-pi:pi]
replot
reset
replot
Command, it performs the previous plot command. When you draw a diagram and need to constantly be modified to add features to the map you want, this command will be very useful. In addition, replot lets you add more diagram. Try to enter
replot cos(x)
. Syntactically, it is equivalent to the command
plot sin(x), cos(x)
. Replot is previously acquired drawing string, add the necessary comma, and then the additional input to the rest of it.
set title "My first graph"
set xlabel "Angle, \n in degrees"
set ylabel "sin(angle)"
plot sin(x)
Now, we note that the x-axis is not actually marked degree, it does not look very good. To modify the problem by adjusting the x-axis tic marks the designated (primary) markers only mark 90 and a secondary increase at 45 degrees increase. Tics of the main "level" is 0, which is the default value; tics of a secondary level. Each points are specified by a 3-tuple: "label"
(in quotes), <point-at-which-tic-is-made>
and <optional-level>
.
1
2
3
4
5
6
7
8
9
|
set xrange [-pi:pi] # we want only one cycle
set xtics ("0" 0, \
"90" pi/2, "-90" -pi/2, \
"" pi/4 1, "" -pi/4 1, \
"" 3*pi/4 1, "" -3*pi/4 1)
set grid
set xlabel "Angle,\n in degrees"
set ylabel "sin(angle)"
plot sin(x)
|
FIG 4. sin (x) axis with tics, title, and the grid tag
xtics
command function is very large, with a convenient option for fixed increments to create tic marks (on a logarithmic scale for normal multiples) special format, as well as for time-related data. View
help set xtics
the examples for more information.
Terminal equipment - digression
At startup, you may notice that the terminal type set X11
. Gnuplot standard design, you can draw on a plurality of terminal devices. This includes print directly to a variety of printers, including Epson, HP and Imagen printer. It can even draw the dummy devices, such as postscript and png. This mainly involves generating an output file instead of the file can be viewed or printed. This is a skill your chart included in other reports. Although I have not found any different in Linux in Windows, the documentation recommends that you set the terminal type before setting the output file name:
4. Listing and set the output terminal type
1
2
3
4
|
set terminal png # gnuplot recommends setting terminal before output
set output "output.png" # The output filename; to be set after setting
# terminal
replot
|
Now, the file output.png you just have to draw the map, and can be included in a larger report. Many layout and mapping procedures commonly used has a dedicated terminal, these procedures include Illustrator Adobe set term aifm
( ), Corel Draw set term corel
( ), AutoCad ( set term dxf
) and a variety of related LaTex terminal eepic
( latex
, pstricks
, texdraw
, , tpic
etc.). You can also get PostScript, enhanced PostScript (eps) or Adobe PDF format. Your version of gnuplot may not compile all terminal drivers - for example, Windows users do not need Xll terminal, Linux users do not need Windows terminal. Similarly, for legal reasons, gnuplot 4.0 removed support for gif terminal.
All terminals are not the same in their ability. Some of these (such as LaTeX) rotation may not support the text, so if you set ylabel as we did earlier, different terminals may appear different. In other words, you can use LaTex LaTeX commands in a specific terminal in. For example, set ylabel "$sin(\\theta)$"
(note that we use two backslash produce a desired LaTex backslash - gnuplot prior to transferring the enclosed double quotes strings to a terminal driver, its first backslash process). Now you can use \input{output.tex}
the output file is included in LaTeX file. To obtain the same results in PostScript terminal using the corresponding PostScript commands: {/Symbol q}
. In the enhanced PostScript and LaTeX, you can use the notation x^{superscript}
and x_{subscript}
get superscript text. Also note that abbreviations and output terminal command:
Ability Listing 5. eps driver
1
2
3
4
5
6
|
set term post enh # enhanced PostScript, essentially PostScript
# with bounding boxes
set out 'gplt.eps'
set xlabel '{/Symbol q_1}
set ylabel 'sin^2({/Symbol q_1})'
plot sin(x)**2
|
Reference Code supplement contains a sample portion of a file having the above commands TeX.
Mouse Support
Version 4.0 provides new features, Windows and X11 terminals support mouse interaction. Mouse support has two main purposes: coordinate tracking and zooming. The current coordinates of the mouse pointer displayed in the lower left corner of the terminal window. You can be copied by double-clicking on a mouse button to the Clipboard. When you need to set up a direct need to coordinate the label or arrow, this will be very useful. (Use help arrow
and help label
more detailed information on these commands available.) May also drag the second (or right) mouse button to select the rectangular area to be enlarged. In 3D graphics, you can drag the mouse to rotate the image (hold down the Ctrl key changes only the axis of view; for so it takes a long time to render the map, you can change the axis, and then release the Ctrl key to re-render Figure).
鼠标支持还支持一组有用的热键:如果先前对图进行了放大, u则取消访大。 g切换网格, l切换坐标轴上的刻度; L切换最靠近指针的最标轴上的刻度, r切换标尺,标尺会建立任意原点。启用了标尺后,屏幕的底部显示当前坐标指针距离标尺原点的 x 轴距离和 y 轴距离以及距离实际原点的 x 轴和 y 轴距离(与点的坐标相同)。在 3D 中,方向键可以用在鼠标拖拉的地方来旋转图像。空格键激活命令窗口, q退出终端窗口。要查看所有选项,在支持鼠标的终端中输入 h。
控制比例和长宽比
默认情况下,gnuplot 对 x 轴和 y 轴都使用比例系数 1,但是它对控制图形的长宽比(y 轴长度与 x 轴长度的比率)不起作用。终端驱动程序使用终端的默认长宽比。比例系数、长宽比或者两者都可以使用 set size
命令指定,例如:
# square is synonymous to an aspect ratio of 1;
# scale y-axis by 2, retain x-axis size
set size ratio square 1,2
gnuplot 使用给定的长宽比能否成功绘制图可能受到终端能力的限制。 set size
也是与 multiplot
命令一起使用才有用,multiplot 命令用于在同一输出屏幕或文件中生成多个图。
绘制多条曲线
正如精明的读者可能已经从上面关于 replot 的注释中推测到的,gnuplot 使您可以同时画多条线。假设我们同时绘制正弦和余弦曲线。简单的 plot 命令为 plot sin(x), cos(x)
;要画的曲线以逗号分隔。如果不再指定其他项,gnuplot 自动显示两个曲线图,从而它们可以互相区别 —— 在诸如 Windows 和 Xll 的终端中,gnuplot 使用不同的颜色。单色终端使用不同种类的线显示曲线图。通过查看图例(或键),您应该能够知道图中的线分别是何种曲线。gnuplot 还允许您指定绘图的样式,以便获得进一步的控制:
unset xtics # keep all other things simple
plot sin(x) with linespoints pointtype 5, cos(x) w boxes lt 4
图 5. 多条曲线
with
子句(请参阅 help plot with
,如果使用版本 4.0,还有 help plotting styles
)使您可以详细而精确地指定线的样式。在本例中,我们说明两种有用的样式。第一种样式 linespoints
通常在对数据绘图时非常有用,它在涉及的每个示例或数据点处标记一个点,并使用线性插值法连接连续的点。这里我们另外指定点类型为 5,它选择终端允许的第五种点。第二种样式 boxes
更适合绘制直方图数据。注意我们如何在 cos(x) 曲线中将 with
缩写成 w
。类似地, lt
是 linetype 的缩写,是另一个特定于终端的设置,它选择终端可以绘制的四种线。不必说(什么,您还没有尝试 help plot with
吗?),您可以使用 pt
代替冗长的 pointtype。如果想在多条线中使用相同的绘图样式(在一个 plot 命令中或在多个 plot 命令中),可以使用 set 命令设置绘图样式。在 gnuplot 4.0 中,使用 set style function linespoints
;以前的版本使用语法 set function style boxes
。要更改用于绘制与函数相对的数据集合的样式,使用 set style data linespoints
(以前的版本使用 set data style linespoints
)。
with
We use the clause is in addition to set
the first example than the other items to customize the map. Some other commonly used options can also be set directly in the plot command. For example, you may be provided plot [-pi:pi] sin(x)
xrange: . Quick and casual one-time option to change the default mapping of the use of such syntax. To reuse a plurality or in a plurality of FIG plot command is necessary to use set
the command.
When drawing two or more curves, we need to distinguish key or legend them. By default, the keyword in the upper right corner; but if it prevents the map, you can keywords to another location - If you prefer, you can even put outside the plot. The following code fragment keywords in the upper left corner, and sets a frame around it. We also control the legend name for the curve in the plot provided by the command given clear title. title may be abbreviated as t , as we set a cosine curve. If you do not want to name in the legend curves, use notitle
instead title
. Finally, and new users often go wrong is if there is a title, the title must be placed in with
front of the clause: