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

在gnuplot绘图时,能否直接从原始数据中减去平滑后的数据?

Subtracting Smoothed Data from Original in Gnuplot

Absolutely—you don’t need external tools to do this! Gnuplot has built-in functionality to handle this operation directly. Here’s how to modify your existing command to plot the difference between your original sensor data and its acsplines-smoothed version:

Approach 1: Use a Temporary File for Smoothed Data

This is the most reliable method, compatible with most gnuplot versions. First, we’ll generate the smoothed data and save it to a temporary file, then calculate the difference by matching x-values between the original and smoothed datasets:

# First, capture the smoothed data to a temporary file
set table 'temp_smooth.dat'
plot ["17.12.2020 08:00:00":"18.12.2020 20:00:00"] 'data3-17-28.csv1' using 4:5 smooth acsplines
unset table

# Configure time formatting for your x-axis (since your x is a timestamp)
set xdata time
set timefmt "%d.%m.%Y %H:%M:%S"
set format x "%d.%m %H:%M"  # Adjust this to your preferred display format

# Plot original, smoothed, and their difference
plot ["17.12.2020 08:00:00":"18.12.2020 20:00:00"] \
     'data3-17-28.csv1' using 4:5 title 'Sensor 3' with lines lc rgb '#0066ff', \
     'temp_smooth.dat' using 1:2 title 'Smoothed' with lines lc rgb '#ff3333', \
     '< join data3-17-28.csv1 temp_smooth.dat' using 1:($2 - $4) title 'Original - Smoothed' with lines lc rgb '#00cc66'

The join command merges the original and smoothed files by their x-values (assuming both are sorted chronologically, which your timestamp data should be). The $2 - $4 calculates the difference between the original y-value (column 2 of the merged output) and the smoothed y-value (column 4).

Approach 2: Use an In-Memory Data Block (Gnuplot 5.0+)

If you’re using gnuplot 5.0 or later, you can avoid creating a physical temporary file by storing the smoothed data in an in-memory data block:

# Save smoothed data to an in-memory block named $SMOOTHED
set table $SMOOTHED
plot ["17.12.2020 08:00:00":"18.12.2020 20:00:00"] 'data3-17-28.csv1' using 4:5 smooth acsplines
unset table

# Configure time formatting
set xdata time
set timefmt "%d.%m.%Y %H:%M:%S"
set format x "%d.%m %H:%M"

# Plot the datasets and their difference
plot ["17.12.2020 08:00:00":"18.12.2020 20:00:00"] \
     'data3-17-28.csv1' using 4:5 title 'Sensor 3' with lines, \
     $SMOOTHED using 1:2 title 'Smoothed' with lines, \
     '< join data3-17-28.csv1 <(echo "$SMOOTHED")' using 1:($2 - $4) title 'Original - Smoothed' with lines

This works similarly to the first method, but uses a data block instead of a file, keeping your workspace clean.

Key Notes:

  • Ensure your original data is sorted by the x-axis (timestamp) for join to work correctly.
  • If you don’t need to plot the original and smoothed datasets separately, you can omit those lines and only plot the difference.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 08:33:04