If I try
using Plots
histogram(abs(randn(100)), xscale = :log10)
I get
INFO: binning = auto
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: DomainError:
in nan_dom_err at ./math.jl:196 [inlined]
in log10(::Float64) at ./math.jl:202
in (::Plots.##114#115{Symbol})(::Float64) at /Users/michael/.julia/v0.5/Plots/src/axes.jl:148
in optimal_ticks_and_labels(::Plots.Axis, ::Void) at /Users/michael/.julia/v0.5/Plots/src/axes.jl:186
in get_ticks(::Plots.Axis) at /Users/michael/.julia/v0.5/Plots/src/axes.jl:229
in tick_padding(::Plots.Axis) at /Users/michael/.julia/v0.5/Plots/src/backends.jl:71
in _update_min_padding!(::Plots.Subplot{Plots.GRBackend}) at /Users/michael/.julia/v0.5/Plots/src/backends.jl:104
in _collect(::Array{Plots.AbstractLayout,2}, ::Base.Generator{Array{Plots.AbstractLayout,2},Plots.#_update_min_padding!}, ::Base.EltypeUnknown, ::Base.HasShape) at ./array.jl:320
in _update_min_padding!(::Plots.GridLayout) at /Users/michael/.julia/v0.5/Plots/src/layouts.jl:302
in prepare_output(::Plots.Plot{Plots.GRBackend}) at /Users/michael/.julia/v0.5/Plots/src/plot.jl:254
in display at /Users/michael/.julia/v0.5/Plots/src/output.jl:133 [inlined]
in gui at /Users/michael/.julia/v0.5/Plots/src/output.jl:123 [inlined]
in display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::MIME{Symbol("text/plain")}, ::Plots.Plot{Plots.GRBackend}) at /Users/michael/.julia/v0.5/Plots/src/output.jl:138
in display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::Plots.Plot{Plots.GRBackend}) at ./REPL.jl:135
in display(::Plots.Plot{Plots.GRBackend}) at ./multimedia.jl:143
in print_response(::Base.Terminals.TTYTerminal, ::Any, ::Void, ::Bool, ::Bool, ::Void) at ./REPL.jl:154
in print_response(::Base.REPL.LineEditREPL, ::Any, ::Void, ::Bool, ::Bool) at ./REPL.jl:139
in (::Base.REPL.##22#23{Bool,Base.REPL.##33#42{Base.REPL.LineEditREPL,Base.REPL.REPLHistoryProvider},Base.REPL.LineEditREPL,Base.LineEdit.Prompt})(::Base.LineEdit.MIState, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Bool) at ./REPL.jl:652
in run_interface(::Base.Terminals.TTYTerminal, ::Base.LineEdit.ModalInterface) at ./LineEdit.jl:1579
in run_interface(::Base.Terminals.TTYTerminal, ::Base.LineEdit.ModalInterface) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
in run_frontend(::Base.REPL.LineEditREPL, ::Base.REPL.REPLBackendRef) at ./REPL.jl:903
in run_repl(::Base.REPL.LineEditREPL, ::Base.##950#951) at ./REPL.jl:188
in _start() at ./client.jl:363
in _start() at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
The problem seems to be that Plots seeks to automatically widen the x axis, which means that the left x axis limit (amin here : https://github.com/JuliaPlots/Plots.jl/blob/master/src/axes.jl#L186) becomes negative. Here, amin is axis_limits(axis)[1] and sf is the function log10.
@oschulz that little fix on log scales on axes turned out to bring a lot with it – which is probably one of the reasons it didn't work before. But it will be so awesome when it finally works :-)
@mkborregaard yes, I think at some point something will have to be done to improve the automatic axis limits. But that'll have to be recipe-independent, on a deeper level, I think.
For now, this works:
histogram(abs(randn(100)), xscale = :log10, xlims = (0.001, 10))
I played with it for an hour or 2 today - this https://github.com/JuliaPlots/Plots.jl/pull/835 doesn't solve the problem but adresses the general issue of widening, which is now only turned on for scatter seriestypes, and not for log scales.
With regard to this issue here, I think where it should be adressed is to allow the Histogram to be fit to the scale-transformed values - so that users specifying xscale = :log10 will se an even-binned histogram, similar to what you'd get with histogram(log(abs(randn(100))) in the above case. I think that'd fail on normalized histograms, though.
so that users specifying xscale = :log10 will se an even-binned histogram [,,,] I think that'd fail on normalized histograms, though.
At leat if they only specify the number of bins, instead of giving a precise binning specification. I like the idea, I can implement that fairly easily, I think. I don't think normalization would be a problem - the histogram would be normalized regarding it's integral in linear space, of course. But I think if the user wants the normalization to be done with the log values of the x-axis, they actually should do histogram(log10(...)).
quite so
Maybe this could be helped by simply replacing 0 with NaN for the log scales.
Sorry this has been stale for so long - I'll try to get on it, again.
Yuhuu :-)
It appears I've had the 0 -> NaN idea before: https://github.com/JuliaPlots/Plots.jl/issues/1261
But then we've also talked about https://github.com/JuliaPlots/Plots.jl/issues/1212 which is important too IMHO.
Also relevant, for completeness, https://github.com/JuliaPlots/Plots.jl/issues/920
cf #1864
@oschulz last time I bumped this issue was two years ago, so I hope it's OK I bump it again?
Oh, yes, definitely!
So you're going to remote-fix it at the vizcon?
Haha, not sure - I recently god some additional manpower though, so maybe I can delegate it. :-)
Most helpful comment
At leat if they only specify the number of bins, instead of giving a precise binning specification. I like the idea, I can implement that fairly easily, I think. I don't think normalization would be a problem - the histogram would be normalized regarding it's integral in linear space, of course. But I think if the user wants the normalization to be done with the log values of the x-axis, they actually should do
histogram(log10(...)).