Keywords: MacOS; gnuplot; Unix; Linux

gnuplot is a command-line program that can generate two- and three-dimensional plots of functions, data, and data fits. It is frequently used for publication-quality graphics as well as education.

在大多的画图功能上, gnuplot 都能很好的适用。写个脚本让 gnuplot 直接把数据转化成高质量输出的图片也酷 (在结尾处会对这个进行展示)。gnuplot 在 unix 和 linux 上的安装极其简便, 这里想说一下在 Mac os x 上的安装和使用。

其实在 Mac OS X 中也有类似的 software repository, 比如 Macport, Fink, Homebrew。由于个人喜好缘故, 这里只介绍 Homebrew。

Homebrew安装

  • 第一步安装Homebrew (链接), 相当简单,打开 Terminal, 输入
 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 

上个厕所回来后就安装好了,默认的安装路径 –prefix=/usr/local/。 随便安装个什么测试下,比如

 brew install wget 

 

  • 然后在 Terminal 中输入
     brew update
    brew options gnuplot 

    下面的是输出结果:

    --with-aquaterm
        Build with AquaTerm support
    --with-cairo
        Build the Cairo based terminals
    --with-latex
        Build with LaTeX support
    --with-pdflib-lite
        Build with pdflib-lite support
    --with-qt
        Build with qt support
    --with-tests
        Verify the build with make check (1 min)
    --with-wxmac
        Build with wxmac support
    --with-x11
        Build with x11 support
    --without-emacs
        Do not build Emacs lisp files
    --without-gd
        Build without gd support
    --without-lua
        Build without the lua/TikZ terminal
    --HEAD
        Install HEAD version

     

    • 在选定你想要的 gnuplot terminal 类型后,在 Terminal 中输入
     brew install gnuplot --with-cairo --with-pdflib-lite --with-qt --with-wxmac --with-latex 

    很快的安装完成后,在 Terminal 中输入 gnuplot 进行测试, 随即进入了 gnuplot 的模式,在这个模式中随便输入个可识别的函数, 比如 plot sin(x), gnuplot 会随即弹出一个对话框来输入图形。

    • Note: 关于如何配置,如何存储图片到本地文件夹, 这里不作过多的介绍。 在使用过程中, 很快就会学会这些简单的技巧, 或者你可以在下面的脚本中学到最基本的输出命令们。 gnuplot 的学习曲线并没有很陡。

    展示

    下面展示一个好玩的东西: 我把需要在 gnuplot 中输出的指令们写成一个 脚本,

    #!/usr/bin/gnuplot -persist

    set terminal postscript eps color solid linewidth 2 “Helvetica” 20

    set output “trajectory_raffinate.eps”

    set multiplot

    set xrange [0:100000]
    set yrange [-0.0005:0.003]

    set xtics add (“0” 0, \
    “20” 20000, \
    “40” 40000, \
    “60” 60000, \
    “80” 80000, \
    “100” 100000)

    set xlabel “Switches”
    set ylabel “Concentration [mMol]”

    set grid
    set key box

    plot “trajectory.dat” using 1 with lines title “comp 1”, “trajectory.dat” using 2 with lines title “comp 2”

    set size 0.5,0.4
    set origin 0.4,0.12

    unset xlabel
    unset ylabel

    set xrange [96000:98000]
    set yrange [0:0.0025]

    set xtics 1000
    set ytics 0.001

    set xtics add (“96” 96000, \
    “97” 97000, \
    “98” 98000)

    unset grid
    unset key

    plot “trajectory.dat” using 1 with lines, “trajectory.dat” using 2 with lines

    unset multiplot

    set output
    #=========================================================#
    unset size
    unset origin
    unset xlabel
    unset ylabel
    unset xtics
    unset ytics

    set output “trajectory_extract.eps”

    set multiplot

    set xrange [0:100000]
    set yrange [-0.001:0.0025]

    set xtics 20000
    set ytics 0.0005
    set xtics add (“0” 0, \
    “20” 20000, \
    “40” 40000, \
    “60” 60000, \
    “80” 80000, \
    “100” 100000)

    set xlabel “Switches”
    set ylabel “Concentration [mMol]”

    set grid
    set key box

    plot “trajectory.dat” using 3 with lines title “comp 1”, “trajectory.dat” using 4 with lines title “comp 2”

    #———————————————————#
    set size 0.5,0.4
    set origin 0.4,0.12

    unset xlabel
    unset ylabel

    set xrange [96000:98000]
    set yrange [0:0.0025]

    set xtics 1000
    set ytics 0.001

    set xtics add (“96” 96000, \
    “97” 97000, \
    “98” 98000)

    unset grid
    unset key

    plot “trajectory.dat” using 3 with lines, “trajectory.dat” using 4 with lines

    unset multiplot

    set output
    #=========================================================#
    unset size
    unset origin
    unset xlabel
    unset ylabel
    unset xtics
    unset ytics

    set output “chromatogram.eps”

    set xrange [0:8000]
    set yrange [0:0.0025]

    set xtics 2000
    set xtics (“” 0, \
    “Zone IV” 1000, \
    “” 2000, \
    “Zone III” 3000, \
    “” 4000, \
    “Zone II” 5000, \
    “” 6000, \
    “Zone I” 7000, \
    “” 8000)

    set ytics 0.0005

    set grid

    set ylabel “Concentration [mMol]”

    set key box

    plot “chromatogram.dat” using 1 with lines title “comp 1”, “chromatogram.dat” using 2 with lines title “comp 2”

    set output

    set terminal wxt

    然后你可以直接在 Terminal 中运行 gnuplot “script”, 然后你可以看到图片已经保存在你当前文件夹了。关于在这个脚本中用到的数据, 我把它存到公开的 google drive 文件夹中了

    https://drive.google.com/folderview?id=0B-XzRGjz86jWMkJKVHYwNk1nMlk&usp=sharing

     

     

     

     

     

     

     

     

     

     

     

     

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s