【问题标题】:Error "xrange is invalid" when trying to plot an histogram with Gnuplot尝试使用 Gnuplot 绘制直方图时出现错误“xrange 无效”
【发布时间】:2021-07-13 15:06:28
【问题描述】:

我想用 Gnuplot 绘制一个直方图,我有以下代码:

n=100 #number of intervals
max=31 #max value
min=22  #min value
width=(max-min)/n #interval width
#function used to map a value to the intervals
hist(x,width)=width*floor(x/width)+width/2.0

GNUTERM = "x11"
set terminal postscript enhanced color
set output "histo.ps"
plot "file_log" u (hist($1,width)):(1.0) smooth freq w boxes lc rgb "blue" notitle

通常这段代码运行良好,但现在我得到了一个

"histo.gnu", line 48: warning: Skipping data file with no valid points

plot "file_log" u (hist($1,width)):(1.0) smooth freq w boxes lc rgb "blue" notitle 
                                                                                       ^
"histo.gnu", line 48: x range is invalid

我真的不明白为什么,因为文件中的值确实在 22 到 31 之间……知道吗?

【问题讨论】:

  • 错误行似乎不是第 48 行。您是否还有一些未显示的代码?如果您在开头添加resetreset session 可能会有所帮助吗?
  • 是的,但我认为这些行不相关......第 48 行对应于以“Plot”开头的行。我试过reset 但它没有改变,reset session 给了我"histo.gnu", line 13: warning: expected optional axis name

标签: gnuplot histogram


【解决方案1】:

错误是这一行

width=(max-min)/n #interval width

由于 max、min 和 n 都是整数 gnuplot 使用整数运算,因此 11/100 = 0。您可以通过说 width=real(max-min)/n 来修复它,或者确保限制值是实数:

n=100 #number of intervals
max=31.0 #max value
min=22.0  #min value
width=(max-min)/n #interval width

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-25
    • 2021-08-23
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多