在Bash中使用图形的x和y标题从文件中绘制gnu绘图
我有一个文件“data”中的数据,该文件分为两列,即比特率和峰值信噪比。我想画gnu图,这样x轴有标题比特率,y轴有标题PSNR。同时显示图表的标题在Bash中使用图形的x和y标题从文件中绘制gnu绘图,bash,gnuplot,Bash,Gnuplot,我有一个文件“data”中的数据,该文件分为两列,即比特率和峰值信噪比。我想画gnu图,这样x轴有标题比特率,y轴有标题PSNR。同时显示图表的标题 set title "Rate Distortion Curve" set xlabel "bit rates" set ylabel "psnr" set grid gnuplot -p -e "plot 'data' with lp" 不确定问题是什么,尽管您似乎将bash命令和变量与gnuplot命令和变量混合在一起 为gnuplot编写
set title "Rate Distortion Curve"
set xlabel "bit rates"
set ylabel "psnr"
set grid
gnuplot -p -e "plot 'data' with lp"
不确定问题是什么,尽管您似乎将
bash
命令和变量与gnuplot
命令和变量混合在一起
为gnuplot
编写整个脚本:
#!/usr/local/bin/gnuplot -persist
set terminal png size 1200,800
set output 'result.png'
set title "Rate Distortion Curve"
set xlabel "bit rates"
set ylabel "psnr"
set grid
plot 'data' with lp
#!/bin/bash
# file is a bash variable set to the first parameter
file=$1
# now start gnuplot and pass variables and commands to it in a "heredoc"
gnuplot <<EOF
set terminal png size 1200,800
set output "$file"
set title "Rate Distortion Curve"
set xlabel "bit rates"
set ylabel "psnr"
set grid
plot 'data' with lp
EOF
或者,编写一个bash
脚本,将调用gnuplot
作为脚本的一个方面,允许您在启动gnuplot
之前灵活地处理参数和shell:
#!/usr/local/bin/gnuplot -persist
set terminal png size 1200,800
set output 'result.png'
set title "Rate Distortion Curve"
set xlabel "bit rates"
set ylabel "psnr"
set grid
plot 'data' with lp
#!/bin/bash
# file is a bash variable set to the first parameter
file=$1
# now start gnuplot and pass variables and commands to it in a "heredoc"
gnuplot <<EOF
set terminal png size 1200,800
set output "$file"
set title "Rate Distortion Curve"
set xlabel "bit rates"
set ylabel "psnr"
set grid
plot 'data' with lp
EOF
然后你可以用它运行
./plot output.png
它将创建一个名为output.png
的图像文件
在回答您的评论时,如果有两批数据要在同一轴上绘制,请使用以下命令-注意第一行末尾的逗号和斜杠:
plot "data.txt" using 1:2 with linespoints title 'time', \
"data.txt" using 1:3 with linespoints title 'size'
以上假设您的数据如下所示,分为3列:
10 1.32632 1.8897552
11 1.33474 1.9563009
12 1.37261 2.0283514
我尝试了第二种技巧。我创建了名为PSNR.sh的文件,并将所有代码放在那里。现在,我将调用并将数据传递给此?我已经添加了一些详细信息-请再看一看。嗨,我需要使用多行绘制多个数据。每一个都将用相同的x轴表示不同的参数。怎么做?@Tahir我在最后添加了更多细节。