Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
log-axis of histogram handles missing bins badly #210
In every histogramming package I've used (several for high energy physics), log scales are easily obtained as options on histograms.
After a fair amount of digging, I managed to figure out how to set log scale for the Y axis in histograms. However, this behaves very badly in the case where some bins are missing entries.
The correct behavior IMO is to leave out the missing bin, but not to make the Y axis go crazy as shown in the attached. In other words, the maximum value for Y in this case should be 3 (there are three 1s); the 5 bin should be empty; and there should be a value of 1 for 3, 4 and 6.
Correct handling of logarithmic scales for histograms is actually a fairly important feature for a statistical package, IMO.
In case it's helpful, though it's a bit kludgy, the following works:
You complain about two things that are worth a discussion: 1) how to make log-axis easily available through the API so that people don't need to search for it and 2) how to handle display of missing bins; let me focus on nr. 2.
Since Incanter is here only a wrapper around JFreeCharts, to find the best solution we would need to understand JFC well, which I do not :-( However, looking at its API and playing with it a little, I found this somewht better workaround:
(let [values (concat [1 2 1 2 3 1 2 4] (repeat 100 6)) hist (histogram values :nbins 6) axis (doto (log-axis) (.setSmallestValue 0.1))] ;; workaround: setSmallestValue > 0 (set-axis hist :y axis) (view hist))
However I still do not know what would be the prefered solution.
PS: Notice that we use LogAxis while JFC also has
Thanks for the detailed reply on this.
In another project I set the minimum to 0.5 by default. I like the
I definitely agree that D3 is much nicer to work with than JFC! :-)
pushed a commit
Jan 9, 2014
I think that setting smallest0value by default is reasonable, pull req.send.
If family permits, I'd like to look into enhancing histogram. But I'd prefer it more generic then you propose, to be able to choose also other types of axis (is it meaningful?) and to supply more options.
(histogram :y-axis :logarithmic) ; optional, minimal syntax, abbrev. for this below: (histogram :y-axis [:type :logarithmic, :base 10, :int-ticks? true, :smallest-value 0.5]) ; full syntax w/ vector w/ type + opts ;; altern. design, less declarative, more flexible: (histogram :y-axis (log-axis :base 10, :int-ticks? true, :smallest-value 0.5))
On Jan 9, 2014, at 9:25 AM, Jakub Holy firstname.lastname@example.org wrote: