gunplot绘图

gnuplot,轻量级画图神器。放上*的解释:gnuplot是一套跨平台的数学绘图*软件。使用交互式接口,可以绘制数学函数图形,也可以从纯文字档读入简单格式的座标资料,绘制统计图表等等。它不是统计软件,也不是数学软件,它纯粹只是一套函数/资料绘图软件。它可以产生PNG,SVG,PS,HPGL,……等等开放的图形档案格式的输出,供文书处理/简报/试算表/……等等软件汇入。
功能:
绘画二维或三维的图像
绘画数学函数
从其他文档读入数据,绘画统计图表
被外部程式(如GNU Octave)调用

一、
plot sin(x)——以曲线绘出三角函数 sin(x)。
gunplot绘图

将数据文件中的数据画出:

plot sin(x), ‘1.dat’

其中1.dat 为一数据文件,每一行描述一点坐标位置。 内容如下,其中 # 后面的内容为注释:

# $Id: 1.dat,v 1.1.1.1 1998/04/15 19:16:40 lhecking Exp $
-20.000000 -3.041676
-19.000000 -3.036427
-18.000000 -3.030596
-17.000000 -3.024081
-16.000000 -3.016755
-15.000000 -3.008456
……

gunplot绘图

命名图和坐标轴

set title 'My first graph'
set xlabel 'Angle, in degrees'
set ylabel 'sin(angle)'
plot sin(x)

gunplot绘图
现在,我们注意到 x 轴实际没有标记为度数,看起来不是很好。要修改此问题,可以通过调整 x 轴上的 tic 标记
改变轴上 tic 并设置网格:

set title "My first graph"
set xrange [-pi:pi]  # we want only one cycle
set xtics ('0' 0, '90' pi/2, '-90' -pi/2, '45' pi/4,'-45' -pi/4,'135' 3*pi/4,'-135' -3*pi/4)
set grid
set xlabel 'Angle, in degrees'
set ylabel 'sin(angle)'
plot sin(x) 

gunplot绘图

多条曲线

plot sin(x) with linespoints pointtype 5, cos(x) w boxes lt 4

gunplot绘图

with 子句使您可以详细而精确地指定线的样式。在本例中,我们说明两种有用的样式。第一种样式 linespoints 通常在对数据绘图时非常有用,它在涉及的每个示例或数据点处标记一个点,并使用线性插值法连接连续的点。这里我们另外指定点类型为 5,它选择终端允许的第五种点。第二种样式 boxes 更适合绘制直方图数据。注意我们如何在 cos(x) 曲线中将 with 缩写成 w。类似地,lt 是 linetype 的缩写,是另一个特定于终端的设置,它选择终端可以绘制的四种线。不必说,您可以使用 pt 代替冗长的 pointtype。如果想在多条线中使用相同的绘图样式(在一个 plot 命令中或在多个 plot 命令中),可以使用 set 命令设置绘图样式:set style function linespoints。要更改用于绘制与函数相对的数据集合的样式,使用 set style data linespoints。

当绘制两条或多条曲线时,我们需要关键字或图例来对它们进行区分。默认情况下,关键字在右上角;但是如果它妨碍了图,可以将关键字放到其他位置 。如果愿意,甚至可以放到图外。

定制图的关键字或图例

set key top left
set key box
plot [-pi:pi] sin(x) title 'sinusoid' with linespoints pointtype 5, cos(x) t 'cosine' w boxes lt 4

gunplot绘图

关于坐标轴

gnuplot> set xlabel ‘x’ %x轴标为‘x’

gnuplot> set ylabel ‘y’ %y轴标为’y’

gnuplot> set ylabel ‘DOS’ tc lt 3 %其中的tc lt 3表示’DOS’的颜色用第三种颜色。

gnuplot> set xtics 1.0 %x轴的主刻度的宽度为1.0,同样可以为y轴定义ytics

gnuplot> set mxtics 3 %x轴上每个主刻度中画3个分刻度,同样可以为y轴定义mytics

gnuplot> set border 3 lt 3 lw 2 %设为第三种边界,颜色类型为3,线宽为2

同样可以为上边的x轴(称为x2)和右边y(称为y2)轴进行设置,即x2tics,mx2tics,y2tics,my2tics。

gnuplot> set xtics nomirror

gnuplot> unset x2tics %以上两条命令去掉上边x2轴的刻度

gnuplot> set ytics nomirror

gnuplot> unset y2tics %以上两条命令去掉右边y轴的刻度