Gnuplot
如何画出复指数信号e^(jwt) 和 e^(-jwt)?
可以使用gnuplot这个工具作图,还是很方便的,
$ e^{-j\omega t} 和 e^{j\omega t}$都是向着t螺旋前进的曲线,但是旋转方向不同,下面就$e^{j\omega t}$举例。
要在复频域画出来,首先定义Z轴为虚轴j,X轴为时间轴t,Y轴还是原来的Y轴,
$e^{j\omega t} = cos(\omega t) + j sin(\omega t)$
拆成$y = cos(\omega t)$ 和$z = sin(\omega t)$
就像在二维平面,$x+iy 代表的点为(x, y)$一样,此处$e^{j\omega t} = cos(\omega t) + j sin(\omega t)$代表的就是空间上的点$(t, y, z)$ 或者说$(x, y, z)$,即$(t, cos(\omega t), sin(\omega t))$,影响不大,因为我们已经把x轴作为t轴。
所以我们只要求出t取不同值的时候,$cos(\omega t)和sin(\omega t)$的值,然后进行描点画线即可。
具体参看这篇文章:Gnuplot 直接读取变量值进行描点连线…
Continue reading...Gnuplot绘制坐标轴
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
unset border; set xtics axis -1,1,4; set ytics axis 0,1,2; set arrow 1 from -1,0 to 4,0 lw 1; set arrow 2 from 0,-1 to 0,2 lw 1; set label 1 'x' at 3.9,0.2; set label 2 'y' at 0.2,2; set xrange [-1:4]; set yrange [-1:2]; u(x)=(x>=0)?1:NaN; p '< echo "0 1"' w impulse lw 3 lt rgb "0x00aaff" title ''; replot u(x) lw 2 lt rgb '0x00aaff'; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#注释专区 unset border; #去除原来的边界线 set xtics axis -1,1,4; #x轴从-1到4,步长1 set ytics axis 0,1,2; #y轴从0到2,步长1 set arrow 1 from -1,0 to 4,0 lw 1; #画箭头 set arrow 2 from 0,-1 to 0,2 lw 1; set label 1 'x' at 3.9,0.2; #设置坐标轴名字 set label 2 'y' at 0.2,2; set xrange [-1:4]; #设置范围 set yrange [ |
Gnuplot 折线或平滑连接各点
数据在data文件里,内容为:
1 2 3 4 5 6 7 |
1 1.2 2 2.1 3 3.2 4 3.8 5 5.5 |
打开Gnuplot.
1.以折线图形式连接各点
1 2 3 4 |
set key left top plot 'data' u 1:2 smooth unique title 'unique', 'data' with points title "points"; |
2.以光滑曲线形式连接各点
1 2 3 4 |
set key left top plot 'data' u 1:2 smooth csplines title 'csplines', 'data' with points title "points"; |
smooth的全部参数如下:
其他没用上,不赘述。…
Continue reading...Gnuplot 在三维坐标中描绘二维曲线
缺乏关键词在网上找了很久,没找到该如何在三维坐标中画二维曲线,用splot直接画,画出的都是一些3维曲面,并没有得到单纯的一条二维曲线。
上图是sin(x)在三维坐标中的曲面图,而目标是在特定的x或y值上的一条正弦曲线,还有一定差距,后来在Gnuplot的官方文档中找到了一丝端倪。如下:
这个图形已经很接近我们想要的了,只是一个是平面,一个是线,把这些平面去掉只保留曲线就是我们要找的实现方法。
通过网上查找很容易得到了Fence plots的代码示例。如下:
看的出,因为设置了函数样式为脉冲形式所以才有了曲线下方的填充,如果不设置这个属性那么我们就可以得到想要的曲线。
最后总结写出自己的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#以下代码可以直接全部复制运行 set view 66,56; set iso 500; set samp 500; set xrange[0:4]; set yrange [-4*pi:4*pi]; set zrange [-1:1]; xf(x,a)=(abs(x-a)<.01)?1:NaN; splot xf(x,2)*cos(y) lw 1; |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#注解专用区 set view 66,56 #设置查看角度; set iso 500 #设置分辨率; set samp 500 #设置样本点数; set xrange[0:4]; set yrange [-4*pi:4*pi]; set zrange [-1:1]; xf(x,a)=(abs(x-a)<.01)?1:NaN #过滤x!=a+-0.01的曲线; splot xf(x,2)*cos(y) lw 1 #画图,line width = 1; |
生成图像如下:
实际上,这仍然是曲面来的,只不过我们限定当x在2的附近时(x-2绝对值小于0.01),让xf函数值为1,其他地方都不取值,所以剩下很小的曲面看上去便像二维曲线。…
Continue reading...Gnuplot设置坐标轴名称 , 修改坐标轴刻度等命令记录
1.设置/显示坐标名称
1 2 3 4 5 |
gnuplot> set xlabel "name_x" gnuplot> set ylabel "name_y" gnuplot> set zlabel "name_z" |
2.设置坐标显示刻度
1 2 3 4 5 |
set xtics 1; set ytics 1; set ztics 1; |
3.三维展示角度设置
1 2 3 |
set view 76,54; # 0-360度变化 |
4.设置绘图范围
1 2 3 4 5 |
set xrange[0:10] set yrange[0:10] set zrange[0:10] |
5.绘图函数
1 2 3 4 5 6 |
replot #重绘或在原图上加绘 plot #绘制二维平面图 splot #绘制三维空间图 clear #清除绘制图像 |
6.设置标题
1 2 3 |
set title "标题名" |
7.取消显示的标题
1 2 3 4 |
unset key replot |
8.设置标题
1 2 3 4 |
set title "name" replot |
9.设置标题偏移
1 2 3 4 |
set title offset -1,-1 replot |
10.设置legend位置为左上方
1 2 3 4 |
set key left top replot |
11.执行脚本时打开多个窗口和防止gnuplot闪退
1 2 3 4 5 6 7 8 9 10 11 12 |
#文件命名test.dot set term wxt 1; plot sin(x); set term wxt 2; plot 1-exp(-x); pause -1; quit; |
执行:
1 2 3 |
gnuplot test.dot |
结果:
…
Continue reading...Gnuplot描点,线性拟合,设置标题为拟合函数
假设我们有以下数据,在文件名为data的文件里。
1 2 3 4 5 6 7 |
1 1 2 2.3 3 2.9 4 3.8 5 5.4 |
1.终端输入gnuplot打开软件,之后输入 f(x)=a*x+b,如下
1 2 3 |
gnuplot> f(x)=a*x+b #用一次函数拟合 |
2.输入以下命令进行拟合:
1 2 3 |
gnuplot> fit f(x) 'data' u 1:2 via a, b |
其中u是using,表示用data文件里第1~2列的数据,via是指拟合变量是a,b。输入以上命令后会输出很多相关信息,不赘述。
3.求取拟合函数的字符串
1 2 3 |
gnuplot> func=sprintf("y=%.2f*x+%.2f",a,b) |
4.画图
1 2 3 |
gnuplot> plot f(x) title func |
得到如下图:
5.描点
1 2 3 |
gnuplot> replot 'data' u 1:2 title 'points' |
最终图像如下:
总的命令如下:
1 2 3 4 5 6 7 |
f(x)=a*x+b fit f(x) 'data' u 1:2 via a, b func=sprintf("y=%.2f*x+%.2f",a,b) plot f(x) title func replot 'data' u 1:2 title 'points' |
…
Continue reading...