-
-
Notifications
You must be signed in to change notification settings - Fork 358
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
Support for missing
in Plots
#1706
Comments
For the record, Float32 and NaN32 also work for PlotlyJS (but are then converted to double precision in the JSON, unfortunately). |
I agree with you @mkborregaard that passing on julia> using PyPlot
julia> y = [rand(9); missing]
10-element Array{Union{Missing, Float64},1}:
0.10054844974750021
0.5619977453885072
0.9352063939642001
0.013072160627248364
0.4219567494193299
0.633474807303148
0.6790561066713039
0.03835857053635672
0.596949167563924
missing
julia> plot(y)
ERROR: PyError ($(Expr(:escape, :(ccall(#= /home/dani/.julia/packages/PyCall/akNFy/src/pyfncall.jl:44 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'TypeError'>
TypeError("float() argument must be a string or a number, not 'PyCall.jlwrap'")
File "/usr/lib/python3.7/site-packages/matplotlib/pyplot.py", line 3363, in plot
ret = ax.plot(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/matplotlib/__init__.py", line 1867, in inner
return func(ax, *args, **kwargs)
File "/usr/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 1529, in plot
self.add_line(line)
File "/usr/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 1960, in add_line
self._update_line_limits(line)
File "/usr/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 1982, in _update_line_limits
path = line.get_path()
File "/usr/lib/python3.7/site-packages/matplotlib/lines.py", line 956, in get_path
self.recache()
File "/usr/lib/python3.7/site-packages/matplotlib/lines.py", line 657, in recache
y = _to_unmasked_float_array(yconv).ravel()
File "/usr/lib/python3.7/site-packages/matplotlib/cbook/__init__.py", line 2052, in _to_unmasked_float_array
return np.asarray(x, float)
File "/usr/lib/python3.7/site-packages/numpy/core/numeric.py", line 501, in asarray
return array(a, dtype, copy=False, order=order)
Stacktrace:
[1] pyerr_check at /home/dani/.julia/packages/PyCall/akNFy/src/exception.jl:60 [inlined]
[2] pyerr_check at /home/dani/.julia/packages/PyCall/akNFy/src/exception.jl:64 [inlined]
[3] macro expansion at /home/dani/.julia/packages/PyCall/akNFy/src/exception.jl:84 [inlined]
[4] __pycall!(::PyCall.PyObject, ::Ptr{PyCall.PyObject_struct}, ::PyCall.PyObject, ::Ptr{Nothing}) at /home/dani/.julia/packages/PyCall/akNFy/src/pyfncall.jl:44
[5] _pycall!(::PyCall.PyObject, ::PyCall.PyObject, ::Tuple{Array{Union{Missing, Float64},1}}, ::Int64, ::Ptr{Nothing}) at /home/dani/.julia/packages/PyCall/akNFy/src/pyfncall.jl:22
[6] #pycall#88 at /home/dani/.julia/packages/PyCall/akNFy/src/pyfncall.jl:11 [inlined]
[7] pycall at /home/dani/.julia/packages/PyCall/akNFy/src/pyfncall.jl:86 [inlined]
[8] #plot#85(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Array{Union{Missing, Float64},1}) at /home/dani/.julia/packages/PyPlot/tA0wP/src/PyPlot.jl:179
[9] plot(::Array{Union{Missing, Float64},1}) at /home/dani/.julia/packages/PyPlot/tA0wP/src/PyPlot.jl:176
[10] top-level scope at none:0 julia> using GR
julia> plot([rand(9); missing])
ERROR: expected Real or Complex
Stacktrace:
[1] #plot_args#6(::Symbol, ::Function, ::Tuple{Array{Union{Missing, Float64},1}}) at /home/dani/.julia/packages/GR/fnyt8/src/jlgr.jl:1038
[2] plot_args at /home/dani/.julia/packages/GR/fnyt8/src/jlgr.jl:964 [inlined]
[3] #plot#19(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Array{Union{Missing, Float64},1}) at /home/dani/.julia/packages/GR/fnyt8/src/jlgr.jl:1123
[4] plot at /home/dani/.julia/packages/GR/fnyt8/src/jlgr.jl:1118 [inlined]
[5] #plot#2 at /home/dani/.julia/packages/GR/fnyt8/src/GR.jl:2973 [inlined]
[6] plot(::Array{Union{Missing, Float64},1}) at /home/dani/.julia/packages/GR/fnyt8/src/GR.jl:2973
[7] top-level scope at none:0 We could still start a transition, by wrapping calls in |
I have just started learning Julia and this is something that it desperately needs in my opinion. Compare this to the simplicity of R:
|
sure. |
There's a WIP PR here: #1731 |
Merged. @abudis try |
@abudis just updating Plots should give you missing value support now, as we've tagged a release with the improvements. If you do use it a lot, it would be useful if you'd test it out and report back. |
@mkborregaard sorry I was offine for some time. Awesome! I'll test it asap! :D |
@mkborregaard works perfectly! Thanks for such a quick response! |
Good to hear! |
I'll keep the issue open, to remind us that this could be done more elegantly in the future. |
Lines 92 to 100 in bad5668
|
Any idea what's going on there? |
No, that's strange. |
Well... let me know if I can do anything to help resolve the problem, I'm pretty lost myself. |
I would like to propose that @recipe function f(coords::AbstractArray{Union{LLA{S},T}} where S<:Real where T<:Nothing;coord_projection=(lla->(lla.lon,lla.lat))) |
Hm, what part of the documentation do you mean? In the Missing Values section it reads
In the FAQ of the documentation you have
So from reading that it does look to me like
|
@karajan9 , you will have to forgive me that I got slighly lost in the context of this discussion. Ie. just general support of passing missing to the backends. The point that I was intending to make is that incases where |
Ah sorry, yes, I have completely misunderstood you 😄 |
Plots uses NaN under the hood, and missing gets converted to NaN. I don't see any problems adding support for converting Nothing to NaN in addition to the existing conversion, as there is no other obvious representation. So I'd be up for merging a PR implementing this. |
I confirmed this in my Julia 1.0 environment.If I place a
|
@BeastyBlacksmith I think this issue was taken care of recently with #2770 |
That PR just touched the documentation. What exactly did it fix? |
Plots doesn't yet support
missing
, which it should, since it's in Base.The current approach taken in StatPlots is to copy the inputs, replacing
missing
withNaN
forVector{<:Number}
(while converting toFloat64
),""
forString
input andSymbol()
forSymbol
input, then propagating that. It should be possible to do so for thex
,y
andz
arguments herePlots.jl/src/series.jl
Lines 75 to 88 in 602dbdf
Personally I think a cleaner approach is to provide first-class missings support in wrapping internal calls in Plots that may return
missing
inskipmissing
where relevant and just forward themissing
-containingVectors
to the backend and leave it to them to handle them. That makes sense sincemissing
is defined in Base, and as such a first-class Julia citizen. But it's more work and we don't know how well the backends handle them.@piever @daschw @SimonDanisch @pfitzseb @jheinen
The text was updated successfully, but these errors were encountered: