Skip to content

Commit

Permalink
added fillrange (#67)
Browse files Browse the repository at this point in the history
* added fillrange

* ribbon and fillrange
* simplified ribbon and fillrange calls
* added examples
* updated link to Plots examples
  • Loading branch information
DanDeepPhase authored Oct 30, 2021
1 parent 465510a commit d98de3d
Show file tree
Hide file tree
Showing 4 changed files with 43 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.5.1"
version = "1.5.2"

[deps]
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Expand Down
31 changes: 30 additions & 1 deletion docs/lit/examples/2_Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#md # These examples are available as Jupyter notebooks.
#md # You can execute them online with [binder](https://mybinder.org/) or just view them with [nbviewer](https://nbviewer.jupyter.org/) by clicking on the badges above!

# These examples were slightly modified from some of [the GR examples in the Plots.jl documentation](http://docs.juliaplots.org/latest/examples/gr/) and can be used as both a tutorial or as a series of test for the UnitfulRecipes package
# These examples were slightly modified from some of [the examples in the Plots.jl documentation](https://github.com/JuliaPlots/Plots.jl/blob/master/src/examples.jl) and can be used as both a tutorial or as a series of test for the UnitfulRecipes package
# (they are essentially the same except we have added some units to the data).

# First we need to tell Julia we are using Plots, Unitful, and UnitfulRecipes
Expand Down Expand Up @@ -75,6 +75,35 @@ n = length(styles)
y = cumsum(randn(20, n), dims=1) * u"km"
plot(y, line=(5, styles), label=map(string, styles), legendtitle="linestyle")


# ## Ribbons
#
# Ribbons can be added to lines via the `ribbon` keyword;
# you can pass:
#* a single Array (for symmetric ribbons)
#* a Function
#* or a number.
#Currently unsupported: a tuple of arrays (upper and lower bounds)
#
x = y = (0:10)*u"m"
plot(
#plot((0:10)*u"m"; ribbon = (LinRange(0, 2, 11)*u"m", LinRange(0, 1, 11)*u"m")),
plot(x,y; ribbon = (0:0.5:5)*u"m", label = "Vector"),
plot(x,y; ribbon = sqrt, label = "Function"),
plot(x,y; ribbon = 1u"m", label = "Constant"), link=:all
)

# ## Fillrange
# the fillrange keyword defines a second line and fills between it and the y data.
# Note: ribbons are fillranges
x = y = (0:10)*u"m"
plot(
plot(x,y; fillrange = (0:0.5:5)*u"m", label = "Vector"),
plot(x,y; fillrange = sin, label = "Function"),
plot(x,y; fillrange = 0u"m", label = "Constant"), link = :all
)


# ## Marker types

markers = intersect(Plots._shape_keys, Plots.supported_markers())
Expand Down
3 changes: 2 additions & 1 deletion src/UnitfulRecipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ function fixaxis!(attr, x, axisletter)
ustripattribute!(attr, axislims, u)
ustripattribute!(attr, axisticks, u)
ustripattribute!(attr, err, u)
if (axisletter == :y) && haskey(attr, :ribbon)
if (axisletter == :y)
ustripattribute!(attr, :ribbon, u)
ustripattribute!(attr, :fillrange, u)
end
fixmarkercolor!(attr)
fixmarkersize!(attr)
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ end
@test yguide(plt) == "s"
end

@testset "Fillrange" begin
x = rand(10) * u"mm"
y = rand(10) * u"s"
fillrange = rand(10) * u"ms"
plt = plot(x, y, fillrange=fillrange)
@test plt isa Plots.Plot
@test xguide(plt) == "mm"
@test yguide(plt) == "s"
end

# https://github.com/jw3126/UnitfulRecipes.jl/issues/60
@testset "Start with empty plot" begin
plt = plot()
Expand Down

2 comments on commit d98de3d

@briochemc
Copy link
Collaborator

Choose a reason for hiding this comment

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

@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/47773

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.2 -m "<description of version>" d98de3d0a853a790364c02ca606e6a6a8c28a640
git push origin v1.5.2

Also, note the warning: Version 1.5.2 skips over 1.5.1
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

Please sign in to comment.