I know how to create a histogram (just use "with boxes") in gnuplot if my .dat file already has properly binned data. Is there a way to take a list of numbers and have gnuplot provide a histogram based on ranges and bin sizes the user provides?
相关问题
- How to set a variable line width when plotting?
- How to create PNG images with more than 72dpi usin
- Very low p-values in Python Kolmogorov-Smirnov Goo
- numpy beginner: writing an array using numpy.savet
- Gnuplot: how to have some space between axes and p
相关文章
- histogram without vertical lines in Mathematica
- Get data points from a histogram in Python
- Matplotlib.pyplot.hist() very slow
- Gnuplot - Using replot with png terminal
- Plotting histograms in Python using pandas
- Gnuplot multiplot with one colorbox
- Most efficient histogram code in python
- Binning time series in R?
With respect to binning functions, I didn't expect the result of the functions offered so far. Namely, if my binwidth is 0.001, these functions were centering the bins on 0.0005 points, whereas I feel it's more intuitive to have the bins centered on 0.001 boundaries.
In other words, I'd like to have
The binning function I came up with is
Here's a script to compare some of the offered bin functions to this one:
and here's the output
I have a couple corrections/additions to Born2Smile's very useful answer:
set boxwidth binwidth
bin
function:bin(x,width)=width*floor(x/width) + width/2.0
I have a little modification to Born2Smile's solution.
I know that doesn't make much sense, but you may want it just in case. If your data is integer and you need a float bin size (maybe for comparison with another set of data, or plot density in finer grid), you will need to add a random number between 0 and 1 inside floor. Otherwise, there will be spikes due to round up error.
floor(x/width+0.5)
will not do because it will create pattern that's not true to original data.