gnuplot使用简介

Gnuplot

Gnuplot 是一款科学作图软件,官方网站是 http://www.gnuplot.info/

使用

建立程序文件(file.gnu)

set term png color enh solid
set logscale x
set xlabel 'L (nm)'
set ylabel "Cumulative kappa (W/mK)"
set output "cumulative_300K_kappa.png"
plot "cumulative_300K.dat" using 1:2 w lp

set: 所有的Gnuplot设置都以set开头
term:指的是terminal,终端。表明图片输出的格式,后面可以跟post eps, png,jpg等等
color:表示输出彩色图片和曲线。
enh:表示enhance,加强,可以输出各种符号,比如希腊字母。
solid:可以使用实体线。
set output “cumulative_300K_kappa.png”:表示输出的图片的名称以及格式,这里输出为png的图片格式。
plot:作图指令。使用该数据的1列作为x轴,2列作为y轴,x轴的值在前。l表示line。lp表示使用点线图。

例如再创建一个tau.gnu。

set term png color enh solid
set xrange [1:]
# set yrange [100:300]
set logscale y
set key outside vertical 
set xlabel "Phonon frequency (cm^{-1})"
set ylabel "Phonon lifetime (ps)"
set xtics format "%.2f"
set ytics format "%.0f"
plot "tau300K_10.dat" using 3:4 w p

xrange/yrange指定x/y轴的刻度范围。, # 注释掉一行代码。
set key outside vertical : 将标识置于图外并保持垂直排列。关于key‘的放置位置,更多参考请参考官方manual,简单常用的有(horizonal水平排列,right top右上角,left top左上角,inside画内放置。
set xtics format “%.2f”: 设置x轴的刻度数值保留小数点后2位。 "%.0f"表示保留到整数。
plot 参数w表示with。p表示points。w p表示画点。

set logscale x
set arrow 100,5 rto 10,2
plot "tau300K_10.dat" using 3:4 lw 2

绘制从位置100,5都位置1000,7的一个arrow(x是log形式,y是线性的)
lw 2表示linewidth 2,默认线和点的粗细位1,这里更改为2.

函数

gnuplot存在很多内置的数学函数,比如bas(), cos(), sin(), int(), log()
以及一些操作算符。一元算符:-a,+a;$3(表示使用第3列,当使用using操作的时候);二元算符:a*b;a/b;三元算符:a?b:c

linetypes,colors,and styles

set linetype 1 lc rgb "dark-violet" lw 2 pt 1
set linetype 2 lc rgb "sea-green" lw 2 pt 7
set linetype 3 lc rgb "cyan" lw 2 pt 6 pi -1
set linetype 4 lc rgb "dark-red" lw 2 pt 5 pi -1
set linetype 5 lc rgb "blue" lw 2 pt 8
set linetype 6 lc rgb "dark-orange" lw 2 pt 3
set linetype 7 lc rgb "black" lw 2 pt 11
set linetype 8 lc rgb "goldenrod" lw 2
set linetype cycle 8
plot sin(x) linetype4
plot sin(x) lt rgb "violet"
plot sin(x) lt rgb "#FF00FF"
plot sin(x) with linespoints ls 5
plot sin(x) with points pointtype 5

使用linestyle 5.
linespoints的缩写为lp。
points风格,(指定set pointsize 改变大小)
linetype,缩写为lt
linecolor,缩写为lc
linewidth,缩写为lw
pointtype,缩写为pt。
pointsize,缩写为ps

刻度的控制

使用方法都相同,xtics, ytics, ztics。
如果使用了logscale的坐标轴刻度,那么间隔就会被解释为multiplicative factor ,而不是一个常数。例如:

# generate a series of tics at y=20 y=200 y=2000 y=20000
set log y
set ytics 20, 10, 50000 logscale

箭头控制

from … to…
箭头起点和终点坐标。rto的时候,是相对位置而不是绝对坐标。
nohead, head, backhead, heads
没有箭头(线段),箭头在终点,箭头在七点,双向都有箭头。
size , ,
分别表示箭头的三个参数。ABC分别代表上面的三个参数。
在这里插入图片描述

filled,empty, nofilled
在这里插入图片描述

set term wxt font "DejaVu Sans, 12"
sinc(x)=sin(pi*x)/(pi*x)
set xlabel "X"
unset key
set samples 500
set arrow 1 from 2,2.05 to 0.3,1 filled size 0.5,15,60 lw 2
set label 1 at 0, 1 point pt 7 ps 1.5 lc rgb "#F87217"
set label 2 "maxmimum (0,1) "  at 2.1, 1.05
plot sinc(x) lw 2

更多技巧:gnuplot的常用技巧

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值