You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将rtl_power_fftw生成的Gnuplot绘图保存为PNG?解决报错问题

解决方案

方法一:调整Gnuplot命令顺序(直接命令行)

错误根源是replot执行时,Gnuplot还未处理管道传来的plot "-"命令,没有任何绘图数据可重绘。我们调整命令顺序,让Gnuplot先完成绘图,再执行保存操作:

rtl_power_fftw -f 900M:950M -n 10 -b 512 -q |
sed -u '/rtl-power-fftw/s/.*/ plot "-"/;/^$/{N;s/^$/e/}' |
gnuplot -p -e '
set term x11;
plot "-";
set term png;
set output "output.png";
replot;
set term x11;
set output;
'

方法二:临时文件中转数据(稳定性更高)

若管道时序问题导致异常,可先将处理后的绘图数据存入临时文件,再让Gnuplot读取:

# 生成处理后的绘图数据到临时文件
rtl_power_fftw -f 900M:950M -n 10 -b 512 -q |
sed -u '/rtl-power-fftw/s/.*/ plot "-"/;/^$/{N;s/^$/e/}' > temp_plot_data.txt

# 读取临时文件完成保存与显示
gnuplot -p -e '
set term png;
set output "output.png";
load "temp_plot_data.txt";
set term x11;
set output;
load "temp_plot_data.txt";
'

# 清理临时文件
rm temp_plot_data.txt

方法三:Bash脚本封装(方便复用)

将逻辑封装为脚本,支持自定义参数:

#!/bin/bash

# 可自定义参数
FREQ_RANGE="900M:950M"
NUM_SAMPLES=10
BINS=512
OUTPUT_PNG="rtl_power_output.png"

# 执行绘图与保存流程
rtl_power_fftw -f "$FREQ_RANGE" -n "$NUM_SAMPLES" -b "$BINS" -q |
sed -u '/rtl-power-fftw/s/.*/ plot "-"/;/^$/{N;s/^$/e/}' |
gnuplot -p -e "
set term x11;
plot \"-\";
set term png;
set output '$OUTPUT_PNG';
replot;
set term x11;
set output;
"

使用前给脚本添加执行权限:chmod +x rtl_plot_save.sh,运行即可:./rtl_plot_save.sh

内容的提问来源于stack exchange,提问作者gautudp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 17:40:06