请教一个gnuplot画图解决问题问题

程序员的绘图利器 — Gnuplot - 推酷
程序员的绘图利器 — 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:
linespoints
xerrorbars
yerrorbars
xyerrorbars
boxerrorbars
boxxyerrorbars
financebars
candlesticks
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
颜色列表大全:
用法: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 // 很粗
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. 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
// 保存文件格式和大小
set output &file.png& // 保存文件名称
set terminal X11 // 重新输出到屏幕
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包:
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字体了。
[6]. gnuplot中文手册
已发表评论数()
已收藏到推刊!
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
排版有问题
没有分页内容
视频无法显示
图片无法显示推荐这篇日记的豆列
······使用gnuplot自动画图之Linux基本的应用程序 - yhzguang1的个人空间 - Gmail社区
- powered by X-Space
使用gnuplot自动画图之Linux基本的应用程序
& 16:00:31
使用gnuplot自动画图之Linux基本的应用程序
gnuplot是一个可以根据数据或者数学公式自动产生图表的非常号的工具。对于交互的图形生成,我比较喜欢电子表格。如果你根据“模板”从大量的数据里生成可视化图形,在这个过程中需要不断进行调整,对于不那么流行的gnuplot可能会有点不那么顺手。gnuplot有很多灵活的特性,但是需要时间去学习。设计一个复杂的图形模板有些时候要花掉我两小时的时间(但是可以接受,因为模板可以在以后重复使用)。最好的办法是启动gnuplot, 然后在“gnuplot&”的提示符下,输入“help”。gnuplot在Linux和Windows下都有效。
我的数据存放在文本文件(ASCII, *.dat)里。我的“图形模板”存放在gnuplot“命令”文件里(*.gnu)。 输出将会输出道图形文件里(*.png),该图形文件可以被打印或者输出道其他的字处理软件里。
以下是一个从命令文件“make_graphs.gnu”产生图形输出的例子,运行命令:
gnuplot make_graphs.gnu
显示输出结果,我可以输入(在 X 终端):
display my_graph.png
用于生成两维图形的文件 "make_graphs.gnu"例子 如下页所示:
# 以#开头的都是注释行
# 给图形打上日期和时间戳
set timestamp "%Y-%m-%dT%T%z"
# 以下设置图形的解析度(缺省值100)
set samples 600
# 把输出存为一个 *.png的文件,并设置为彩色
set output "my_plot.png"
set terminal png color
#interesting terminals: png, x11, postscript, postscript. eps, hpgl
set title "My Graph" # 设置图形的标题
set xlabel "Distance [m]" # 设置x轴的第一个标题(底部)
set x2label "Distance [feet]" # 设置x轴的第二个标题(顶部)
set ylabel "sin meters" # 设置y轴的第一个标题(左侧)
set y2label "log feet" # 设置y轴的第二个标题(右侧)
set xtics # 控制坐标轴上的刻度
set x2 set y2tics # 同一行上的命令可以使用“;”来分隔
set mytics # 设置坐标轴上的最小值,这里我把它加到y轴上
set xrange [0:15] # 在x轴上的数值范围
set x2range [0:15.0/0.305] # 把“米”制量度转化成“英尺”
set yrange [*:*] # "*" 设置数值范围为自动
set y2range [*:*] # 设置y轴的第二个数值范围(右侧)
set nologscale # 控制画图的类型,缺省是线性
set nogrid # 或者 "set grid", 设置不画格子,缺省是nogrid
set key outside # 或者 "set nokey",设置标注的位置
# 以下的行使用4个不同的系列生成图形:
plot sin(x) axes x1y1, log(x) axes x2y2, "data.dat" using 1:2, \
"data.dat" using 1:3
# 比较长的行可以使用“\”来分隔
# 第三个系列使用数据文件里的第一和第二列数据
# 第四个图形从数据文件里采用第三列的数据和第一列的数据做对照本文资料来源于/Python中用popen调用gnuplot画图 - 快快乐乐搞技术 - ITeye技术网站
博客分类:
cmd += "set terminal png\n"
cmd += "set output 'rate_avg_" +name+ ".png'\n"
cmd += "p '" +name+
"_avg.log' u " + str(xyconv((1,2),3)+1) + "w lp t '1-&2(avg)',"
"'" +name+
"_inst.log' u " + str(xyconv((1,2),3)+1) + "w lp t '1-&2(inst)',"
"'" +name+
"_avg.log' u " + str(xyconv((2,3),3)+1) + "w lp t '2-&3(avg)',"
"'" +name+
"_inst.log' u " + str(xyconv((2,3),3)+1) + "w lp t '2-&3(inst)',"
"'" +name+
"_avg.log' u " + str(xyconv((3,1),3)+1) + "w lp t '3-&1(avg)',"
"'" +name+
"_inst.log' u " + str(xyconv((3,1),3)+1) + "w lp t '3-&1(inst)'\n"
gp=os.popen('gnuplot', 'w')
gp.write(cmd)
gp.flush()
这几天我在做仿真,就用python写了一个script来自动运行多次实验,并且生成png的图像。
我只会用gnuplot来画图,python有一个gunuplot的库(gnuplot.py)可以对在python中生成的数据来画图,但是我的图像是存成trace文件的,要用这个库要读出trace反而麻烦了。于是我就看了看gnuplot.py的源代码,原来他调用gnuplot的方式是popen。
以上的程序就是用了gnuplot.py的方法,然后程序中画图的一段。如果你要是用过gnuplot大概一看就明白了。
后来想到其实也有个更简单的方法,就是写好一个gnuplot的script然后每次用os.system来调用也是可以的,但这样灵活性就差一点。当然也可以用python来生成gnuplot的script然后再用os.system来调用,方法反正很多的了!
论坛回复 /
(2 / 3144)
浏览: 115312 次
来自: 武汉
方案不错,用之,呵呵
是,少折腾为好。我也有曾经有两次想用几个星期把emacs搞定, ...
这话说的...
最好用的主流编辑器居然被说成 将就可用.
哥们在用60%的键盘吗?
SSH Secure Shell 3.1.0 (Build 2 ...

我要回帖

更多关于 用画图的策略解决问题 的文章

 

随机推荐