2017-06-02 72 views
0

我必须绘制除法算法的robertson图和pd图。 他们看起来像在这篇文章末尾显示的图片中的东西。 我基本上有一个C++程序,它可以派生出所有需要的参数,所以我只需要写下一些将所有这些行绘制在一起的脚本。使用gnuplot绘制robertson图/ pd图

考虑PD图,这对应于具有斜率m[0],...,m[n-1],因此对于一些x[x0,x1]绘图y = m[0]*x,...,y = m[n-1]*x。为了达到这个目的,最快的方法是什么?我正在考虑扩展我的C++代码,以便吐出一些可以由gnuplot执行的脚本文件,但我从来没有使用它,所以我不知道应该是什么格式或我需要的一般。

也许这是非常愚蠢的事情,或者我只是不知道我真的需要这样做。

Robertson diagramPD-diagram

回答

0

假设你的倾斜度数据与每行一个值的文件,你可以将其转换为一个字符串,然后作为阵列使用。通过将EOL字符替换为空格来将数据转换为tr实用程序。然后在功能f(k,x)中使用范围[x1:x2]中的每个值。

这里是数据文件:

$ cat rob.dat 
20 
10 
5 
2 
-2 
-5 
-10 
-20 

它被转换成:20 10 5 2 -2 -5 -10 -20和存储在变量a

同巴新的终端,就可以得到一张图片,但没有斜体符号:

set term pngcairo enh mono solid lw 1.5 font "Helvetica,14" size 600,800 
set output "rob.png" 
set nokey 
set noborder 
set noxtics 
set noytics 
x1=-0.1 
x2=10.0 
f(k,x)=(x>=x1 && x<=x2 ? k*x : 1/0) 
a=system("tr '\\n' ' ' < rob.dat") 
v(n)=word(a,n) 
set style arrow 1 head size 0.2, 25 filled 
set arrow from x1-1,0 to x2+1.,0 arrowstyle 1 
set arrow from 0.,f(v(8),x2) to 0.,f(v(1),x2) arrowstyle 1 
set arrow from 4.,100. to 7.,60. arrowstyle 1 front 
set label "Selection interval\nfor {/:Italic q_{j+1} = k}" at 1.,120. 
set label "{/:Italic U_a = r{/Symbol r}d}" at x2+0.1, f(v(1),x2) 
set label "{/:Italic U_k}" at x2+0.1, f(v(2),x2) 
set label "{/:Italic L_k}" at x2+0.1, f(v(3),x2) 
set label "{/:Italic U_0}" at x2+0.1, f(v(4),x2) 
set label "{/:Italic L_0}" at x2+0.1, f(v(5),x2) 
set label "{/:Italic U_k}" at x2+0.1, f(v(6),x2) 
set label "{/:Italic L_k}" at x2+0.1, f(v(7),x2) 
set label "{/:Italic L_{-a} = -r{/Symbol r}d}" at x2+0.1, f(v(8),x2) 
set label "{/Italic rw[j]}" at 0.3,f(v(1),x2) 
set label "{/Italic k} < 0" at 2.,-130. 
set style fill solid 0.3 
plot [-2:12][] for [b in a] f(b,x) w l lw 2 lc rgb "black", "+" u 1:(f(v(2),$1)):(f(v(3),$1)) w filledcurves 

enter image description here

使用PostScript EPS终端,你可以得到的人(代替两个第一行):

set term post eps enh mono solid lw 2 font "Helvetica,30" size 6 in,9 in 
set output "rob.eps" 

enter image description here

+0

嗨,我正在阅读你的回答呃,你用的是什么版本的gnuplot?我有4.0。不知道你的代码是否也适用于我。 – user8469759

+0

我的版本是4.6。升级gnuplot,因为这是一个相当旧的版本。 –