2

I am using gnuplot version 4.6, patch level 3 on a windows 8 machine, terminal set to wxt.

The file results.csv has a list of energies varying with radius of a sphere. I am using Gnuplot to produce a graph in order to show the trend.

Unfortunately, due to what can only be described as 'numerical instabilities' within the program that was used to compute these energies, results.csv includes anomalous results. Thus plotting results.csv with:

set datafile separator “,”
set title “Oxygen3 Point Vacancy Defect Energy Variation with \n Radius of Region I in Mott-Littleton Defect Model”
set xlabel ‘Radius of Region I (Å)’
set ylabel ‘Defect Energy (eV)’
set grid
unset key
set border 3
set xtics border nomirror outwards
set ytics border nomirror outwards
set format y '%.2f'
plot ‘results.csv’ using 2:4 smooth unique with linespoints lw 3 lc rgb ‘black’

gives the following graph: enter image description here

[N.B. I have reduced the number of datalines for this example]

As I want the overall trend, I want to skip the point at radius = 16. However, changing my plot command to:

plot 'results.csv' using 2: ($4 > 20 ? $4 : 1/0) smooth unique with linespoints lw 3 lc rgb 'black'

results in: enter image description here

Has anyone got any suggestions as to what is making gnuplot connect the x=9 point to x=17 and how to overcome this problem.

Also, how do I skip the anomalous data point when I try and fit a 'line of best fit'?

Any help would be much appreciated

4

1 回答 1

1

绘图时忽略异常点

原则上,gnuplot已知

  1. missing点,可以用 设置set datafile missing。这些点在绘图期间会被跳过,不会影响线图。
  2. undefined点,如1/0。这些点也被跳过,但线图在这里被打断。

不幸的是,当涉及计算(例如您的情况下的过滤)时,无法使用丢失的数据点,请参见例如在 gnuplot 中,“set datafile missing”,如何忽略“nan”和“-nan”?.

因此,最好的方法是使用外部工具来过滤数据:

plot '< awk ''{ if ($4 > 20) print }'' results.csv' using 2:4 smooth unique

但这要求进行平均的每个点都满足这个标准。

拟合时忽略异常点

关于在拟合过程中忽略异常点,我最近给出了一个答案Ignore points far away from mean gnuplot

我认为你可以在没有平滑的情况下进行拟合,可能比先平滑然后拟合更好。拟合平滑数据将忽略单个数据点的分布,以及单个数据点更好/更差的保真度。

如果您仍想使用平滑后的数据,则必须先将它们写入临时文件,因为smooth unique不能与fit:

set output '| head -n -2 > results.tmp'
set table
plot '< awk ''{ if ($4 > 20) print }'' results.csv' using 2:4 smooth unique
unset table

关于这set output部分,请参阅为什么 Gnuplot 中的“设置表”选项会重写最后一行的第一个条目?.

于 2013-10-22T07:17:06.953 回答