Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axis failure with log xscale #833

Closed
mkborregaard opened this issue May 16, 2017 · 13 comments
Closed

Axis failure with log xscale #833

mkborregaard opened this issue May 16, 2017 · 13 comments
Labels

Comments

@mkborregaard
Copy link
Member

mkborregaard commented May 16, 2017

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 :-)

@oschulz
Copy link
Contributor

oschulz commented May 17, 2017

@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))

@mkborregaard
Copy link
Member Author

mkborregaard commented May 17, 2017

I played with it for an hour or 2 today - this #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.

@oschulz
Copy link
Contributor

oschulz commented May 20, 2017

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(...)).

@mkborregaard
Copy link
Member Author

quite so

@mkborregaard
Copy link
Member Author

Maybe this could be helped by simply replacing 0 with NaN for the log scales.

@oschulz
Copy link
Contributor

oschulz commented May 4, 2018

Sorry this has been stale for so long - I'll try to get on it, again.

@mkborregaard
Copy link
Member Author

Yuhuu :-)
It appears I've had the 0 -> NaN idea before: #1261
But then we've also talked about #1212 which is important too IMHO.
Also relevant, for completeness, #920

@mkborregaard
Copy link
Member Author

cf #1864

@mkborregaard
Copy link
Member Author

@oschulz last time I bumped this issue was two years ago, so I hope it's OK I bump it again?

@oschulz
Copy link
Contributor

oschulz commented Feb 29, 2020

Oh, yes, definitely!

@mkborregaard
Copy link
Member Author

So you're going to remote-fix it at the vizcon?

@oschulz
Copy link
Contributor

oschulz commented Mar 1, 2020

Haha, not sure - I recently god some additional manpower though, so maybe I can delegate it. :-)

@t-bltg
Copy link
Member

t-bltg commented Jul 6, 2021

I think I got it fixed with #3619, can't reproduce.

@t-bltg t-bltg closed this as completed Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants