Skip to content

Commit d98de3d

Browse files
authored
added fillrange (#67)
* added fillrange * ribbon and fillrange * simplified ribbon and fillrange calls * added examples * updated link to Plots examples
1 parent 465510a commit d98de3d

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "UnitfulRecipes"
22
uuid = "42071c24-d89e-48dd-8a24-8a12d9b8861f"
33
authors = ["Benoit Pasquier", "Jan Weidner"]
4-
version = "1.5.1"
4+
version = "1.5.2"
55

66
[deps]
77
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"

docs/lit/examples/2_Plots.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#md # These examples are available as Jupyter notebooks.
1010
#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!
1111

12-
# 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
12+
# 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
1313
# (they are essentially the same except we have added some units to the data).
1414

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

78+
79+
# ## Ribbons
80+
#
81+
# Ribbons can be added to lines via the `ribbon` keyword;
82+
# you can pass:
83+
#* a single Array (for symmetric ribbons)
84+
#* a Function
85+
#* or a number.
86+
#Currently unsupported: a tuple of arrays (upper and lower bounds)
87+
#
88+
x = y = (0:10)*u"m"
89+
plot(
90+
#plot((0:10)*u"m"; ribbon = (LinRange(0, 2, 11)*u"m", LinRange(0, 1, 11)*u"m")),
91+
plot(x,y; ribbon = (0:0.5:5)*u"m", label = "Vector"),
92+
plot(x,y; ribbon = sqrt, label = "Function"),
93+
plot(x,y; ribbon = 1u"m", label = "Constant"), link=:all
94+
)
95+
96+
# ## Fillrange
97+
# the fillrange keyword defines a second line and fills between it and the y data.
98+
# Note: ribbons are fillranges
99+
x = y = (0:10)*u"m"
100+
plot(
101+
plot(x,y; fillrange = (0:0.5:5)*u"m", label = "Vector"),
102+
plot(x,y; fillrange = sin, label = "Function"),
103+
plot(x,y; fillrange = 0u"m", label = "Constant"), link = :all
104+
)
105+
106+
78107
# ## Marker types
79108

80109
markers = intersect(Plots._shape_keys, Plots.supported_markers())

src/UnitfulRecipes.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ function fixaxis!(attr, x, axisletter)
4646
ustripattribute!(attr, axislims, u)
4747
ustripattribute!(attr, axisticks, u)
4848
ustripattribute!(attr, err, u)
49-
if (axisletter == :y) && haskey(attr, :ribbon)
49+
if (axisletter == :y)
5050
ustripattribute!(attr, :ribbon, u)
51+
ustripattribute!(attr, :fillrange, u)
5152
end
5253
fixmarkercolor!(attr)
5354
fixmarkersize!(attr)

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,16 @@ end
283283
@test yguide(plt) == "s"
284284
end
285285

286+
@testset "Fillrange" begin
287+
x = rand(10) * u"mm"
288+
y = rand(10) * u"s"
289+
fillrange = rand(10) * u"ms"
290+
plt = plot(x, y, fillrange=fillrange)
291+
@test plt isa Plots.Plot
292+
@test xguide(plt) == "mm"
293+
@test yguide(plt) == "s"
294+
end
295+
286296
# https://github.com/jw3126/UnitfulRecipes.jl/issues/60
287297
@testset "Start with empty plot" begin
288298
plt = plot()

0 commit comments

Comments
 (0)