plot.log(plot.log文件怎么打开)一篇读懂
Gnuplot 是一个小巧而强大,免费开源跨平台(Windows,Mac,Linux)的绘图工具。其特点在于绘图质量高且快,易学易用,仅需少量代
Gnuplot 是一个小巧而强大,免费开源跨平台(Windows,Mac,Linux)的绘图工具其特点在于绘图质量高且快,易学易用,仅需少量代码,就可得到用于发表的高质量图片,中英文参考文档丰富Gnuplot可做简单的数据处理和分析,比如统计和多参数函数拟合。
毕竟2,3维绘图才是它的强项演示可以查看视频开源免费,小巧强大:一张图急速入门数据绘图。 先上图,后边贴代码。
Gnuplot 生的PNG图片用到的数据文件(data.txt)的内容如下1.0 2.0 0.63.1 3.9 0.54.9 5.0 1.57.2 8.1 0.98.9 10.3 0.7三种运行方式(假设绘图脚本存于“plot.gp”文件中):
(1)在当前目录下打开终端, 输入 gnuplot plot.gp 并回车 (2) 在当前目录下打开终端,先在终端输入gnuplot进去,然后load "plot.gp" 回车(3)Windows 下双击脚本。
代码如下: ############ 几十行代码急速入门Gnuplot数据绘图 ################ "#" 后边是注释### 首先设置输出的格式,支持pdf,png,eps等常用格式
set terminal pngcairo size1000,1000 font Times New Roman,10## 格式,大小和字体setoutput"plot.png"###输出的文件名#set terminal pdfcairo size 20cm,20cm font Times New Roman,12 ##
#set output "plot.pdf"#set terminal epscairo size 20cm,20cm font Times New Roman,12 ## #set output "plot.eps"
### 可以定义变量和宏,便于后边重复使用 sx = "set xrange "## 例如后边当成宏来引用:@sx ,而不是使用 "set xrange",你可缩减代码量### 定义变量,用来设置上下左右的边缘和子图间距离
left=0.1right=0.95 bottom=0.1 top="0.95" hspace="0.1" wspace="0.15"###因为是要一张图里4个子图,所以启用了多图模式:set multiplot layout
2,2 spacing @hspace,@wspace margins left,right,bottom,@top ########## 子图 (1): 绘制函数,设置基本的元素如:标题、坐标范围、图例等
set label "(1)"at graph 0.02,0.03 font ,20 textcolor rgb redset title "example"set xlabel "This is xlabel with {/Symbol a}=0.1 to 100"
set ylabel "This is ylabel with X^2_3"setkey top rightLeftreverse font Times New Roman,15###设置图例格式:位置、字体等
f(x)=sin(x)/x ###定义函数set xrange [0:100] ###设置x轴范围set yrange [-0.5:1.0] ###设置y轴范围set xtics scale
3###设置x轴的刻度的长度,是默认的3倍长set mxtics 10###x轴子刻度的数目set mytics 5###y轴子刻度的数目setlog x ###x轴设置成log
setstyle fill pattern 1### plot命令开始绘图并设置参数: plot f(x) w line linetype 1 pointtype 5 ps 1.0 lc 2 lw 4,\ f(x) w filledcurves y=
0.5 lc rgb blue###上边用到了缩写ps=pointsize.其他也有缩写:如line=l, linetype=lt, pointtype=pt等等######### 子图 (2): 数据文件绘图和拟合
reset###Gnuplot会继承上边的命令,所以需要reset取消之前所有的设置set title "fitting functions"set label "(2)"at graph 0.02,0.03
font ,20 textcolor rgb red @sx [0:11] ###这里引用了宏set yrange [0:11] setkey bottom right font ",14"
spacing 2 g(x) = a*x**2 + b*x + c ###定义函数并拟合,参数为a,b,c fit g(x) "data.txt" u 1:2 via a,b,c
###定义函数并拟合 key_g= sprintf("fits without yerror:\ng(x) = %5.3f*x^2 + %5.3f*x + %5.3f",a,b,c) h(x) = d*x**
2 + e*x + f fit h(x) "data.txt" u 1:2:3 yerror via d,e,f key_h= sprintf("fits with yerror:\nh(x) = %5.3f*x^2 + %5.3f*x + %5.3f"
,d,e,f) set xlabel xxxx rotate by45 plot "data.txt" u 1:2:3 w yerror pt 5 ps 1.0 lc rgb blue title "data"
,\ g(x) w line linecolor rgb red title key_g,\ h(x) w l lc rgb green title key_h ######### 子图 (3):统计和填充
resetsetkeyleft top box set label "(3)"at graph 0.02,0.03 font ,20 textcolor rgb red df=data.txt###这里使用文件里的数据绘图
stats df u 1:2name"A"###统计数据的1和2列,并将统计结果存入A中 print A_min_x, A_min_y ###可以打印出A中统计的x的最大和最小值 @sx [A_min_x
-1: A_max_x + 1] ###根据统计数据设置x轴范围set yr [A_min_y-1: A_max_y + 1] set arrow from A_min_x,A_min_y+2to A_min_x,A_min_y
###绘制箭头set label Min.at A_min_x,A_min_y+2.3 center set arrow from A_max_x,A_max_y-2to A_max_x,A_max_y
set label Max.at A_max_x,A_max_y-2.3 center front set xlabel xxxx textcolor rgb redsetstyle fill solid
0.5#set style fill pattern 3 plot df u 1:2 w filledcurves y=2 lc rgb seagreen title fill with y=2,\ df u
1:2 w lp pt 4 ps 0.9 lc rgb red lw 2,\ [3:6] A_mean_y w l dt -- lw 2 lc rgb black title "mean"######## 子图 (4):直方图
resetset label "(4)"at graph 0.02,0.03 font ,20 textcolor rgb redsetstyledata histogram setstyle fill solid
1.0 border lt -1set boxwidth 1.0setkeyat1.5,7 box font ,15reverseset yr [0:10] set xtics ("A"0, "B"1
, "C"2, "{/Symbol b}"3, "{/Symbol S}"4) set xlabel xxxxoffset0,-1 plot "data.txt" u 1 title histogram
lc rgb seagreen,\ "data.txt" u 0:($1+0.5):1 w labels title "" unset multiplot ###退出多图模式,完成绘图并保存
- 标签:
- 编辑:李松一
- 相关文章
-
夏森老人?夏森老人的事迹?
新华社南昌3月8日电 题:她的“枝叶”仍繁茂——夏森老人的故事新华社记者张璇、李子健相隔数千里,中国社会科学院原外事局研究员夏…
-
老爸老妈向前冲?老爸老妈向前冲胡华?
江西省瑞昌市92岁高龄退役老兵胡华纯,是位有着69年党龄的共产党员,曾为新中国解放事业立下赫赫战功,复员转业回乡后,他深藏功名,不忘初…
- 畅想中国?畅想中国未来的样子?
- 我的家乡 普通话?我的家乡普通话命题说话?
- 中国抗日?中国抗日战争的转折点是哪场战役?
- 我爱文学网?天涯文学网?
- 小学班主任经验交流?小学班主任经验交流题目?