Skip to content

Commit

Permalink
rename p = plot -> pl = plot
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Jul 14, 2022
1 parent 9f73560 commit dcee6db
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 307 deletions.
4 changes: 2 additions & 2 deletions test/test_animations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ end
end

@testset "html" begin
p = plot([sin, cos], zeros(0), leg = false, xlims = (0, 2π), ylims = (-1, 1))
pl = plot([sin, cos], zeros(0), leg = false, xlims = (0, 2π), ylims = (-1, 1))
anim = Animation()
for x in range(0, stop = 2π, length = 10)
push!(p, x, Float64[sin(x), cos(x)])
push!(pl, x, Float64[sin(x), cos(x)])
frame(anim)
end

Expand Down
106 changes: 53 additions & 53 deletions test/test_axes.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@testset "Axes" begin
p = plot()
axis = p.subplots[1][:xaxis]
pl = plot()
axis = pl.subplots[1][:xaxis]
@test typeof(axis) == Plots.Axis
@test Plots.discrete_value!(axis, "HI") == (0.5, 1)
@test Plots.discrete_value!(axis, :yo) == (1.5, 2)
Expand Down Expand Up @@ -39,9 +39,9 @@ end
ticks2 = ([4, 5], ("e", "f"))
p1 = plot(1:5, 1:5, 1:5, xticks = ticks1, yticks = ticks1, zticks = ticks1)
p2 = plot(1:5, 1:5, 1:5, xticks = ticks2, yticks = ticks2, zticks = ticks2)
p = plot(p1, p2)
@test xticks(p) == yticks(p) == zticks(p) == [ticks1, ticks2]
@test xticks(p[1]) == yticks(p[1]) == zticks(p[1]) == ticks1
pl = plot(p1, p2)
@test xticks(pl) == yticks(pl) == zticks(pl) == [ticks1, ticks2]
@test xticks(pl[1]) == yticks(pl[1]) == zticks(pl[1]) == ticks1
end

@testset "Axis limits" begin
Expand Down Expand Up @@ -80,55 +80,55 @@ end
@test haskey(Plots._keyAliases, :xguideposition)
@test haskey(Plots._keyAliases, :x_guide_position)
@test !haskey(Plots._keyAliases, :xguide_position)
p = plot(1:2, xl = "x label")
@test p[1][:xaxis][:guide] === "x label"
p = plot(1:2, xrange = (0, 3))
@test xlims(p) === (0, 3)
p = plot(1:2, xtick = [1.25, 1.5, 1.75])
@test p[1][:xaxis][:ticks] == [1.25, 1.5, 1.75]
p = plot(1:2, xlabelfontsize = 4)
@test p[1][:xaxis][:guidefontsize] == 4
p = plot(1:2, xgα = 0.07)
@test p[1][:xaxis][:gridalpha] 0.07
p = plot(1:2, xgridls = :dashdot)
@test p[1][:xaxis][:gridstyle] === :dashdot
p = plot(1:2, xgridcolor = :red)
@test p[1][:xaxis][:foreground_color_grid] === RGBA{Float64}(1.0, 0.0, 0.0, 1.0)
p = plot(1:2, xminorgridcolor = :red)
@test p[1][:xaxis][:foreground_color_minor_grid] === RGBA{Float64}(1.0, 0.0, 0.0, 1.0)
p = plot(1:2, xgrid_lw = 0.01)
@test p[1][:xaxis][:gridlinewidth] 0.01
p = plot(1:2, xminorgrid_lw = 0.01)
@test p[1][:xaxis][:minorgridlinewidth] 0.01
p = plot(1:2, xtickor = :out)
@test p[1][:xaxis][:tick_direction] === :out
pl = plot(1:2, xl = "x label")
@test pl[1][:xaxis][:guide] === "x label"
pl = plot(1:2, xrange = (0, 3))
@test xlims(pl) === (0, 3)
pl = plot(1:2, xtick = [1.25, 1.5, 1.75])
@test pl[1][:xaxis][:ticks] == [1.25, 1.5, 1.75]
pl = plot(1:2, xlabelfontsize = 4)
@test pl[1][:xaxis][:guidefontsize] == 4
pl = plot(1:2, xgα = 0.07)
@test pl[1][:xaxis][:gridalpha] 0.07
pl = plot(1:2, xgridls = :dashdot)
@test pl[1][:xaxis][:gridstyle] === :dashdot
pl = plot(1:2, xgridcolor = :red)
@test pl[1][:xaxis][:foreground_color_grid] === RGBA{Float64}(1.0, 0.0, 0.0, 1.0)
pl = plot(1:2, xminorgridcolor = :red)
@test pl[1][:xaxis][:foreground_color_minor_grid] === RGBA{Float64}(1.0, 0.0, 0.0, 1.0)
pl = plot(1:2, xgrid_lw = 0.01)
@test pl[1][:xaxis][:gridlinewidth] 0.01
pl = plot(1:2, xminorgrid_lw = 0.01)
@test pl[1][:xaxis][:minorgridlinewidth] 0.01
pl = plot(1:2, xtickor = :out)
@test pl[1][:xaxis][:tick_direction] === :out
end

@testset "Aliases" begin
compare(p::Plot, s::Symbol, val, op) =
op(p[1][:xaxis][s], val) && op(p[1][:yaxis][s], val) && op(p[1][:zaxis][s], val)
p = plot(1:2, guide = "all labels")
@test compare(p, :guide, "all labels", ===)
p = plot(1:2, label = "test")
@test compare(p, :guide, "", ===)
p = plot(1:2, lim = (0, 3))
@test xlims(p) === ylims(p) === zlims(p) === (0, 3)
p = plot(1:2, tick = [1.25, 1.5, 1.75])
@test compare(p, :ticks, [1.25, 1.5, 1.75], ==)
p = plot(1:2, labelfontsize = 4)
@test compare(p, :guidefontsize, 4, ==)
p = plot(1:2, gα = 0.07)
@test compare(p, :gridalpha, 0.07, )
p = plot(1:2, gridls = :dashdot)
@test compare(p, :gridstyle, :dashdot, ===)
p = plot(1:2, gridcolor = :red)
@test compare(p, :foreground_color_grid, RGBA{Float64}(1.0, 0.0, 0.0, 1.0), ===)
p = plot(1:2, minorgridcolor = :red)
@test compare(p, :foreground_color_minor_grid, RGBA{Float64}(1.0, 0.0, 0.0, 1.0), ===)
p = plot(1:2, grid_lw = 0.01)
@test compare(p, :gridlinewidth, 0.01, )
p = plot(1:2, minorgrid_lw = 0.01)
@test compare(p, :minorgridlinewidth, 0.01, )
p = plot(1:2, tickor = :out)
@test compare(p, :tick_direction, :out, ===)
compare(pl::Plot, s::Symbol, val, op) =
op(pl[1][:xaxis][s], val) && op(pl[1][:yaxis][s], val) && op(pl[1][:zaxis][s], val)
pl = plot(1:2, guide = "all labels")
@test compare(pl, :guide, "all labels", ===)
pl = plot(1:2, label = "test")
@test compare(pl, :guide, "", ===)
pl = plot(1:2, lim = (0, 3))
@test xlims(pl) === ylims(pl) === zlims(pl) === (0, 3)
pl = plot(1:2, tick = [1.25, 1.5, 1.75])
@test compare(pl, :ticks, [1.25, 1.5, 1.75], ==)
pl = plot(1:2, labelfontsize = 4)
@test compare(pl, :guidefontsize, 4, ==)
pl = plot(1:2, gα = 0.07)
@test compare(pl, :gridalpha, 0.07, )
pl = plot(1:2, gridls = :dashdot)
@test compare(pl, :gridstyle, :dashdot, ===)
pl = plot(1:2, gridcolor = :red)
@test compare(pl, :foreground_color_grid, RGBA{Float64}(1.0, 0.0, 0.0, 1.0), ===)
pl = plot(1:2, minorgridcolor = :red)
@test compare(pl, :foreground_color_minor_grid, RGBA{Float64}(1.0, 0.0, 0.0, 1.0), ===)
pl = plot(1:2, grid_lw = 0.01)
@test compare(pl, :gridlinewidth, 0.01, )
pl = plot(1:2, minorgrid_lw = 0.01)
@test compare(pl, :minorgridlinewidth, 0.01, )
pl = plot(1:2, tickor = :out)
@test compare(pl, :tick_direction, :out, ===)
end
68 changes: 34 additions & 34 deletions test/test_backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,35 +135,35 @@ end
io = IOContext(IOBuffer(), :color => true)

# lets just make sure it runs without error
p = plot(rand(10))
@test p isa Plot
@test show(io, p) isa Nothing

p = bar(randn(10))
@test p isa Plot
@test show(io, p) isa Nothing

p = plot([1, 2], [3, 4])
annotate!(p, [(1.5, 3.2, Plots.text("Test", :red, :center))])
hline!(p, [3.1])
@test p isa Plot
@test show(io, p) isa Nothing

p = plot([Dates.Date(2019, 1, 1), Dates.Date(2019, 2, 1)], [3, 4])
hline!(p, [3.1])
annotate!(p, [(Dates.Date(2019, 1, 15), 3.2, Plots.text("Test", :red, :center))])
@test p isa Plot
@test show(io, p) isa Nothing

p = plot([Dates.Date(2019, 1, 1), Dates.Date(2019, 2, 1)], [3, 4])
annotate!(p, [(Dates.Date(2019, 1, 15), 3.2, :auto)])
hline!(p, [3.1])
@test p isa Plot
@test show(io, p) isa Nothing

p = plot((plot(i) for i in 1:4)..., layout = (2, 2))
@test p isa Plot
@test show(io, p) isa Nothing
pl = plot(rand(10))
@test pl isa Plot
@test show(io, pl) isa Nothing

pl = bar(randn(10))
@test pl isa Plot
@test show(io, pl) isa Nothing

pl = plot([1, 2], [3, 4])
annotate!(pl, [(1.5, 3.2, Plots.text("Test", :red, :center))])
hline!(pl, [3.1])
@test pl isa Plot
@test show(io, pl) isa Nothing

pl = plot([Dates.Date(2019, 1, 1), Dates.Date(2019, 2, 1)], [3, 4])
hline!(pl, [3.1])
annotate!(pl, [(Dates.Date(2019, 1, 15), 3.2, Plots.text("Test", :red, :center))])
@test pl isa Plot
@test show(io, pl) isa Nothing

pl = plot([Dates.Date(2019, 1, 1), Dates.Date(2019, 2, 1)], [3, 4])
annotate!(pl, [(Dates.Date(2019, 1, 15), 3.2, :auto)])
hline!(pl, [3.1])
@test pl isa Plot
@test show(io, pl) isa Nothing

pl = plot((plot(i) for i in 1:4)..., layout = (2, 2))
@test pl isa Plot
@test show(io, pl) isa Nothing
end
end

Expand All @@ -189,9 +189,9 @@ end
with(:plotlyjs) do
@test backend() == Plots.PlotlyJSBackend()

p = plot(rand(10))
@test p isa Plot
@test_broken display(p) isa Nothing
pl = plot(rand(10))
@test pl isa Plot
@test_broken display(pl) isa Nothing
end
end

Expand All @@ -211,9 +211,9 @@ end
)
for be in backends
@info be
for (i, p) in Plots.test_examples(be, only = only, disp = false)
for (i, pl) in Plots.test_examples(be, only = only, disp = false)
fn = tempname() * ".png"
png(p, fn)
png(pl, fn)
@test filesize(fn) > 1_000
end
end
Expand Down
38 changes: 19 additions & 19 deletions test/test_components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
ellipse(x, y, w, h) = Shape(w * sin.(ang) .+ x, h * cos.(ang) .+ y)
myshapes = [ellipse(x, rand(), rand(), rand()) for x in 1:4]
@test coords(myshapes) isa Tuple{Vector{Vector{S}},Vector{Vector{T}}} where {T,S}
local p
@test_nowarn p = plot(myshapes)
@test p[1][1][:seriestype] === :shape
local pl
@test_nowarn pl = plot(myshapes)
@test pl[1][1][:seriestype] === :shape
end

@testset "Misc" begin
Expand Down Expand Up @@ -171,7 +171,7 @@ end
@testset "Series Annotations" begin
square = Shape([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)])
@test_logs (:warn, "Unused SeriesAnnotations arg: triangle (Symbol)") begin
p = plot(
pl = plot(
[1, 2, 3],
series_annotations = (
["a"],
Expand All @@ -182,7 +182,7 @@ end
:triangle, # pass an incorrect argument
),
)
sa = p.series_list[1].plotattributes[:series_annotations]
sa = pl.series_list[1].plotattributes[:series_annotations]
@test only(sa.strs).str == "a"
@test sa.font.family == "courier"
@test sa.baseshape == square
Expand All @@ -201,29 +201,29 @@ end
"1/$i"
end

series_anns(p, series) = p.series_list[series].plotattributes[:series_annotations]
series_anns(pl, series) = pl.series_list[series].plotattributes[:series_annotations]
ann_strings(ann) = [s.str for s in ann.strs]
ann_pointsizes(ann) = [s.font.pointsize for s in ann.strs]

let p = plot(ones(3, 2), series_annotations = ["a" "d"; "b" "e"; "c" "f"])
ann1 = series_anns(p, 1)
let pl = plot(ones(3, 2), series_annotations = ["a" "d"; "b" "e"; "c" "f"])
ann1 = series_anns(pl, 1)
@test ann_strings(ann1) == ["a", "b", "c"]

ann2 = series_anns(p, 2)
ann2 = series_anns(pl, 2)
@test ann_strings(ann2) == ["d", "e", "f"]
end

let p = plot(ones(2, 2), series_annotations = (["a" "c"; "b" "d"], square))
ann1 = series_anns(p, 1)
let pl = plot(ones(2, 2), series_annotations = (["a" "c"; "b" "d"], square))
ann1 = series_anns(pl, 1)
@test ann_strings(ann1) == ["a", "b"]

ann2 = series_anns(p, 2)
ann2 = series_anns(pl, 2)
@test ann_strings(ann2) == ["c", "d"]

@test ann1.baseshape == ann2.baseshape == square
end

let p = plot(
let pl = plot(
ones(3, 2),
series_annotations = (
permutedims([
Expand All @@ -233,27 +233,27 @@ end
(12, 13),
),
)
ann1 = series_anns(p, 1)
ann1 = series_anns(pl, 1)
@test ann1.baseshape == square
@test ann1.scalefactor == (14, 15)
@test ann_strings(ann1) == ["x", "y", "z"]
@test ann_pointsizes(ann1) == [10, 20, 30]

ann2 = series_anns(p, 2)
ann2 = series_anns(pl, 2)
@test ann2.scalefactor == (12, 13)
@test ann_strings(ann2) == ["a", "b", "c"]
@test ann2.strs[1].font.pointsize == 42
end

@test_throws ArgumentError plot(ones(2, 2), series_annotations = [([1],) 2; 3 4])

p = plot([1, 2], annotations = (1.5, 2, text("foo", :left)))
x, y, txt = only(p.subplots[end][:annotations])
pl = plot([1, 2], annotations = (1.5, 2, text("foo", :left)))
x, y, txt = only(pl.subplots[end][:annotations])
@test (x, y) == (1.5, 2)
@test txt.str == "foo"

p = plot([1, 2], annotations = ((0.1, 0.5), :auto))
pos, txt = only(p.subplots[end][:annotations])
pl = plot([1, 2], annotations = ((0.1, 0.5), :auto))
pos, txt = only(pl.subplots[end][:annotations])
@test pos == (0.1, 0.5)
@test txt.str == "(a)"
end
Expand Down
14 changes: 7 additions & 7 deletions test/test_dates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

rx = [x[3], x[5]]

p = plot(x, y, widen = false)
vspan!(p, rx, label = "", alpha = 0.2)
pl = plot(x, y, widen = false)
vspan!(pl, rx, label = "", alpha = 0.2)

ref_ylims = (y[1], y[end])
ref_xlims = (x[1].instant.periods.value, x[end].instant.periods.value)
@test Plots.ylims(p) == ref_ylims
@test Plots.xlims(p) == ref_xlims
@test Plots.ylims(pl) == ref_ylims
@test Plots.xlims(pl) == ref_xlims
end

@testset "Date xlims" begin
Expand All @@ -20,7 +20,7 @@ end

ref_xlims = map(date -> date.instant.periods.value, span)

p = plot(x, y, xlims = span, widen = false)
pl = plot(x, y, xlims = span, widen = false)
end

@testset "DateTime xlims" begin
Expand All @@ -30,6 +30,6 @@ end

ref_xlims = map(date -> date.instant.periods.value, span)

p = plot(x, y, xlims = span, widen = false)
@test Plots.xlims(p) == ref_xlims
pl = plot(x, y, xlims = span, widen = false)
@test Plots.xlims(pl) == ref_xlims
end

0 comments on commit dcee6db

Please sign in to comment.