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

Plots.jl compatibility with SIUnits.jl #427

Closed
ChrisRackauckas opened this issue Aug 2, 2016 · 4 comments
Closed

Plots.jl compatibility with SIUnits.jl #427

ChrisRackauckas opened this issue Aug 2, 2016 · 4 comments

Comments

@ChrisRackauckas
Copy link
Member

Currently Plots.jl is not compatible with SIUnits.jl:

julia> sol[:]
17-element Array{SIUnits.SIQuantity{Float64,1,1,-2,0,0,0,0,0,0},1}:
     1.5 kg m s⁻²
 1.54688 kg m s⁻²
 1.59521 kg m s⁻²
 1.64507 kg m s⁻²
 1.69647 kg m s⁻²
 1.74949 kg m s⁻²
 1.80416 kg m s⁻²
 1.86054 kg m s⁻²
 1.91868 kg m s⁻²
 1.97864 kg m s⁻²
 2.04047 kg m s⁻²
 2.10424 kg m s⁻²
    2.17 kg m s⁻²
 2.23781 kg m s⁻²
 2.30774 kg m s⁻²
 2.37986 kg m s⁻²
 2.45423 kg m s⁻²

julia> plot(1:length(sol[:]),sol[:])
ERROR: MethodError: no method matching isless(::Float64, ::SIUnits.SIQuantity{Float64,1,1,-2,0,0,0,0,0,0})
Closest candidates are:
  isless(::Float64, ::Float64) at float.jl:281
  isless(::AbstractFloat, ::AbstractFloat) at operators.jl:35
  isless(::Real, ::AbstractFloat) at operators.jl:36
  ...
 in expand_extrema!(::Plots.Extrema, ::SIUnits.SIQuantity{Float64,1,1,-2,0,0,0,0,0,0}) at /home/crackauc/.julia/v0.5/Plots/src/axes.jl:216
 in expand_extrema!(::Plots.Axis, ::Array{SIUnits.SIQuantity{Float64,1,1,-2,0,0,0,0,0,0},1}) at /home/crackauc/.julia/v0.5/Plots/src/axes.jl:239
 in expand_extrema!(::Plots.Subplot{Plots.GRBackend}, ::Dict{Symbol,Any}) at /home/crackauc/.julia/v0.5/Plots/src/axes.jl:255
 in _expand_subplot_extrema(::Plots.Subplot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Symbol) at /home/crackauc/.julia/v0.5/Plots/src/pipeline.jl:351
 in _process_seriesrecipe(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}) at /home/crackauc/.julia/v0.5/Plots/src/pipeline.jl:381
 in _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{UnitRange{Int64},Array{SIUnits.SIQuantity{Float64,1,1,-2,0,0,0,0,0,0},1}}) at /home/crackauc/.julia/v0.5/Plots/src/plot.jl:204
 in #plot#232(::Array{Any,1}, ::Function, ::UnitRange{Int64}, ::Vararg{Any,N}) at /home/crackauc/.julia/v0.5/Plots/src/plot.jl:52
 in plot(::UnitRange{Int64}, ::Array{SIUnits.SIQuantity{Float64,1,1,-2,0,0,0,0,0,0},1}, ::Vararg{Array{SIUnits.SIQuantity{Float64,1,1,-2,0,0,0,0,0,0},1},N}) at /home/crackauc/.julia/v0.5/Plots/src/plot.jl:46
 in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
 in macro expansion at ./REPL.jl:95 [inlined]
 in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:46

However, if you strip the values of their units

julia> plot(map((x)->x.val,sol[:]),sol.t) 

This works. (If you find a way to type check this and strip the units without adding the dependency, I'd be interested in something similar).

@tbreloff
Copy link
Member

tbreloff commented Aug 2, 2016

Can't you just add type recipes for this?

@ChrisRackauckas
Copy link
Member Author

Oh true, didn't think about that.

@ChrisRackauckas
Copy link
Member Author

ChrisRackauckas commented Aug 27, 2016

Hey, I got the basic recipe together:

@recipe function f{ND,N,m,kg,s,A,K,mol,cd,rad,sr}(::Type{Array{SIUnits.SIQuantity{N,m,kg,s,A,K,mol,cd,rad,sr},ND}},x::Array{SIUnits.SIQuantity{N,m,kg,s,A,K,mol,cd,rad,sr},ND})
 map((y)->y.val,x)
end

However, I am wondering how I would add the axis to it. I can get a string for the units using SIUnits.unit(u[1]), so I was wondering how the recipe could pass that on as the guide for the position it's in. For example:

using SIUnits.ShortUnits
u = [1.0N 1.0N
     1.0N 1.2N
     1.5N 1.7N]

x = [1 1
     2 2
     3 3]

plot(x,u) # Works on all backends

I would like to have SIUnits.unit(u[1]) (which returns "kg m s^-2") to be the yguide (but if u and x were flipped, make it the xguide)

@ChrisRackauckas
Copy link
Member Author

Superseded by #460.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants