2016-11-30 22 views
0

我在一個文件中有一些數據,其中x在[2,4]中。使用replot時的繪圖截止

我把它們中的一些,用於x的[2.5, 3.5],放在一個新的文件中,然後我只適合第二個文件。

然後,我繪製第一個文件,包含所有數據,並重新繪製擬合函數。

通過這種方式,擬合函數在[2,4]繪製x但可怕的,因爲它不會在[2, 2.5][3, 3.5]適合。

所以我想只有在正確的範圍有這個擬合函數的情節,但gnuplot不允許我使用replot時設置特定的x範圍。

那麼,我怎樣才能獲得所有的數據,但只有在合適的功能,只有在一個獨特的陰謀的右側區域?

回答

0

將擬合函數放入數據文件中,然後將此數據文件與原始數據一起繪製。

# This is the complete xrange 
set xrange [-2:2] 

# This creates some test data to play with 
set table "data.txt" 
plot sin(x) 
unset table 


# Fit some of the created data points 
f(x) = a*x + b 
fit [-0.5:0.5] f(x) "data.txt" via a, b 

# Plot the fit function to a temporary file 
# Note, only the xrange of the fit is used 
set table "fit.dat" 
plot [-0.5:0.5] f(x) 
unset table 


# Plot both datafiles in one diagram 
plot "data.txt" w l, "fit.dat" w l lw 4 
+0

非常感謝! –

相關問題