Dynamically changing the range of a histogram in gnuplot?

≯℡__Kan透↙ 提交于 2019-12-25 16:47:44

问题


I have a c++ program that generates 10000 medians from sample data and outputs the medians to a file named "data.dat". I then modified this gnuplot script from here to generate a histogram:

reset
n=100 #number of intervals
max=500
min=0 #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
set term png #output terminal and file
set output "histogram.png"
set xrange [min:max]
set yrange [0:]
#to put an empty boundary around the
#data inside an autoscaled graph.
set offset graph 0.05,0.05,0.05,0.0
set xtics min,(max-min)/5,max
set boxwidth width*0.9
set style fill solid 0.5 #fillstyle
set tics out nomirror
set xlabel "Medians"
set ylabel "Frequency"
#count and plot
plot "data.dat" u (hist($1,width)):(1.0) smooth freq w boxes lc rgb"green" notitle

set xrange [GPVAL_DATA_X_MIN:GPVAL_DATA_X_MAX]
reset
replot

This script generates exactly what I want, except I need the ability to change the x range of the histogram. My C++ program asks the user for the upper boundary of sample data to use. Which means that the median data could be anywhere between 0 and whatever the user enters as the upper boundary. As you can see above, I have attempted to change the xrange of the data, but I haven't been able to get it to work. Even when I use GLPVAL_DATA and reset the xrange and replot the data, the histogram ranges never change. I just get the same xrange of 0 to 500 that the original graph outputted. What am I doing wrong here?

来源:https://stackoverflow.com/questions/21369409/dynamically-changing-the-range-of-a-histogram-in-gnuplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!