程序员的绘图利器 — Gnuplot
介绍
Gnuplot is a command-line program that can generate two- and three-dimensional plots.
It is frequently used for publication-quality graphics as well as education.
The program can be used both interactively and in batch mode using scripts.
gnuplot is programmed in C.
For script-driven graphics, gnuplot is by far the most popular program.
先上一张效果图:
用法
(1)数据文件格式
Discrete data contained in a file can be displayed by specifying the name of the data file (enclosed in quotes)
on the plot or splot command line. Data files should have the data arranged in columns of numbers. Columns
should be separated by white space (tabs or spaces) only, (no commas). Lines beginning with a # character
are treated as comments and are ignored by gnuplot. A blank line in the data file results in a break in the line
connecting data points.
(2)风格定制
一般需要指明:
ranges of the axes
labels of the x and y axes
style of data point
style of the lines connecting the data points
title of the entire plot
Plots may be displayed in one of styles:
lines
points
linespoints
impulses
dots
steps
fsteps
histeps
errorbars
xerrorbars
yerrorbars
xyerrorbars
boxes
boxerrorbars
boxxyerrorbars
financebars
candlesticks
vector
实例
(1)基础
set title "Some math functions" // 图片标题
set xrange [-10:10] // 横坐标范围
set yrange [-2:2] // 纵坐标范围
set zeroaxis // 零坐标线
plot (x/4)*2, sin(x), 1/x // 画函数
(2)三维曲线
splot sin(x), tan(x) // 画sin(x)和tan(x)的三维曲线
(3)多条曲线
plot sin(x) title 'Sine', tan(x) title 'Tangent' // 画多条曲线,并且分别指定名称
从不同数据文件中提取信息来画图:
plot "fileA.dat" using 1:2 title 'data A', \
"fileB.dat" using 1:3 title 'data B'
(4)点和线风格
plot "fileA.dat" using 1:2 title 'data A' with lines, \
"fileB.dat" using 1:3 title 'data B' with linespoints
可以使用缩写:
using title and with can be abbreviated as u t and w.
plot sin(x) with line linetype 3 linewidth 2
或plot sin(x) w l lt 3 lw 2
plot sin(x) with point pointtype 3 pointsize 2
或plot sin(x) w p pt 3 ps 2
颜色列表大全:
http://www.uni-hamburg.de/Wiss/FB/15/Sustainability/schneider/gnuplot/colors.htm
用法:lc grb "greenyellow"
线条颜色,点的为pointtype
linetype 1 // 红色
linetype 2 // 绿色
linetype 3 // 蓝色
linetype 4 // 粉色
linetype 5 // 比较浅的蓝色
linetype 6 // 褐色
linetype 7 // 橘黄色
linetype 8 // 浅红色
线条粗细,点的为大小pointsize
linewidth 1 // 普通的线
linewidth 2 // 比较粗
linewidth 3 // 很粗
(5)常用
replot // 重绘
set autoscale // scale axes automatically
unset label // remove any previous labels
set xtic auto // set xtics automatically
set ytic auto // set ytics automatically
set xtics 2 // x轴每隔2设一个标点
set xlabel "x axe label"
set ylabel 'y axe label"
set label 'Yield Point" at 0.003,260 // 对一个点进行注释
set arrow from 0.0028,250 to 0.003,280 // 两点之间添加箭头
set grid // 添加网格
reset // gnuplot没有缩小,放大后只能reset后重绘,remove all customization
set key box // 曲线名称加框
set key top left // 改变曲线名称位置
set format xy "%3.2f" // x轴和y轴坐标格式,至少有3位,精确到小数点后两位
quit、q、exit // 退出程序
(6)绘制多个图
set size 1,1 // 总的大小
set origin 0,0 // 总的起点
set multiplot // 进入多图模式
set size 0.5,0.5 // 第一幅图大小
set origin 0,0.5 // 第一幅图起点
plot sin(x)
set size 0.5,0.5
set origin 0,0
plot 1/sin(x)
set size 0.5,0.5
set orgin 0.5,0.5
plot cos(x)
set size 0.5,0.5
set origin 0.5,0
plot 1/cos(x)
unset multiplot
(7)输出文件
set terminal png size 1024, 768 // 保存文件格式和大小
set output "file.png" // 保存文件名称
set terminal X11 // 重新输出到屏幕
(8)脚本
a.plt //后缀名为plt
gnuplot> load 'a.plt'
或gnuplot a.plt
save "graph.gp"
或save "graph.plt"
传入参数
call "a.plt" param1 param2
param1、param2在a.plt中对应于$0、$1
(9)字体设置
输出错误:
Could not find/open font when opening font "arial", using internal non-scalable font
下载RPM包:
wget http://www.my-guides.net/en/images/stories/fedora12/msttcore-fonts-2.0-3.noarch.rpm
rpm -ivh msttcore-fonts-2.0-3.noarch.rpm
设置环境变量:
修改/etc/profile或~/.bashrc,这样设置可以固定下来。
export GDFONTPATH="/usr/share/fonts/msttcore"
export GNUPLOT_DEFAULT_GDFONT="arial"
. /profile/etc
OK,现在可以使用arial字体了。
Reference
[1]. http://en.wikipedia.org/wiki/Gnuplot
[2]. http://people.duke.edu/~hpgavin/gnuplot.html
[3]. http://blog.csdn.net/liyuanbhu/article/details/8502461
[4]. http://linux.chinaunix.net/techdoc/develop/2009/07/21/1125242.shtml
[5]. http://www.fnal.gov/docs/products/gnuplot/manual/
[6]. gnuplot中文手册
程序员的绘图利器 — Gnuplot的更多相关文章
- 【原创精品】程序员最强大的利器——电子笔记本的思考(1)(ver0.3)
[原创精品]程序员最强大的利器,本文以下内容全都是作者EverStenis(胡佳吉)的原创,未经授权不得转载,抄袭必究. 我想问大家一个问题,对于我们程序员来说,在我们的武器工具库中,最强大的一件利器 ...
- 打磨程序员的专属利器——命令行&界面
工欲善其事,必先利其器,程序员更是如此,如果没有一套与自己思维同步的工具,将非常难受并且编码效率会非常低. 但十个程序员就有对工具的十种不同理解,本人现在冒然将自己的“工具箱”拿出来晒晒.若对大家没帮 ...
- Mac OS X 程序员利器 – Homebrew安装与使用
Mac OS X 程序员利器 – Homebrew安装与使用 Homebrew安装与使用 什么是Homebrew? Homebrew is the easiest and most flexible ...
- 程序员编程利器:20款最好的免费的IDEs和编辑器
程序员编程利器:20款最好的免费的IDEs和编辑器 还没转眼明年可就大年三十了,忙的可真是晕头转了个向,看着亲朋好友们那让人欣羡的小肚腩,不禁感慨,岁月是一把猪饲料,绿了芭蕉,肥了那杨柳小蛮腰,可怜我 ...
- Mac开发利器之程序员编辑器MacVim学习总结
Emacs和Vim都是程序员专用编辑器,Emacs被称为神的编辑器,Vim则是编辑器之神.至于两者到底哪个更好用,网络上两大派系至今还争论不休.不过,相比之下,Emacs更加复杂,已经不能算是一个编辑 ...
- Mac开发利器之程序员编辑器MacVim学习总结(转)
一.关于Vim Emacs和Vim都是程序员专用编辑器,Emacs被称为神的编辑器,Vim则是编辑器之神.至于两者到底哪个更好用,网络上两大派系至今还争论不休.不过,相比之下,Emacs更加复杂, ...
- freecplus框架,Linux平台下C/C++程序员提高开发效率的利器
目录 一.freecplus框架简介 二.freecplus开源许可协议 三.freecplus框架内容 字符串操作 2.xml解析 3.日期时间 4.目录操作 5.文件操作 6.日志文件 7.参数文 ...
- 面试利器!字节跳动2021年Android程序员面试指导小册已开源
整份手册分为两个部分,分别是:Java部分.Android部分.数据结构与算法篇.字节跳动2020年全年面试题总结篇! 每个知识点都有左侧导航书签页,看的时候十分方便,由于内容较多,这里就截取一部分图 ...
- [Mac A]为什么国外程序员爱用 Mac?
from http://www.vpsee.com/2009/06/why-programmers-love-mac/ Mac 在国外很受欢迎,尤其是在 设计/web开发/IT 人员圈子里.普通用户喜 ...
随机推荐
- samba服务日志文件-密码文件及启停
1.Samba服务日志文件日志文件对于samba非常重要,它存储着客户端访问samba服务器的信息,以及samba服务的错误提示信息等,可以通过分析日志,帮助解决客户端访问和服务器维护等问题.在/et ...
- Windows下Node.js开发环境搭建-合适的开发环境
1)生产环境中的Node.js应用 Windows + Linus 2)虚拟机工具 VirtualBox 虚拟机CentOS安装 3)xShell与xFtp(windows到linux文件传输) 4) ...
- XenServer 使用笔记
XenServer 模拟千兆网卡 这两天用 XenServer 安装 VM,其中一台 VM 是用作无盘测试的 Linux Server,不在主流发行版之列,无奈 XenServer 日前对非主流的 L ...
- BFC——块级格式上下文
BFC中的B指的是block,对应的还有IFC,I指的是inline.对于BFC的理解可以参考层叠上下文.页面中,盒子的排布规则,是生效在对应的BFC中.两个BFC中的布局互不影响.页面的本身的根本身 ...
- Swift - IBOutlet返回nil(fatal error: unexpectedly found nil while unwrapping an Optional value)
在Swift 中 ViewController 默认构造方法不关联同名的xib文件 在使用OC的时候,调用ViewController的默认构造函数,会自动关联到一个与ViewController名字 ...
- 高仿QQ即时聊天软件开发系列之一开端
前段时间在园子里看到一个大神做了一个GG2014IM软件,仿QQ的,那感觉···,赶快下载源码过来试试,还真能直接跑起来,效果也不错.但一看源码,全都给封装到了ESFramework里面了,音视频那部 ...
- Dom4j 添加 / 更新 / 删除 XML
1.获得文档 /** *1.获得解析流 *2.解析XML */ 2.添加 /** *1.获取父元素 *2.创建元素 *3.创建属性并添加到元素中 *4.元素添加到根节点 */ 3.更新 /** *1. ...
- C++拾遗(二)关于变量
符号常量——预处理方式 例如: #define ZERO 0 会替换程序中所有的ZERO为0,在那些设计为用于C和C++的头文件中,必须使用#define来定义符号常量. 无符号类型 unsigned ...
- Guava API学习之Optional 判断对象是否为null
java.lang.NullPointerException,只要敢自称Java程序员,那对这个异常就再熟悉不过了.为了防止抛出这个异常,我们经常会写出这样的代码: Person person = p ...
- 实例讲解MySQL联合查询
好了终于贴完了MySQL联合查询的内容了,加上上一篇一共2篇,都是我转载的,实例讲解MySQL联合查询.那下面就具体讲讲简单的JOIN的用法了.首先我们假设有2个表A和B,他们的表结构和字段分别为: ...