Merge pull request #3661 from t-bltg/rng

Use a stable RNG in fakedata
This commit is contained in:
t-bltg 2021-07-23 19:50:54 +02:00 committed by GitHub
commit 878e590125
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 10 deletions

View File

@ -118,7 +118,6 @@ export
scalefontsizes,
resetfontsizes
# ---------------------------------------------------------
import NaNMath # define functions that ignores NaNs. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563
@ -250,6 +249,7 @@ end
# ---------------------------------------------------------
const CURRENT_BACKEND = CurrentBackend(:none)
const PLOTS_SEED = 1234
include("precompile_includer.jl")

View File

@ -128,8 +128,7 @@ const _examples = PlotExample[
:(
begin
import FileIO
path =
download("http://juliaplots.org/PlotReferenceImages.jl/Plots/pyplot/0.7.0/ref1.png")
path = download("http://juliaplots.org/PlotReferenceImages.jl/Plots/pyplot/0.7.0/ref1.png")
img = FileIO.load(path)
plot(img)
end

View File

@ -303,10 +303,12 @@ function convert_to_polar(theta, r, r_extrema = ignorenan_extrema(r))
x, y
end
function fakedata(sz...)
fakedata(sz::Int...) = fakedata(Random.seed!(PLOTS_SEED), sz...)
function fakedata(rng::AbstractRNG, sz...)
y = zeros(sz...)
for r in 2:size(y,1)
y[r,:] = 0.95 * vec(y[r-1,:]) + randn(size(y,2))
y[r,:] = 0.95 * vec(y[r-1,:]) + randn(rng, size(y,2))
end
y
end

View File

@ -6,14 +6,14 @@ function replace_rand!(ex::Expr)
for arg in ex.args
replace_rand!(arg)
end
if ex.head === :call && ex.args[1] (:rand, :randn)
if ex.head === :call && ex.args[1] (:rand, :randn, :(Plots.fakedata))
pushfirst!(ex.args, ex.args[1])
ex.args[2] = :rng
end
end
function fix_rand!(ex)
replace_rand!(ex)
pushfirst!(ex.args[1].args, :(rng = StableRNG(1234)))
pushfirst!(ex.args[1].args, :(rng = StableRNG(PLOTS_SEED)))
end
function image_comparison_tests(
@ -35,6 +35,7 @@ function image_comparison_tests(
fn = "ref$idx.png"
reffn = reference_file(pkg, idx, _current_plots_version)
newfn = joinpath(reference_path(pkg, _current_plots_version), fn)
@debug example.exprs
# test function
func = (fn, idx) -> begin

View File

@ -1,4 +1,4 @@
using Plots: guidefont, series_annotations
using Plots: guidefont, series_annotations, PLOTS_SEED
import ImageMagick
using VisualRegressionTests
using Plots
@ -13,7 +13,6 @@ import GeometryBasics
using Dates
using RecipesBase
@testset "Plotly standalone" begin
@test_nowarn Plots._init_ijulia_plotting()
@test Plots.plotly_local_file_path[] === nothing
@ -68,7 +67,7 @@ end
include("imgcomp.jl")
# don't actually show the plots
Random.seed!(1234)
Random.seed!(PLOTS_SEED)
default(show=false, reuse=true)
is_ci() = get(ENV, "CI", "false") == "true"
const PLOTS_IMG_TOL = parse(