Skip to content

Commit

Permalink
Merge pull request #64 from gustaphe/master
Browse files Browse the repository at this point in the history
Bare units recipe
  • Loading branch information
gustaphe committed Aug 3, 2021
2 parents 5bf02fa + 759bf85 commit e832c12
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "UnitfulRecipes"
uuid = "42071c24-d89e-48dd-8a24-8a12d9b8861f"
authors = ["Benoit Pasquier", "Jan Weidner"]
version = "1.4.1"
version = "1.5.0"

[deps]
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Expand Down
7 changes: 7 additions & 0 deletions docs/lit/examples/1_Examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,10 @@ plot(t, U; xlabel="t", ylabel="U", st=:scatter, label="Samples")
plot!(model, t; st=:scatter, label="Noise removed")
plot!(model, u"s"; label="True function")

# ## Initializing empty plot
#
# A plot can be initialized with unitful axes but without datapoints by
# simply supplying the unit:

plot(u"m", u"s")
plot!([2u"ft"], [1u"minute"], st=:scatter)
6 changes: 6 additions & 0 deletions src/UnitfulRecipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ end
[fixaxis!(plotattributes, x, axisletter) for x in x]
end

# Recipe for bare units
@recipe function f(::Type{T}, x::T) where T <: Units
primary := false
Float64[]*x
end

# Recipes for functions
@recipe function f(f::Function, x::T) where T <: AVec{<:Union{Missing,<:Quantity}}
x, f.(x)
Expand Down
13 changes: 11 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ end
pl = plot(f, m)
@test xguide(pl) == string(m)
@test yguide(pl) == string(m^2)
f(x) = exp(x/(3m))
@test plot(f, u"m") isa Plots.Plot
g(x) = exp(x/(3m))
@test plot(g, u"m") isa Plots.Plot
end
end

Expand Down Expand Up @@ -236,6 +236,15 @@ end
@test_throws DimensionError plot!(plt, x3) # can't place seconds on top of meters!
end

@testset "Bare units" begin
plt = plot(u"m", u"s")
@test xguide(plt) == "m"
@test yguide(plt) == "s"
@test iszero(length(plt.series_list[1].plotattributes[:y]))
hline!(plt, [1u"hr"])
@test yguide(plt) == "s"
end

@testset "Inset subplots" begin
x1 = rand(10) * u"m"
x2 = rand(10) * u"s"
Expand Down

2 comments on commit e832c12

@gustaphe
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/42057

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.5.0 -m "<description of version>" e832c12c9e50b5f50f1ee35ac1eb1d208ee7e6c4
git push origin v1.5.0

Please sign in to comment.