Merge 0dc2edbd988a5e6280279f9f62f30312b0ad2fb9 into 0eab0dc6802064e5225075d2ad646c51d41039ef

This commit is contained in:
RalphAS 2018-07-02 14:30:56 +00:00 committed by GitHub
commit 1c34ae29f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 306 additions and 228 deletions

View File

@ -2,12 +2,13 @@
language: julia language: julia
os: os:
- linux - linux
# - osx - osx
julia: julia:
- 0.6 # - 0.7
matrix: - nightly
allow_failures: #matrix:
- julia: nightly # allow_failures:
# - julia: nightly
# # before install: # # before install:
# # - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi # # - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
@ -40,11 +41,11 @@ before_install:
notifications: notifications:
email: true email: false
# uncomment the following lines to override the default test script # uncomment the following lines to override the default test script
script: script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd()); Pkg.build("Plots")' - julia -e 'import Pkg; Pkg.develop(pwd()); Pkg.build("Plots")'
- julia test/travis_commands.jl - julia test/travis_commands.jl
# - julia -e 'Pkg.clone("ImageMagick"); Pkg.build("ImageMagick")' # - julia -e 'Pkg.clone("ImageMagick"); Pkg.build("ImageMagick")'
# - julia -e 'Pkg.clone("GR"); Pkg.build("GR")' # - julia -e 'Pkg.clone("GR"); Pkg.build("GR")'

View File

@ -1,7 +1,6 @@
julia 0.6 julia 0.7
RecipesBase 0.2.3 RecipesBase 0.2.3
PlotUtils 0.4.1 PlotUtils 0.5
PlotThemes 0.1.3 PlotThemes 0.1.3
Reexport Reexport
StaticArrays 0.5 StaticArrays 0.5

View File

@ -1,13 +1,10 @@
environment: environment:
matrix: matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
matrix: matrix:
allow_failures: allow_failures:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" #check and address
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
@ -32,8 +29,8 @@ install:
build_script: build_script:
# Need to convert from shallow to complete for Pkg.clone to work # Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow) - IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo(); Pkg.clone(pwd(), \"Plots\"); Pkg.build(\"Plots\")" - C:\projects\julia\bin\julia -e "using InteractiveUtils; versioninfo(); import Pkg; Pkg.clone(pwd(),\"Plots\"); Pkg.build(\"Plots\")"
test_script: test_script:
# - C:\projects\julia\bin\julia -e "Pkg.test(\"Plots\")" # - C:\projects\julia\bin\julia -e "Pkg.test(\"Plots\")"
- C:\projects\julia\bin\julia -e "include(Pkg.dir(\"Plots\", \"test\", \"travis_commands.jl\"))" - C:\projects\julia\bin\julia -e "import Pkg; include(Pkg.dir(\"Plots\", \"test\", \"travis_commands.jl\"))"

View File

@ -12,6 +12,17 @@ import RecipesBase: plot, plot!, animate
using Base.Meta using Base.Meta
@reexport using PlotUtils @reexport using PlotUtils
@reexport using PlotThemes @reexport using PlotThemes
import Dates
using Dates: Date, DateTime
using Printf: @printf, @sprintf
using REPL: REPLDisplay
using Base64: base64encode
using Base.Sys: isapple, islinux, iswindows, isbsd
import Pkg
using LinearAlgebra: Transpose
const euler_e = Base.MathConstants.e
import Showoff import Showoff
import StatsBase import StatsBase
import JSON import JSON
@ -264,6 +275,8 @@ xgrid!(args...; kw...) = plot!(; xgrid = args
ygrid!(args...; kw...) = plot!(; ygrid = args, kw...) ygrid!(args...; kw...) = plot!(; ygrid = args, kw...)
let PlotOrSubplot = Union{Plot, Subplot} let PlotOrSubplot = Union{Plot, Subplot}
global title!, xlabel!, ylabel!, xlims!, ylims!, zlims!, xticks!, yticks!
global xgrid!, ygrid!, annotate!, xflip!, yflip!, xaxis!, yaxis!
title!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; title = s, kw...) title!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; title = s, kw...)
xlabel!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; xlabel = s, kw...) xlabel!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; xlabel = s, kw...)
ylabel!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; ylabel = s, kw...) ylabel!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; ylabel = s, kw...)

View File

@ -21,7 +21,7 @@ const _arg_desc = KW(
:markerstrokewidth => "Number. Width of the marker stroke (border. in pixels)", :markerstrokewidth => "Number. Width of the marker stroke (border. in pixels)",
:markerstrokecolor => "Color Type. Color of the marker stroke (border). `:match` will take the value from `:foreground_color_subplot`.", :markerstrokecolor => "Color Type. Color of the marker stroke (border). `:match` will take the value from `:foreground_color_subplot`.",
:markerstrokealpha => "Number in [0,1]. The alpha/opacity override for the marker stroke (border). `nothing` (the default) means it will take the alpha value of markerstrokecolor.", :markerstrokealpha => "Number in [0,1]. The alpha/opacity override for the marker stroke (border). `nothing` (the default) means it will take the alpha value of markerstrokecolor.",
:bins => "Integer, NTuple{2,Integer}, AbstractVector or Symbol. Default is :auto (the Freedman-Diaconis rule). For histogram-types, defines the approximate number of bins to aim for, or the auto-binning algorithm to use (:sturges, :sqrt, :rice, :scott or :fd). For fine-grained control pass a Vector of break values, e.g. `linspace(extrema(x)..., 25)`", :bins => "Integer, NTuple{2,Integer}, AbstractVector or Symbol. Default is :auto (the Freedman-Diaconis rule). For histogram-types, defines the approximate number of bins to aim for, or the auto-binning algorithm to use (:sturges, :sqrt, :rice, :scott or :fd). For fine-grained control pass a Vector of break values, e.g. `range(minimum(x),stop=maximum(x), length=25)`",
:smooth => "Bool. Add a regression line?", :smooth => "Bool. Add a regression line?",
:group => "AbstractVector. Data is split into a separate series, one for each unique value in `group`.", :group => "AbstractVector. Data is split into a separate series, one for each unique value in `group`.",
:x => "Various. Input data. First Dimension", :x => "Various. Input data. First Dimension",

View File

@ -15,7 +15,7 @@ function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol})
for (k,v) in aliases for (k,v) in aliases
s = string(k) s = string(k)
if '_' in s if '_' in s
aliases[Symbol(replace(s, "_", ""))] = v aliases[Symbol(replace(s, "_" => ""))] = v
end end
end end
end end
@ -176,7 +176,11 @@ const _positionAliases = Dict{Symbol,Symbol}(
const _allScales = [:identity, :ln, :log2, :log10, :asinh, :sqrt] const _allScales = [:identity, :ln, :log2, :log10, :asinh, :sqrt]
const _logScales = [:ln, :log2, :log10] const _logScales = [:ln, :log2, :log10]
const _logScaleBases = Dict(:ln => e, :log2 => 2.0, :log10 => 10.0) const _logScaleBases = Dict(
:ln => euler_e,
:log2 => 2.0,
:log10 => 10.0
)
const _scaleAliases = Dict{Symbol,Symbol}( const _scaleAliases = Dict{Symbol,Symbol}(
:none => :identity, :none => :identity,
:log => :log10, :log => :log10,
@ -188,7 +192,7 @@ const _allGridSyms = [:x, :y, :z,
:all, :both, :on, :yes, :show, :all, :both, :on, :yes, :show,
:none, :off, :no, :hide] :none, :off, :no, :hide]
const _allGridArgs = [_allGridSyms; string.(_allGridSyms); nothing] const _allGridArgs = [_allGridSyms; string.(_allGridSyms); nothing]
hasgrid(arg::Void, letter) = false hasgrid(arg::Nothing, letter) = false
hasgrid(arg::Bool, letter) = arg hasgrid(arg::Bool, letter) = arg
function hasgrid(arg::Symbol, letter) function hasgrid(arg::Symbol, letter)
if arg in _allGridSyms if arg in _allGridSyms
@ -206,7 +210,7 @@ const _allShowaxisSyms = [:x, :y, :z,
:all, :both, :on, :yes, :show, :all, :both, :on, :yes, :show,
:off, :no, :hide] :off, :no, :hide]
const _allShowaxisArgs = [_allGridSyms; string.(_allGridSyms)] const _allShowaxisArgs = [_allGridSyms; string.(_allGridSyms)]
showaxis(arg::Void, letter) = false showaxis(arg::Nothing, letter) = false
showaxis(arg::Bool, letter) = arg showaxis(arg::Bool, letter) = arg
function showaxis(arg::Symbol, letter) function showaxis(arg::Symbol, letter)
if arg in _allGridSyms if arg in _allGridSyms
@ -654,6 +658,7 @@ function handleColors!(d::KW, arg, csym::Symbol)
d[csym] = c d[csym] = c
end end
return true return true
catch
end end
false false
end end
@ -1028,7 +1033,7 @@ function extractGroupArgs(vs::Tuple, args...)
end end
# allow passing NamedTuples for a named legend entry # allow passing NamedTuples for a named legend entry
@require NamedTuples begin @require NamedTuples="73a701b4-84e1-5df0-88ff-1968ee2ee8dc" begin
legendEntryFromTuple(ns::NamedTuples.NamedTuple) = legendEntryFromTuple(ns::NamedTuples.NamedTuple) =
join(["$k = $v" for (k, v) in zip(keys(ns), values(ns))], ", ") join(["$k = $v" for (k, v) in zip(keys(ns), values(ns))], ", ")
@ -1131,7 +1136,7 @@ function convertLegendValue(val::Symbol)
end end
end end
convertLegendValue(val::Bool) = val ? :best : :none convertLegendValue(val::Bool) = val ? :best : :none
convertLegendValue(val::Void) = :none convertLegendValue(val::Nothing) = :none
convertLegendValue(v::Tuple{S,T}) where {S<:Real, T<:Real} = v convertLegendValue(v::Tuple{S,T}) where {S<:Real, T<:Real} = v
convertLegendValue(v::AbstractArray) = map(convertLegendValue, v) convertLegendValue(v::AbstractArray) = map(convertLegendValue, v)

View File

@ -251,7 +251,7 @@ function get_ticks(axis::Axis)
# discrete ticks... # discrete ticks...
n = length(dvals) n = length(dvals)
rng = if ticks == :auto rng = if ticks == :auto
Int[round(Int,i) for i in linspace(1, n, 15)] Int[round(Int,i) for i in range(1, stop=n, length=15)]
else # if ticks == :all else # if ticks == :all
1:n 1:n
end end
@ -265,7 +265,7 @@ function get_ticks(axis::Axis)
end end
elseif typeof(ticks) <: Union{AVec, Int} elseif typeof(ticks) <: Union{AVec, Int}
if !isempty(dvals) && typeof(ticks) <: Int if !isempty(dvals) && typeof(ticks) <: Int
rng = Int[round(Int,i) for i in linspace(1, length(dvals), ticks)] rng = Int[round(Int,i) for i in range(1, stop=length(dvals), length=ticks)]
axis[:continuous_values][rng], dvals[rng] axis[:continuous_values][rng], dvals[rng]
else else
# override ticks, but get the labels # override ticks, but get the labels
@ -310,7 +310,7 @@ function expand_extrema!(axis::Axis, v::Number)
end end
# these shouldn't impact the extrema # these shouldn't impact the extrema
expand_extrema!(axis::Axis, ::Void) = axis[:extrema] expand_extrema!(axis::Axis, ::Nothing) = axis[:extrema]
expand_extrema!(axis::Axis, ::Bool) = axis[:extrema] expand_extrema!(axis::Axis, ::Bool) = axis[:extrema]

View File

@ -13,6 +13,20 @@ backends() = _backends
backend_name() = CURRENT_BACKEND.sym backend_name() = CURRENT_BACKEND.sym
_backend_instance(sym::Symbol) = haskey(_backendType, sym) ? _backendType[sym]() : error("Unsupported backend $sym") _backend_instance(sym::Symbol) = haskey(_backendType, sym) ? _backendType[sym]() : error("Unsupported backend $sym")
# kludge while waiting for Pkg alternatives
function _findmod(f::Symbol)
for (u,v) in Base.loaded_modules
(Symbol(v) == f) && return u
end
nothing
end
function topimport(modname)
@eval Base.__toplevel__ import $modname
u = _findmod(modname)
@eval $modname = Base.loaded_modules[$u]
end
# end kludge
macro init_backend(s) macro init_backend(s)
str = lowercase(string(s)) str = lowercase(string(s))
sym = Symbol(str) sym = Symbol(str)
@ -134,8 +148,7 @@ CurrentBackend(sym::Symbol) = CurrentBackend(sym, _backend_instance(sym))
function pickDefaultBackend() function pickDefaultBackend()
env_default = get(ENV, "PLOTS_DEFAULT_BACKEND", "") env_default = get(ENV, "PLOTS_DEFAULT_BACKEND", "")
if env_default != "" if env_default != ""
try if Base.find_package(env_default) != nothing
Pkg.installed(env_default) # this will error if not installed
sym = Symbol(lowercase(env_default)) sym = Symbol(lowercase(env_default))
if haskey(_backendType, sym) if haskey(_backendType, sym)
return backend(sym) return backend(sym)
@ -143,7 +156,7 @@ function pickDefaultBackend()
warn("You have set PLOTS_DEFAULT_BACKEND=$env_default but it is not a valid backend package. Choose from:\n\t", warn("You have set PLOTS_DEFAULT_BACKEND=$env_default but it is not a valid backend package. Choose from:\n\t",
join(sort(_backends), "\n\t")) join(sort(_backends), "\n\t"))
end end
catch else
warn("You have set PLOTS_DEFAULT_BACKEND=$env_default but it is not installed.") warn("You have set PLOTS_DEFAULT_BACKEND=$env_default but it is not installed.")
end end
end end
@ -152,7 +165,7 @@ function pickDefaultBackend()
# which one someone will want to use if they have the package installed...accounting for # which one someone will want to use if they have the package installed...accounting for
# features, speed, and robustness # features, speed, and robustness
for pkgstr in ("GR", "PyPlot", "PlotlyJS", "PGFPlots", "UnicodePlots", "InspectDR", "GLVisualize") for pkgstr in ("GR", "PyPlot", "PlotlyJS", "PGFPlots", "UnicodePlots", "InspectDR", "GLVisualize")
if Pkg.installed(pkgstr) != nothing if Base.find_package(pkgstr) != nothing
return backend(Symbol(lowercase(pkgstr))) return backend(Symbol(lowercase(pkgstr)))
end end
end end

View File

@ -9,7 +9,7 @@ TODO
* fix units in all visuals (e.g dotted lines, marker scale, surfaces) * fix units in all visuals (e.g dotted lines, marker scale, surfaces)
=# =#
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "glvisualize.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "glvisualize.jl"))
end end
@ -397,7 +397,7 @@ function gappy(x, ps)
return last(ps) - x return last(ps) - x
end end
function ticks(points, resolution) function ticks(points, resolution)
Float16[gappy(x, points) for x = linspace(first(points),last(points), resolution)] Float16[gappy(x, points) for x = range(first(points),stop=last(points), length=resolution)]
end end
@ -901,7 +901,7 @@ function gl_boxplot(d, kw_args)
# filter y # filter y
values = y[filter(i -> _cycle(x,i) == glabel, 1:length(y))] values = y[filter(i -> _cycle(x,i) == glabel, 1:length(y))]
# compute quantiles # compute quantiles
q1,q2,q3,q4,q5 = quantile(values, linspace(0,1,5)) q1,q2,q3,q4,q5 = quantile(values, range(0,stop=1,5))
# notch # notch
n = Plots.notch_width(q2, q4, length(values)) n = Plots.notch_width(q2, q4, length(values))
# warn on inverted notches? # warn on inverted notches?

View File

@ -3,7 +3,7 @@
# significant contributions by @jheinen # significant contributions by @jheinen
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "gr.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "gr.jl"))
end end
@ -67,7 +67,7 @@ end
function _initialize_backend(::GRBackend; kw...) function _initialize_backend(::GRBackend; kw...)
@eval begin @eval begin
import GR topimport(:GR)
export GR export GR
end end
end end
@ -144,7 +144,7 @@ gr_set_fillcolor(c) = GR.setfillcolorind(gr_getcolorind(_cycle(c,1)))
gr_set_markercolor(c) = GR.setmarkercolorind(gr_getcolorind(_cycle(c,1))) gr_set_markercolor(c) = GR.setmarkercolorind(gr_getcolorind(_cycle(c,1)))
gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(_cycle(c,1))) gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(_cycle(c,1)))
gr_set_transparency(α::Real) = GR.settransparency(clamp(α, 0, 1)) gr_set_transparency(α::Real) = GR.settransparency(clamp(α, 0, 1))
function gr_set_transparency(::Void) end function gr_set_transparency(::Nothing) end
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
@ -196,7 +196,7 @@ gr_inqtext(x, y, s::Symbol) = gr_inqtext(x, y, string(s))
function gr_inqtext(x, y, s) function gr_inqtext(x, y, s)
if length(s) >= 2 && s[1] == '$' && s[end] == '$' if length(s) >= 2 && s[1] == '$' && s[end] == '$'
GR.inqtextext(x, y, s[2:end-1]) GR.inqtextext(x, y, s[2:end-1])
elseif search(s, '\\') != 0 || contains(s, "10^{") elseif something(findfirst(isequal('\\'), s), 0) != 0 || occursin("10^{", s)
GR.inqtextext(x, y, s) GR.inqtextext(x, y, s)
else else
GR.inqtext(x, y, s) GR.inqtext(x, y, s)
@ -208,7 +208,7 @@ gr_text(x, y, s::Symbol) = gr_text(x, y, string(s))
function gr_text(x, y, s) function gr_text(x, y, s)
if length(s) >= 2 && s[1] == '$' && s[end] == '$' if length(s) >= 2 && s[1] == '$' && s[end] == '$'
GR.mathtex(x, y, s[2:end-1]) GR.mathtex(x, y, s[2:end-1])
elseif search(s, '\\') != 0 || contains(s, "10^{") elseif something(findfirst(isequal('\\'), s), 0) != 0 || occursin("10^{", s)
GR.textext(x, y, s) GR.textext(x, y, s)
else else
GR.text(x, y, s) GR.text(x, y, s)
@ -485,7 +485,7 @@ function gr_colorbar(sp::Subplot, clims)
xmin, xmax = gr_xy_axislims(sp)[1:2] xmin, xmax = gr_xy_axislims(sp)[1:2]
gr_set_viewport_cmap(sp) gr_set_viewport_cmap(sp)
l = zeros(Int32, 1, 256) l = zeros(Int32, 1, 256)
l[1,:] = Int[round(Int, _i) for _i in linspace(1000, 1255, 256)] l[1,:] = Int[round(Int, _i) for _i in range(1000, stop=1255, length=256)]
GR.setscale(0) GR.setscale(0)
GR.setwindow(xmin, xmax, clims[1], clims[2]) GR.setwindow(xmin, xmax, clims[1], clims[2])
GR.cellarray(xmin, xmax, clims[2], clims[1], 1, length(l), l) GR.cellarray(xmin, xmax, clims[2], clims[1], 1, length(l), l)
@ -502,16 +502,16 @@ function gr_legend_pos(s::Symbol,w,h)
if str == "best" if str == "best"
str = "topright" str = "topright"
end end
if contains(str,"right") if occursin("right",str)
xpos = viewport_plotarea[2] - 0.05 - w xpos = viewport_plotarea[2] - 0.05 - w
elseif contains(str,"left") elseif occursin("left",str)
xpos = viewport_plotarea[1] + 0.11 xpos = viewport_plotarea[1] + 0.11
else else
xpos = (viewport_plotarea[2]-viewport_plotarea[1])/2 - w/2 +.04 xpos = (viewport_plotarea[2]-viewport_plotarea[1])/2 - w/2 +.04
end end
if contains(str,"top") if occursin("top",str)
ypos = viewport_plotarea[4] - 0.06 ypos = viewport_plotarea[4] - 0.06
elseif contains(str,"bottom") elseif occursin("bottom",str)
ypos = viewport_plotarea[3] + h + 0.06 ypos = viewport_plotarea[3] + h + 0.06
else else
ypos = (viewport_plotarea[4]-viewport_plotarea[3])/2 + h/2 ypos = (viewport_plotarea[4]-viewport_plotarea[3])/2 + h/2
@ -531,7 +531,7 @@ const _gr_gradient_alpha = ones(256)
function gr_set_gradient(c) function gr_set_gradient(c)
grad = isa(c, ColorGradient) ? c : cgrad() grad = isa(c, ColorGradient) ? c : cgrad()
for (i,z) in enumerate(linspace(0, 1, 256)) for (i,z) in enumerate(range(0, stop=1, length=256))
c = grad[z] c = grad[z]
GR.setcolorrep(999+i, red(c), green(c), blue(c)) GR.setcolorrep(999+i, red(c), green(c), blue(c))
_gr_gradient_alpha[i] = alpha(c) _gr_gradient_alpha[i] = alpha(c)
@ -1051,7 +1051,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
if typeof(series[:levels]) <: AbstractArray if typeof(series[:levels]) <: AbstractArray
h = series[:levels] h = series[:levels]
else else
h = series[:levels] > 1 ? linspace(zmin, zmax, series[:levels]) : [(zmin + zmax) / 2] h = series[:levels] > 1 ? range(zmin, stop=zmax, length=series[:levels]) : [(zmin + zmax) / 2]
end end
if series[:fillrange] != nothing if series[:fillrange] != nothing
GR.surface(x, y, z, GR.OPTION_CELL_ARRAY) GR.surface(x, y, z, GR.OPTION_CELL_ARRAY)
@ -1358,10 +1358,10 @@ const _gr_mimeformats = Dict(
"image/svg+xml" => "svg", "image/svg+xml" => "svg",
) )
const _gr_wstype_default = @static if is_linux() const _gr_wstype_default = @static if islinux()
"x11" "x11"
# "cairox11" # "cairox11"
elseif is_apple() elseif isapple()
"quartz" "quartz"
else else
"use_default" "use_default"

View File

@ -28,7 +28,7 @@ Read from .hdf5 file using:
- Should be reliable for archival purposes. - Should be reliable for archival purposes.
==# ==#
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "hdf5.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "hdf5.jl"))
end end
@ -39,7 +39,7 @@ struct HDF5PlotNative; end #Indentifies a data element that can natively be hand
struct HDF5CTuple; end #Identifies a "complex" tuple structure struct HDF5CTuple; end #Identifies a "complex" tuple structure
mutable struct HDF5Plot_PlotRef mutable struct HDF5Plot_PlotRef
ref::Union{Plot, Void} ref::Union{Plot, Nothing}
end end
@ -142,13 +142,13 @@ end
function _initialize_backend(::HDF5Backend) function _initialize_backend(::HDF5Backend)
@eval begin @eval begin
import HDF5 topimport(:HDF5)
export HDF5 export HDF5
if length(HDF5PLOT_MAP_TELEM2STR) < 1 if length(HDF5PLOT_MAP_TELEM2STR) < 1
#Possible element types of high-level data types: #Possible element types of high-level data types:
const telem2str = Dict{String, Type}( const telem2str = Dict{String, Type}(
"NATIVE" => HDF5PlotNative, "NATIVE" => HDF5PlotNative,
"VOID" => Void, "VOID" => Nothing,
"BOOL" => Bool, "BOOL" => Bool,
"SYMBOL" => Symbol, "SYMBOL" => Symbol,
"TUPLE" => Tuple, "TUPLE" => Tuple,
@ -315,9 +315,9 @@ function _hdf5plot_gwrite(grp, k::String, v::Array{Any})
warn("Cannot write Array: $k=$v") warn("Cannot write Array: $k=$v")
end end
=# =#
function _hdf5plot_gwrite(grp, k::String, v::Void) function _hdf5plot_gwrite(grp, k::String, v::Nothing)
grp[k] = 0 grp[k] = 0
_hdf5plot_writetype(grp, k, Void) _hdf5plot_writetype(grp, k, Nothing)
end end
function _hdf5plot_gwrite(grp, k::String, v::Bool) function _hdf5plot_gwrite(grp, k::String, v::Bool)
grp[k] = Int(v) grp[k] = Int(v)
@ -344,7 +344,7 @@ end
function _hdf5plot_gwrite(grp, k::String, d::Dict) function _hdf5plot_gwrite(grp, k::String, d::Dict)
# warn("Cannot write dict: $k=$d") # warn("Cannot write dict: $k=$d")
end end
function _hdf5plot_gwrite(grp, k::String, v::Range) function _hdf5plot_gwrite(grp, k::String, v::AbstractRange)
_hdf5plot_gwrite(grp, k, collect(v)) #For now _hdf5plot_gwrite(grp, k, collect(v)) #For now
end end
function _hdf5plot_gwrite(grp, k::String, v::ARGB{N0f8}) function _hdf5plot_gwrite(grp, k::String, v::ARGB{N0f8})
@ -409,15 +409,6 @@ function _hdf5plot_gwrite(grp, k::String, v::Surface)
_hdf5plot_gwrite(grp, "data2d", v.surf) _hdf5plot_gwrite(grp, "data2d", v.surf)
_hdf5plot_writetype(grp, Surface) _hdf5plot_writetype(grp, Surface)
end end
#TODO: "Properly" support Nullable using _hdf5plot_writetype?
function _hdf5plot_gwrite(grp, k::String, v::Nullable)
if isnull(v)
_hdf5plot_gwrite(grp, k, nothing)
else
_hdf5plot_gwrite(grp, k, v.value)
end
return
end
function _hdf5plot_gwrite(grp, k::String, v::SeriesAnnotations) function _hdf5plot_gwrite(grp, k::String, v::SeriesAnnotations)
#Currently no support for SeriesAnnotations #Currently no support for SeriesAnnotations
@ -485,7 +476,7 @@ function _hdf5plot_readcount(grp) #Read directly from group
end end
_hdf5plot_convert(T::Type{HDF5PlotNative}, v) = v _hdf5plot_convert(T::Type{HDF5PlotNative}, v) = v
_hdf5plot_convert(T::Type{Void}, v) = nothing _hdf5plot_convert(T::Type{Nothing}, v) = nothing
_hdf5plot_convert(T::Type{Bool}, v) = (v!=0) _hdf5plot_convert(T::Type{Bool}, v) = (v!=0)
_hdf5plot_convert(T::Type{Symbol}, v) = Symbol(v) _hdf5plot_convert(T::Type{Symbol}, v) = Symbol(v)
_hdf5plot_convert(T::Type{Tuple}, v) = tuple(v...) #With Vector{T<:Number} _hdf5plot_convert(T::Type{Tuple}, v) = tuple(v...) #With Vector{T<:Number}

View File

@ -13,7 +13,7 @@ Add in functionality to Plots.jl:
:aspect_ratio, :aspect_ratio,
=# =#
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "inspectdr.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "inspectdr.jl"))
end end
@ -162,17 +162,17 @@ end
function _initialize_backend(::InspectDRBackend; kw...) function _initialize_backend(::InspectDRBackend; kw...)
@eval begin @eval begin
import InspectDR topimport(:InspectDR)
export InspectDR export InspectDR
#Glyph used when plotting "Shape"s: #Glyph used when plotting "Shape"s:
const INSPECTDR_GLYPH_SHAPE = InspectDR.GlyphPolyline( INSPECTDR_GLYPH_SHAPE = InspectDR.GlyphPolyline(
2*InspectDR.GLYPH_SQUARE.x, InspectDR.GLYPH_SQUARE.y 2*InspectDR.GLYPH_SQUARE.x, InspectDR.GLYPH_SQUARE.y
) )
mutable struct InspecDRPlotRef mutable struct InspecDRPlotRef
mplot::Union{Void, InspectDR.Multiplot} mplot::Union{Nothing, InspectDR.Multiplot}
gui::Union{Void, InspectDR.GtkPlot} gui::Union{Nothing, InspectDR.GtkPlot}
end end
_inspectdr_getmplot(::Any) = nothing _inspectdr_getmplot(::Any) = nothing
@ -347,8 +347,8 @@ end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend}) function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend})
const plot = sp.o plot = sp.o
const strip = plot.strips[1] #Only 1 strip supported with Plots.jl strip = plot.strips[1] #Only 1 strip supported with Plots.jl
xaxis = sp[:xaxis]; yaxis = sp[:yaxis] xaxis = sp[:xaxis]; yaxis = sp[:yaxis]
xgrid_show = xaxis[:grid] xgrid_show = xaxis[:grid]
@ -406,7 +406,7 @@ end
# called just before updating layout bounding boxes... in case you need to prep # called just before updating layout bounding boxes... in case you need to prep
# for the calcs # for the calcs
function _before_layout_calcs(plt::Plot{InspectDRBackend}) function _before_layout_calcs(plt::Plot{InspectDRBackend})
const mplot = _inspectdr_getmplot(plt.o) mplot = _inspectdr_getmplot(plt.o)
if nothing == mplot; return; end if nothing == mplot; return; end
mplot.title = plt[:plot_title] mplot.title = plt[:plot_title]
@ -506,7 +506,7 @@ const _inspectdr_mimeformats_nodpi = Dict(
# "application/postscript" => "ps", #TODO: support once Cairo supports PSSurface # "application/postscript" => "ps", #TODO: support once Cairo supports PSSurface
"application/pdf" => "pdf" "application/pdf" => "pdf"
) )
_inspectdr_show(io::IO, mime::MIME, ::Void, w, h) = _inspectdr_show(io::IO, mime::MIME, ::Nothing, w, h) =
throw(ErrorException("Cannot show(::IO, ...) plot - not yet generated")) throw(ErrorException("Cannot show(::IO, ...) plot - not yet generated"))
function _inspectdr_show(io::IO, mime::MIME, mplot, w, h) function _inspectdr_show(io::IO, mime::MIME, mplot, w, h)
InspectDR._show(io, mime, mplot, Float64(w), Float64(h)) InspectDR._show(io, mime, mplot, Float64(w), Float64(h))

View File

@ -2,7 +2,7 @@
# significant contributions by: @pkofod # significant contributions by: @pkofod
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pgfplots.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pgfplots.jl"))
end end
@ -58,7 +58,7 @@ end
function _initialize_backend(::PGFPlotsBackend; kw...) function _initialize_backend(::PGFPlotsBackend; kw...)
@eval begin @eval begin
import PGFPlots topimport(:PGFPlots)
export PGFPlots export PGFPlots
end end
end end

View File

@ -1,7 +1,7 @@
# https://plot.ly/javascript/getting-started # https://plot.ly/javascript/getting-started
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl"))
end end
@ -450,7 +450,7 @@ function plotly_colorscale(c::AbstractVector{<:RGBA}, α)
if length(c) == 1 if length(c) == 1
return [[0.0, rgba_string(plot_color(c[1], α))], [1.0, rgba_string(plot_color(c[1], α))]] return [[0.0, rgba_string(plot_color(c[1], α))], [1.0, rgba_string(plot_color(c[1], α))]]
else else
vals = linspace(0.0, 1.0, length(c)) vals = range(0.0, stop=1.0, length=length(c))
return [[vals[i], rgba_string(plot_color(c[i], α))] for i in eachindex(c)] return [[vals[i], rgba_string(plot_color(c[i], α))] for i in eachindex(c)]
end end
end end

View File

@ -1,4 +1,4 @@
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotlyjs.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotlyjs.jl"))
end end
@ -29,7 +29,7 @@ end
function _initialize_backend(::PlotlyJSBackend; kw...) function _initialize_backend(::PlotlyJSBackend; kw...)
@eval begin @eval begin
import PlotlyJS topimport(:PlotlyJS)
export PlotlyJS export PlotlyJS
end end

View File

@ -1,7 +1,7 @@
# https://github.com/stevengj/PyPlot.jl # https://github.com/stevengj/PyPlot.jl
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pyplot.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pyplot.jl"))
end end
@ -77,8 +77,12 @@ function _initialize_backend(::PyPlotBackend)
# problem: https://github.com/tbreloff/Plots.jl/issues/308 # problem: https://github.com/tbreloff/Plots.jl/issues/308
# solution: hack from @stevengj: https://github.com/stevengj/PyPlot.jl/pull/223#issuecomment-229747768 # solution: hack from @stevengj: https://github.com/stevengj/PyPlot.jl/pull/223#issuecomment-229747768
otherdisplays = splice!(Base.Multimedia.displays, 2:length(Base.Multimedia.displays)) otherdisplays = splice!(Base.Multimedia.displays, 2:length(Base.Multimedia.displays))
import PyPlot, PyCall
import LaTeXStrings: latexstring topimport(:PyPlot)
topimport(:PyCall)
topimport(:LaTeXStrings)
latexstring = LaTeXStrings.latexstring
append!(Base.Multimedia.displays, otherdisplays) append!(Base.Multimedia.displays, otherdisplays)
export PyPlot export PyPlot
@ -679,8 +683,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
if typeof(z) <: AbstractMatrix || typeof(z) <: Surface if typeof(z) <: AbstractMatrix || typeof(z) <: Surface
x, y, z = map(Array, (x,y,z)) x, y, z = map(Array, (x,y,z))
if !ismatrix(x) || !ismatrix(y) if !ismatrix(x) || !ismatrix(y)
x = repmat(x', length(y), 1) x = repeat(x', length(y), 1)
y = repmat(y, 1, length(series[:x])) y = repeat(y, 1, length(series[:x]))
end end
z = transpose_z(series, z) z = transpose_z(series, z)
if st == :surface if st == :surface
@ -919,7 +923,7 @@ function py_set_scale(ax, axis::Axis)
"linear" "linear"
else else
kw[Symbol(:base,letter)] = if scale == :ln kw[Symbol(:base,letter)] = if scale == :ln
e Base.MathConstants.e
elseif scale == :log2 elseif scale == :log2
2 2
elseif scale == :log10 elseif scale == :log10

View File

@ -5,7 +5,7 @@
function _initialize_backend(::[PkgName]Backend; kw...) function _initialize_backend(::[PkgName]Backend; kw...)
@eval begin @eval begin
import [PkgName] topimport(:[PkgName])
export [PkgName] export [PkgName]
# todo: other initialization that needs to be eval-ed # todo: other initialization that needs to be eval-ed
end end

View File

@ -1,7 +1,7 @@
# https://github.com/Evizero/UnicodePlots.jl # https://github.com/Evizero/UnicodePlots.jl
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "unicodeplots.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "unicodeplots.jl"))
end end
@ -42,7 +42,7 @@ end
function _initialize_backend(::UnicodePlotsBackend; kw...) function _initialize_backend(::UnicodePlotsBackend; kw...)
@eval begin @eval begin
import UnicodePlots topimport(:UnicodePlots)
export UnicodePlots export UnicodePlots
end end
end end
@ -183,7 +183,7 @@ function png(plt::AbstractPlot{UnicodePlotsBackend}, fn::AbstractString)
gui(plt) gui(plt)
# @osx_only begin # @osx_only begin
@static if is_apple() @static if isapple()
# BEGIN HACK # BEGIN HACK
# wait while the plot gets drawn # wait while the plot gets drawn

View File

@ -2,7 +2,7 @@
# NOTE: backend should implement `html_body` and `html_head` # NOTE: backend should implement `html_body` and `html_head`
# CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl # CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl
@require Revise begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" begin
Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "web.jl")) Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "web.jl"))
end end
@ -23,13 +23,13 @@ function standalone_html(plt::AbstractPlot; title::AbstractString = get(plt.attr
end end
function open_browser_window(filename::AbstractString) function open_browser_window(filename::AbstractString)
@static if is_apple() @static if isapple()
return run(`open $(filename)`) return run(`open $(filename)`)
end end
@static if is_linux() || is_bsd() # is_bsd() addition is as yet untested, but based on suggestion in https://github.com/JuliaPlots/Plots.jl/issues/681 @static if islinux() || isbsd() # is_bsd() addition is as yet untested, but based on suggestion in https://github.com/JuliaPlots/Plots.jl/issues/681
return run(`xdg-open $(filename)`) return run(`xdg-open $(filename)`)
end end
@static if is_windows() @static if iswindows()
return run(`$(ENV["COMSPEC"]) /c start "" "$(filename)"`) return run(`$(ENV["COMSPEC"]) /c start "" "$(filename)"`)
end end
warn("Unknown OS... cannot open browser window.") warn("Unknown OS... cannot open browser window.")

View File

@ -58,7 +58,7 @@ end
"get an array of tuples of points on a circle with radius `r`" "get an array of tuples of points on a circle with radius `r`"
function partialcircle(start_θ, end_θ, n = 20, r=1) function partialcircle(start_θ, end_θ, n = 20, r=1)
Tuple{Float64,Float64}[(r*cos(u),r*sin(u)) for u in linspace(start_θ, end_θ, n)] Tuple{Float64,Float64}[(r*cos(u),r*sin(u)) for u in range(start_θ, stop=end_θ, length=n)]
end end
"interleave 2 vectors into each other (like a zipper's teeth)" "interleave 2 vectors into each other (like a zipper's teeth)"
@ -68,7 +68,8 @@ function weave(x,y; ordering = Vector[x,y])
while !done while !done
for o in ordering for o in ordering
try try
push!(ret, shift!(o)) push!(ret, popfirst!(o))
catch
end end
end end
done = isempty(x) && isempty(y) done = isempty(x) && isempty(y)
@ -388,6 +389,7 @@ function stroke(args...; alpha = nothing)
elseif T <: Symbol || T <: AbstractString elseif T <: Symbol || T <: AbstractString
try try
color = parse(Colorant, string(arg)) color = parse(Colorant, string(arg))
catch
end end
elseif allAlphas(arg) elseif allAlphas(arg)
alpha = arg alpha = arg
@ -420,6 +422,7 @@ function brush(args...; alpha = nothing)
elseif T <: Symbol || T <: AbstractString elseif T <: Symbol || T <: AbstractString
try try
color = parse(Colorant, string(arg)) color = parse(Colorant, string(arg))
catch
end end
elseif allAlphas(arg) elseif allAlphas(arg)
alpha = arg alpha = arg
@ -438,16 +441,16 @@ end
mutable struct SeriesAnnotations mutable struct SeriesAnnotations
strs::AbstractVector # the labels/names strs::AbstractVector # the labels/names
font::Font font::Font
baseshape::Nullable baseshape::Union{Any, Nothing}
scalefactor::Tuple scalefactor::Tuple
end end
function series_annotations(strs::AbstractVector, args...) function series_annotations(strs::AbstractVector, args...)
fnt = font() fnt = font()
shp = Nullable{Any}() shp = Union{Any, Nothing}()
scalefactor = (1,1) scalefactor = (1,1)
for arg in args for arg in args
if isa(arg, Shape) || (isa(arg, AbstractVector) && eltype(arg) == Shape) if isa(arg, Shape) || (isa(arg, AbstractVector) && eltype(arg) == Shape)
shp = Nullable(arg) shp = Union{Any, Nothing}(arg)
elseif isa(arg, Font) elseif isa(arg, Font)
fnt = arg fnt = arg
elseif isa(arg, Symbol) && haskey(_shapes, arg) elseif isa(arg, Symbol) && haskey(_shapes, arg)
@ -468,7 +471,7 @@ function series_annotations(strs::AbstractVector, args...)
SeriesAnnotations(strs, fnt, shp, scalefactor) SeriesAnnotations(strs, fnt, shp, scalefactor)
end end
series_annotations(anns::SeriesAnnotations) = anns series_annotations(anns::SeriesAnnotations) = anns
series_annotations(::Void) = nothing series_annotations(::Nothing) = nothing
function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels) function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels)
anns = series[:series_annotations] anns = series[:series_annotations]
@ -483,7 +486,7 @@ function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels)
# end # end
# @show msw msh # @show msw msh
if anns != nothing && !isnull(anns.baseshape) if anns != nothing && (anns.baseshape != nothing)
# we use baseshape to overwrite the markershape attribute # we use baseshape to overwrite the markershape attribute
# with a list of custom shapes for each # with a list of custom shapes for each
msw,msh = anns.scalefactor msw,msh = anns.scalefactor
@ -531,7 +534,7 @@ function Base.next(ea::EachAnn, i)
((_cycle(ea.x,i), _cycle(ea.y,i), str, fnt), i+1) ((_cycle(ea.x,i), _cycle(ea.y,i), str, fnt), i+1)
end end
annotations(::Void) = [] annotations(::Nothing) = []
annotations(anns::AVec) = anns annotations(anns::AVec) = anns
annotations(anns) = Any[anns] annotations(anns) = Any[anns]
annotations(sa::SeriesAnnotations) = sa annotations(sa::SeriesAnnotations) = sa
@ -747,7 +750,7 @@ end
@deprecate curve_points coords @deprecate curve_points coords
coords(curve::BezierCurve, n::Integer = 30; range = [0,1]) = map(curve, linspace(range..., n)) coords(curve::BezierCurve, n::Integer = 30; limits = [0,1]) = map(curve, range(limits[1],stop=limits[2], length=n))
# build a BezierCurve which leaves point p vertically upwards and arrives point q vertically upwards. # build a BezierCurve which leaves point p vertically upwards and arrives point q vertically upwards.
# may create a loop if necessary. Assumes the view is [0,1] # may create a loop if necessary. Assumes the view is [0,1]

View File

@ -8,7 +8,9 @@ mutable struct PlotExample
end end
# the _examples we'll run for each # the _examples we'll run for each
const _examples = PlotExample[ # FIXME: suppress explicit typing of array until parser is fixed
#const _examples = PlotExample[
const _examples = [
PlotExample("Lines", PlotExample("Lines",
"A simple line plot of the columns.", "A simple line plot of the columns.",
@ -29,7 +31,7 @@ animation.
[:(begin [:(begin
p = plot([sin,cos], zeros(0), leg=false) p = plot([sin,cos], zeros(0), leg=false)
anim = Animation() anim = Animation()
for x in linspace(0, 10π, 100) for x in range(0, stop=10π, length=100)
push!(p, x, Float64[sin(x), cos(x)]) push!(p, x, Float64[sin(x), cos(x)])
frame(anim) frame(anim)
end end
@ -156,8 +158,8 @@ PlotExample("Marker types",
markers = filter(m -> m in Plots.supported_markers(), Plots._shape_keys) markers = filter(m -> m in Plots.supported_markers(), Plots._shape_keys)
markers = reshape(markers, 1, length(markers)) markers = reshape(markers, 1, length(markers))
n = length(markers) n = length(markers)
x = linspace(0,10,n+2)[2:end-1] x = range(0,stop=10,length=n+2)[2:end-1]
y = repmat(reshape(reverse(x),1,:), n, 1) y = repeat(reshape(reverse(x),1,:), n, 1)
scatter(x, y, m=(8,:auto), lab=map(string,markers), bg=:linen, xlim=(0,10), ylim=(0,10)) scatter(x, y, m=(8,:auto), lab=map(string,markers), bg=:linen, xlim=(0,10), ylim=(0,10))
end)] end)]
), ),
@ -238,7 +240,7 @@ y = rand(10)
plot(y, annotations = (3,y[3],text("this is #3",:left)), leg=false) plot(y, annotations = (3,y[3],text("this is #3",:left)), leg=false)
annotate!([(5, y[5], text("this is #5",16,:red,:center)), annotate!([(5, y[5], text("this is #5",16,:red,:center)),
(10, y[10], text("this is #10",:right,20,"courier"))]) (10, y[10], text("this is #10",:right,20,"courier"))])
scatter!(linspace(2,8,6), rand(6), marker=(50,0.2,:orange), scatter!(range(2,stop=8,length=6), rand(6), marker=(50,0.2,:orange),
series_annotations = ["series","annotations","map","to","series", series_annotations = ["series","annotations","map","to","series",
text("data",:green)]) text("data",:green)])
end)] end)]
@ -269,8 +271,8 @@ unfilled contour from a matrix.
x = 1:0.5:20 x = 1:0.5:20
y = 1:0.5:10 y = 1:0.5:10
f(x,y) = (3x+y^2)*abs(sin(x)+cos(y)) f(x,y) = (3x+y^2)*abs(sin(x)+cos(y))
X = repmat(reshape(x,1,:), length(y), 1) X = repeat(reshape(x,1,:), length(y), 1)
Y = repmat(y, 1, length(x)) Y = repeat(y, 1, length(x))
Z = map(f, X, Y) Z = map(f, X, Y)
p1 = contour(x, y, f, fill=true) p1 = contour(x, y, f, fill=true)
p2 = contour(x, y, Z) p2 = contour(x, y, Z)
@ -291,7 +293,7 @@ PlotExample("3D",
"", "",
[:(begin [:(begin
n = 100 n = 100
ts = linspace(0,8π,n) ts = range(0,stop=8π,length=n)
x = ts .* map(cos,ts) x = ts .* map(cos,ts)
y = 0.1ts .* map(sin,ts) y = 0.1ts .* map(sin,ts)
z = 1:n z = 1:n
@ -323,7 +325,7 @@ PlotExample("Groups and Subplots",
PlotExample("Polar Plots", PlotExample("Polar Plots",
"", "",
[:(begin [:(begin
Θ = linspace(0,1.5π,100) Θ = range(0,stop=1.5π,length=100)
r = abs.(0.1randn(100)+sin.(3Θ)) r = abs.(0.1randn(100)+sin.(3Θ))
plot(Θ, r, proj=:polar, m=2) plot(Θ, r, proj=:polar, m=2)
end)] end)]
@ -368,7 +370,7 @@ PlotExample("Animation with subplots",
plot(log,1,xlims=(1,10π),ylims=(0,5),leg=false),layout=l) plot(log,1,xlims=(1,10π),ylims=(0,5),leg=false),layout=l)
anim = Animation() anim = Animation()
for x = linspace(1,10π,100) for x = range(1,stop=10π,length=100)
plot(push!(p,x,Float64[sin(x),cos(x),atan(x),cos(x),log(x)])) plot(push!(p,x,Float64[sin(x),cos(x),atan(x),cos(x),log(x)]))
frame(anim) frame(anim)
end end
@ -411,7 +413,7 @@ attribute. The default framestyle is `:axes`.
scatter(fill(randn(10), 6), fill(randn(10), 6), scatter(fill(randn(10), 6), fill(randn(10), 6),
framestyle = [:box :semi :origin :zerolines :grid :none], framestyle = [:box :semi :origin :zerolines :grid :none],
title = [":box" ":semi" ":origin" ":zerolines" ":grid" ":none"], title = [":box" ":semi" ":origin" ":zerolines" ":grid" ":none"],
color = RowVector(1:6), layout = 6, label = "", markerstrokewidth = 0, color = Transpose(1:6), layout = 6, label = "", markerstrokewidth = 0,
ticks = -2:2) ticks = -2:2)
end)] end)]
), ),
@ -422,7 +424,7 @@ You can use the `line_z` and `marker_z` properties to associate a color with
each line segment or marker in the plot. each line segment or marker in the plot.
""", """,
[:(begin [:(begin
t = linspace(0, 1, 100) t = range(0, stop=1, length=100)
θ = 6π .* t θ = 6π .* t
x = t .* cos.(θ) x = t .* cos.(θ)
y = t .* sin.(θ) y = t .* sin.(θ)

View File

@ -268,7 +268,7 @@ function GridLayout(dims...;
widths = zeros(dims[2]), widths = zeros(dims[2]),
heights = zeros(dims[1]), heights = zeros(dims[1]),
kw...) kw...)
grid = Matrix{AbstractLayout}(dims...) grid = Matrix{AbstractLayout}(undef,dims...)
layout = GridLayout( layout = GridLayout(
parent, parent,
(20mm, 5mm, 2mm, 10mm), (20mm, 5mm, 2mm, 10mm),
@ -357,10 +357,10 @@ function update_child_bboxes!(layout::GridLayout, minimum_perimeter = [0mm,0mm,0
# get the max horizontal (left and right) padding over columns, # get the max horizontal (left and right) padding over columns,
# and max vertical (bottom and top) padding over rows # and max vertical (bottom and top) padding over rows
# TODO: add extra padding here # TODO: add extra padding here
pad_left = maximum(minpad_left, 1) pad_left = maximum(minpad_left, dims=1)
pad_top = maximum(minpad_top, 2) pad_top = maximum(minpad_top, dims=2)
pad_right = maximum(minpad_right, 1) pad_right = maximum(minpad_right, dims=1)
pad_bottom = maximum(minpad_bottom, 2) pad_bottom = maximum(minpad_bottom, dims=2)
# make sure the perimeter match the parent # make sure the perimeter match the parent
pad_left[1] = max(pad_left[1], minimum_perimeter[1]) pad_left[1] = max(pad_left[1], minimum_perimeter[1])

View File

@ -146,7 +146,7 @@ function Base.display(::PlotsDisplay, plt::Plot)
end end
# override the REPL display to open a gui window # override the REPL display to open a gui window
Base.display(::Base.REPL.REPLDisplay, ::MIME"text/plain", plt::Plot) = gui(plt) Base.display(::REPLDisplay, ::MIME"text/plain", plt::Plot) = gui(plt)
_do_plot_show(plt, showval::Bool) = showval && gui(plt) _do_plot_show(plt, showval::Bool) = showval && gui(plt)
@ -254,7 +254,7 @@ end
# IJulia # IJulia
# --------------------------------------------------------- # ---------------------------------------------------------
@require IJulia begin @require IJulia="7073ff75-c697-5162-941a-fcdaad2a7d2a" begin
if IJulia.inited if IJulia.inited
""" """
@ -310,7 +310,7 @@ end
# --------------------------------------------------------- # ---------------------------------------------------------
# Atom PlotPane # Atom PlotPane
# --------------------------------------------------------- # ---------------------------------------------------------
@require Juno begin @require Juno="e5e0dc1b-0480-54bc-9374-aad01c23163d" begin
import Hiccup, Media import Hiccup, Media
if Juno.isactive() if Juno.isactive()

View File

@ -70,7 +70,7 @@ function _process_userrecipes(plt::Plot, d::KW, args)
# grab the first in line to be processed and either add it to the kw_list or # grab the first in line to be processed and either add it to the kw_list or
# pass it through apply_recipe to generate a list of RecipeData objects (data + attributes) # pass it through apply_recipe to generate a list of RecipeData objects (data + attributes)
# for further processing. # for further processing.
next_series = shift!(still_to_process) next_series = popfirst!(still_to_process)
# recipedata should be of type RecipeData. if it's not then the inputs must not have been fully processed by recipes # recipedata should be of type RecipeData. if it's not then the inputs must not have been fully processed by recipes
if !(typeof(next_series) <: RecipeData) if !(typeof(next_series) <: RecipeData)
error("Inputs couldn't be processed... expected RecipeData but got: $next_series") error("Inputs couldn't be processed... expected RecipeData but got: $next_series")
@ -329,7 +329,7 @@ function _override_seriestype_check(d::KW, st::Symbol)
# do we want to override the series type? # do we want to override the series type?
if !is3d(st) && !(st in (:contour,:contour3d)) if !is3d(st) && !(st in (:contour,:contour3d))
z = d[:z] z = d[:z]
if !isa(z, Void) && (size(d[:x]) == size(d[:y]) == size(z)) if !isa(z, Nothing) && (size(d[:x]) == size(d[:y]) == size(z))
st = (st == :scatter ? :scatter3d : :path3d) st = (st == :scatter ? :scatter3d : :path3d)
d[:seriestype] = st d[:seriestype] = st
end end

View File

@ -1,10 +1,10 @@
mutable struct CurrentPlot mutable struct CurrentPlot
nullableplot::Nullable{AbstractPlot} nullableplot::Union{AbstractPlot, Nothing}
end end
const CURRENT_PLOT = CurrentPlot(Nullable{AbstractPlot}()) const CURRENT_PLOT = CurrentPlot(nothing)
isplotnull() = isnull(CURRENT_PLOT.nullableplot) isplotnull() = CURRENT_PLOT.nullableplot == nothing
""" """
current() current()
@ -14,9 +14,9 @@ function current()
if isplotnull() if isplotnull()
error("No current plot/subplot") error("No current plot/subplot")
end end
get(CURRENT_PLOT.nullableplot) CURRENT_PLOT.nullableplot
end end
current(plot::AbstractPlot) = (CURRENT_PLOT.nullableplot = Nullable(plot)) current(plot::AbstractPlot) = (CURRENT_PLOT.nullableplot = plot)
# --------------------------------------------------------- # ---------------------------------------------------------
@ -46,9 +46,8 @@ When you pass in matrices, it splits by columns. To see the list of available at
function, where `attr` is the symbol `:Series:`, `:Subplot:`, `:Plot` or `:Axis`. Pass any attribute to `plotattr` function, where `attr` is the symbol `:Series:`, `:Subplot:`, `:Plot` or `:Axis`. Pass any attribute to `plotattr`
as a String to look up its docstring; e.g. `plotattr("seriestype")`. as a String to look up its docstring; e.g. `plotattr("seriestype")`.
""" """
# this creates a new plot with args/kw and sets it to be the current plot
function plot(args...; kw...) function plot(args...; kw...)
# this creates a new plot with args/kw and sets it to be the current plot
d = KW(kw) d = KW(kw)
preprocessArgs!(d) preprocessArgs!(d)
@ -193,7 +192,7 @@ function _plot!(plt::Plot, d::KW, args::Tuple)
still_to_process = kw_list still_to_process = kw_list
kw_list = KW[] kw_list = KW[]
while !isempty(still_to_process) while !isempty(still_to_process)
next_kw = shift!(still_to_process) next_kw = popfirst!(still_to_process)
_process_plotrecipe(plt, next_kw, kw_list, still_to_process) _process_plotrecipe(plt, next_kw, kw_list, still_to_process)
end end

View File

@ -80,7 +80,7 @@ end
@recipe function f(::Type{Val{:hline}}, x, y, z) @recipe function f(::Type{Val{:hline}}, x, y, z)
n = length(y) n = length(y)
newx = repmat(Float64[-1, 1, NaN], n) newx = repeat(Float64[-1, 1, NaN], n)
newy = vec(Float64[yi for i=1:3,yi=y]) newy = vec(Float64[yi for i=1:3,yi=y])
x := newx x := newx
y := newy y := newy
@ -92,7 +92,7 @@ end
@recipe function f(::Type{Val{:vline}}, x, y, z) @recipe function f(::Type{Val{:vline}}, x, y, z)
n = length(y) n = length(y)
newx = vec(Float64[yi for i=1:3,yi=y]) newx = vec(Float64[yi for i=1:3,yi=y])
newy = repmat(Float64[-1, 1, NaN], n) newy = repeat(Float64[-1, 1, NaN], n)
x := newx x := newx
y := newy y := newy
seriestype := :straightline seriestype := :straightline
@ -284,7 +284,7 @@ end
# where the points are the control points of the curve # where the points are the control points of the curve
for rng in iter_segments(args...) for rng in iter_segments(args...)
length(rng) < 2 && continue length(rng) < 2 && continue
ts = linspace(0, 1, npoints) ts = range(0, stop=1, length=npoints)
nanappend!(newx, map(t -> bezier_value(_cycle(x,rng), t), ts)) nanappend!(newx, map(t -> bezier_value(_cycle(x,rng), t), ts))
nanappend!(newy, map(t -> bezier_value(_cycle(y,rng), t), ts)) nanappend!(newy, map(t -> bezier_value(_cycle(y,rng), t), ts))
if z != nothing if z != nothing
@ -620,10 +620,10 @@ _hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::Symbol) where {N
_hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::AbstractVector) where {N} = binning _hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::AbstractVector) where {N} = binning
_hist_edges(vs::NTuple{N,AbstractVector}, binning::NTuple{N}) where {N} = _hist_edges(vs::NTuple{N,AbstractVector}, binning::NTuple{N}) where {N} =
map(dim -> _hist_edge(vs, dim, binning[dim]), (1:N...)) map(dim -> _hist_edge(vs, dim, binning[dim]), (1:N...,))
_hist_edges(vs::NTuple{N,AbstractVector}, binning::Union{Integer, Symbol, AbstractVector}) where {N} = _hist_edges(vs::NTuple{N,AbstractVector}, binning::Union{Integer, Symbol, AbstractVector}) where {N} =
map(dim -> _hist_edge(vs, dim, binning), (1:N...)) map(dim -> _hist_edge(vs, dim, binning), (1:N...,))
_hist_norm_mode(mode::Symbol) = mode _hist_norm_mode(mode::Symbol) = mode
_hist_norm_mode(mode::Bool) = mode ? :pdf : :none _hist_norm_mode(mode::Bool) = mode ? :pdf : :none

View File

@ -14,7 +14,7 @@ all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surfac
convertToAnyVector(x, d::KW) = error("No user recipe defined for $(typeof(x))") convertToAnyVector(x, d::KW) = error("No user recipe defined for $(typeof(x))")
# missing # missing
convertToAnyVector(v::Void, d::KW) = Any[nothing], nothing convertToAnyVector(v::Nothing, d::KW) = Any[nothing], nothing
# fixed number of blank series # fixed number of blank series
convertToAnyVector(n::Integer, d::KW) = Any[zeros(0) for i in 1:n], nothing convertToAnyVector(n::Integer, d::KW) = Any[zeros(0) for i in 1:n], nothing
@ -46,7 +46,7 @@ convertToAnyVector(v::Volume, d::KW) = Any[v], nothing
# convertToAnyVector(v::AVec{OHLC}, d::KW) = Any[v], nothing # convertToAnyVector(v::AVec{OHLC}, d::KW) = Any[v], nothing
# # dates # # dates
convertToAnyVector{D<:Union{Date,DateTime}}(dts::AVec{D}, d::KW) = Any[dts], nothing convertToAnyVector(dts::AVec{D}, d::KW) where {D<:Union{Date,DateTime}} = Any[dts], nothing
# list of things (maybe other vectors, functions, or something else) # list of things (maybe other vectors, functions, or something else)
function convertToAnyVector(v::AVec, d::KW) function convertToAnyVector(v::AVec, d::KW)
@ -72,19 +72,19 @@ end
# TODO: can we avoid the copy here? one error that crops up is that mapping functions over the same array # TODO: can we avoid the copy here? one error that crops up is that mapping functions over the same array
# result in that array being shared. push!, etc will add too many items to that array # result in that array being shared. push!, etc will add too many items to that array
compute_x(x::Void, y::Void, z) = 1:size(z,1) compute_x(x::Nothing, y::Nothing, z) = 1:size(z,1)
compute_x(x::Void, y, z) = 1:size(y,1) compute_x(x::Nothing, y, z) = 1:size(y,1)
compute_x(x::Function, y, z) = map(x, y) compute_x(x::Function, y, z) = map(x, y)
compute_x(x, y, z) = copy(x) compute_x(x, y, z) = copy(x)
# compute_y(x::Void, y::Function, z) = error() # compute_y(x::Nothing, y::Function, z) = error()
compute_y(x::Void, y::Void, z) = 1:size(z,2) compute_y(x::Nothing, y::Nothing, z) = 1:size(z,2)
compute_y(x, y::Function, z) = map(y, x) compute_y(x, y::Function, z) = map(y, x)
compute_y(x, y, z) = copy(y) compute_y(x, y, z) = copy(y)
compute_z(x, y, z::Function) = map(z, x, y) compute_z(x, y, z::Function) = map(z, x, y)
compute_z(x, y, z::AbstractMatrix) = Surface(z) compute_z(x, y, z::AbstractMatrix) = Surface(z)
compute_z(x, y, z::Void) = nothing compute_z(x, y, z::Nothing) = nothing
compute_z(x, y, z) = copy(z) compute_z(x, y, z) = copy(z)
nobigs(v::AVec{BigFloat}) = map(Float64, v) nobigs(v::AVec{BigFloat}) = map(Float64, v)
@ -99,9 +99,9 @@ nobigs(v) = v
end end
# not allowed # not allowed
compute_xyz(x::Void, y::FuncOrFuncs{F}, z) where {F<:Function} = error("If you want to plot the function `$y`, you need to define the x values!") compute_xyz(x::Nothing, y::FuncOrFuncs{F}, z) where {F<:Function} = error("If you want to plot the function `$y`, you need to define the x values!")
compute_xyz(x::Void, y::Void, z::FuncOrFuncs{F}) where {F<:Function} = error("If you want to plot the function `$z`, you need to define x and y values!") compute_xyz(x::Nothing, y::Nothing, z::FuncOrFuncs{F}) where {F<:Function} = error("If you want to plot the function `$z`, you need to define x and y values!")
compute_xyz(x::Void, y::Void, z::Void) = error("x/y/z are all nothing!") compute_xyz(x::Nothing, y::Nothing, z::Nothing) = error("x/y/z are all nothing!")
# -------------------------------------------------------------------- # --------------------------------------------------------------------
@ -518,7 +518,7 @@ end
xs, fs xs, fs
end end
@recipe f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, u::AVec) where {F<:Function,G<:Function} = mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u) @recipe f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, u::AVec) where {F<:Function,G<:Function} = mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u)
@recipe f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, umin::Number, umax::Number, n = 200) where {F<:Function,G<:Function} = fx, fy, linspace(umin, umax, n) @recipe f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, umin::Number, umax::Number, n = 200) where {F<:Function,G<:Function} = fx, fy, range(umin, stop=umax, length=n)
# #
# # special handling... 3D parametric function(s) # # special handling... 3D parametric function(s)
@ -526,7 +526,7 @@ end
mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u), mapFuncOrFuncs(fz, u) mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u), mapFuncOrFuncs(fz, u)
end end
@recipe function f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, fz::FuncOrFuncs{H}, umin::Number, umax::Number, numPoints = 200) where {F<:Function,G<:Function,H<:Function} @recipe function f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, fz::FuncOrFuncs{H}, umin::Number, umax::Number, numPoints = 200) where {F<:Function,G<:Function,H<:Function}
fx, fy, fz, linspace(umin, umax, numPoints) fx, fy, fz, range(umin, stop=umax, length=numPoints)
end end
# #

View File

@ -132,7 +132,7 @@ _get_showtheme_args(thm::Symbol, func::Symbol) = thm, get(_color_functions, func
f(r) = sin(r) / r f(r) = sin(r) / r
_norm(x, y) = norm([x, y]) _norm(x, y) = norm([x, y])
x = y = linspace(-3π, 3π, 30) x = y = range(-3π, stop=3π, length=30)
z = f.(_norm.(x, y')) z = f.(_norm.(x, y'))
wi = 2:3:30 wi = 2:3:30
@ -152,7 +152,7 @@ _get_showtheme_args(thm::Symbol, func::Symbol) = thm, get(_color_functions, func
end end
n = 100 n = 100
ts = linspace(0, 10π, n) ts = range(0, stop=10π, length=n)
x = ts .* cos.(ts) x = ts .* cos.(ts)
y = (0.1ts) .* sin.(ts) y = (0.1ts) .* sin.(ts)
z = 1:n z = 1:n

View File

@ -6,7 +6,7 @@ const AVec = AbstractVector
const AMat = AbstractMatrix const AMat = AbstractMatrix
const KW = Dict{Symbol,Any} const KW = Dict{Symbol,Any}
struct PlotsDisplay <: Display end struct PlotsDisplay <: AbstractDisplay end
# ----------------------------------------------------------- # -----------------------------------------------------------

View File

@ -4,7 +4,7 @@ calcMidpoints(edges::AbstractVector) = Float64[0.5 * (edges[i] + edges[i+1]) for
"Make histogram-like bins of data" "Make histogram-like bins of data"
function binData(data, nbins) function binData(data, nbins)
lo, hi = ignorenan_extrema(data) lo, hi = ignorenan_extrema(data)
edges = collect(linspace(lo, hi, nbins+1)) edges = collect(range(lo, stop=hi, length=nbins+1))
midpoints = calcMidpoints(edges) midpoints = calcMidpoints(edges)
buckets = Int[max(2, min(searchsortedfirst(edges, x), length(edges)))-1 for x in data] buckets = Int[max(2, min(searchsortedfirst(edges, x), length(edges)))-1 for x in data]
counts = zeros(Int, length(midpoints)) counts = zeros(Int, length(midpoints))
@ -119,7 +119,7 @@ function replace_image_with_heatmap(z::Array{T}) where T<:Colorant
n, m = size(z) n, m = size(z)
# idx = 0 # idx = 0
colors = ColorGradient(vec(z)) colors = ColorGradient(vec(z))
newz = reshape(linspace(0, 1, n*m), n, m) newz = reshape(range(0, stop=1, length=n*m), n, m)
newz, colors newz, colors
# newz = zeros(n, m) # newz = zeros(n, m)
# for i=1:n, j=1:m # for i=1:n, j=1:m
@ -259,7 +259,7 @@ float_extended_type(x::AbstractArray{T}) where {T<:Real} = Float64
nop() = nothing nop() = nothing
notimpl() = error("This has not been implemented yet") notimpl() = error("This has not been implemented yet")
isnothing(x::Void) = true isnothing(x::Nothing) = true
isnothing(x) = false isnothing(x) = false
_cycle(wrapper::InputWrapper, idx::Int) = wrapper.obj _cycle(wrapper::InputWrapper, idx::Int) = wrapper.obj
@ -305,7 +305,7 @@ function _expand_limits(lims, x)
e1, e2 = ignorenan_extrema(x) e1, e2 = ignorenan_extrema(x)
lims[1] = NaNMath.min(lims[1], e1) lims[1] = NaNMath.min(lims[1], e1)
lims[2] = NaNMath.max(lims[2], e2) lims[2] = NaNMath.max(lims[2], e2)
# catch err catch err
# warn(err) # warn(err)
end end
nothing nothing
@ -343,7 +343,7 @@ function replaceAliases!(d::KW, aliases::Dict{Symbol,Symbol})
end end
end end
createSegments(z) = collect(repmat(reshape(z,1,:),2,1))[2:end] createSegments(z) = collect(repeat(reshape(z,1,:),2,1))[2:end]
Base.first(c::Colorant) = c Base.first(c::Colorant) = c
Base.first(x::Symbol) = x Base.first(x::Symbol) = x
@ -355,7 +355,7 @@ sortedkeys(d::Dict) = sort(collect(keys(d)))
const _scale_base = Dict{Symbol, Real}( const _scale_base = Dict{Symbol, Real}(
:log10 => 10, :log10 => 10,
:log2 => 2, :log2 => 2,
:ln => e, :ln => euler_e
) )
function _heatmap_edges(v::AVec) function _heatmap_edges(v::AVec)
@ -450,8 +450,8 @@ limsType(lims) = :invalid
# axis_Symbol(letter, postfix) = Symbol(letter * postfix) # axis_Symbol(letter, postfix) = Symbol(letter * postfix)
# axis_symbols(letter, postfix...) = map(s -> axis_Symbol(letter, s), postfix) # axis_symbols(letter, postfix...) = map(s -> axis_Symbol(letter, s), postfix)
Base.convert(::Type{Vector{T}}, rng::Range{T}) where {T<:Real} = T[x for x in rng] Base.convert(::Type{Vector{T}}, rng::AbstractRange{T}) where {T<:Real} = T[x for x in rng]
Base.convert(::Type{Vector{T}}, rng::Range{S}) where {T<:Real,S<:Real} = T[x for x in rng] Base.convert(::Type{Vector{T}}, rng::AbstractRange{S}) where {T<:Real,S<:Real} = T[x for x in rng]
Base.merge(a::AbstractVector, b::AbstractVector) = sort(unique(vcat(a,b))) Base.merge(a::AbstractVector, b::AbstractVector) = sort(unique(vcat(a,b)))
@ -846,8 +846,8 @@ end
extendSeriesByOne(v::UnitRange{Int}, n::Int = 1) = isempty(v) ? (1:n) : (minimum(v):maximum(v)+n) extendSeriesByOne(v::UnitRange{Int}, n::Int = 1) = isempty(v) ? (1:n) : (minimum(v):maximum(v)+n)
extendSeriesByOne(v::AVec, n::Integer = 1) = isempty(v) ? (1:n) : vcat(v, (1:n) + ignorenan_maximum(v)) extendSeriesByOne(v::AVec, n::Integer = 1) = isempty(v) ? (1:n) : vcat(v, (1:n) + ignorenan_maximum(v))
extendSeriesData(v::Range{T}, z::Real) where {T} = extendSeriesData(float(collect(v)), z) extendSeriesData(v::AbstractRange{T}, z::Real) where {T} = extendSeriesData(float(collect(v)), z)
extendSeriesData(v::Range{T}, z::AVec) where {T} = extendSeriesData(float(collect(v)), z) extendSeriesData(v::AbstractRange{T}, z::AVec) where {T} = extendSeriesData(float(collect(v)), z)
extendSeriesData(v::AVec{T}, z::Real) where {T} = (push!(v, convert(T, z)); v) extendSeriesData(v::AVec{T}, z::Real) where {T} = (push!(v, convert(T, z)); v)
extendSeriesData(v::AVec{T}, z::AVec) where {T} = (append!(v, convert(Vector{T}, z)); v) extendSeriesData(v::AVec{T}, z::AVec) where {T} = (append!(v, convert(Vector{T}, z)); v)
@ -856,7 +856,7 @@ extendSeriesData(v::AVec{T}, z::AVec) where {T} = (append!(v, convert(Ve
# NOTE: backends should implement the following methods to get/set the x/y/z data objects # NOTE: backends should implement the following methods to get/set the x/y/z data objects
tovec(v::AbstractVector) = v tovec(v::AbstractVector) = v
tovec(v::Void) = zeros(0) tovec(v::Nothing) = zeros(0)
function getxy(plt::Plot, i::Integer) function getxy(plt::Plot, i::Integer)
d = plt.series_list[i].d d = plt.series_list[i].d
@ -1138,9 +1138,9 @@ function convert_sci_unicode(label::AbstractString)
"×10" => "×10^{", "×10" => "×10^{",
) )
for key in keys(unicode_dict) for key in keys(unicode_dict)
label = replace(label, key, unicode_dict[key]) label = replace(label, key => unicode_dict[key])
end end
if contains(label, "10^{") if occursin("10^{", label)
label = string(label, "}") label = string(label, "}")
end end
label label

View File

@ -1,7 +1,7 @@
StatPlots StatPlots
Images Images
ImageMagick ImageMagick
@osx QuartzImageIO # @osx QuartzImageIO
GR 0.31.0 GR 0.31.0
RDatasets RDatasets
VisualRegressionTests VisualRegressionTests

View File

@ -4,17 +4,28 @@ using VisualRegressionTests
import DataFrames, RDatasets import DataFrames, RDatasets
# don't let pyplot use a gui... it'll crash # FIXME: pending update of PlotReferenceImages to a proper package
# note: Agg will set gui -> :none in PyPlot # import PlotReferenceImages
ENV["MPLBACKEND"] = "Agg"
try if !isdefined(@__MODULE__,:backends2test)
@eval import PyPlot backends2test = Symbol.(lowercase.(
info("Matplotlib version: $(PyPlot.matplotlib[:__version__])") split(get(ENV,"PLOTS_TEST_BACKENDS","GR:UnicodePlots"),":")))
end end
if :pyplot backends2test
# don't let pyplot use a gui... it'll crash
# note: Agg will set gui -> :none in PyPlot
ENV["MPLBACKEND"] = "Agg"
try
@eval import PyPlot
info("Matplotlib version: $(PyPlot.matplotlib[:__version__])")
catch
end
end
using Plots using Plots
using StatPlots info("Suppressing StatPlots until dependencies are ready")
# using StatPlots
using Base.Test using Base.Test
default(size=(500,300)) default(size=(500,300))
@ -38,7 +49,14 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = is
# reference image directory setup # reference image directory setup
# refdir = joinpath(Pkg.dir("ExamplePlots"), "test", "refimg", string(pkg)) # refdir = joinpath(Pkg.dir("ExamplePlots"), "test", "refimg", string(pkg))
refdir = Pkg.dir("PlotReferenceImages", "Plots", string(pkg))
# FIXME: this needs for PlotReferenceImages to be properly instantiated
# refdir0 = Base.find_package(@__MODULE__,"PlotReferenceImages")
refdir0 = joinpath(ENV["HOME"],".julia","packages","PlotReferenceImages","Rtul")
refdir0 == nothing && error("Failed to find PlotReferenceImages")
refdir = joinpath(refdir0, "Plots", string(pkg))
isdir(refdir) || error("$pkg not found in PlotReferenceImages")
fn = "ref$idx.png" fn = "ref$idx.png"
# firgure out version info # firgure out version info

View File

@ -1,5 +1,10 @@
module PlotsTests module PlotsTests
# The backends to test may be listed in a colon-delimited environment
# variable
backends2test = Symbol.(lowercase.(
split(get(ENV,"PLOTS_TEST_BACKENDS","GR:UnicodePlots"),":")))
include("imgcomp.jl") include("imgcomp.jl")
# don't actually show the plots # don't actually show the plots
@ -7,23 +12,29 @@ srand(1234)
default(show=false, reuse=true) default(show=false, reuse=true)
img_eps = isinteractive() ? 1e-2 : 10e-2 img_eps = isinteractive() ? 1e-2 : 10e-2
if :gr backends2test
@testset "GR" begin @testset "GR" begin
ENV["PLOTS_TEST"] = "true" ENV["PLOTS_TEST"] = "true"
ENV["GKSwstype"] = "100" ENV["GKSwstype"] = "100"
@test gr() == Plots.GRBackend() @test gr() == Plots.GRBackend()
@test backend() == Plots.GRBackend() @test backend() == Plots.GRBackend()
image_comparison_facts(:gr, eps=img_eps) # image_comparison_facts(:gr, eps=img_eps)
info("Let's just get ONE working first...")
image_comparison_facts(:gr, skip=collect(range(2,stop=35)), eps=img_eps)
end
end end
if :pyplot backends2test
@testset "PyPlot" begin
@test pyplot() == Plots.PyPlotBackend()
@test backend() == Plots.PyPlotBackend()
#@testset "PyPlot" begin image_comparison_facts(:pyplot, eps=img_eps)
# @test pyplot() == Plots.PyPlotBackend() end
# @test backend() == Plots.PyPlotBackend() end
#
# image_comparison_facts(:pyplot, eps=img_eps)
#end
if :unicodeplots backends2test
@testset "UnicodePlots" begin @testset "UnicodePlots" begin
@test unicodeplots() == Plots.UnicodePlotsBackend() @test unicodeplots() == Plots.UnicodePlotsBackend()
@test backend() == Plots.UnicodePlotsBackend() @test backend() == Plots.UnicodePlotsBackend()
@ -31,57 +42,60 @@ end
# lets just make sure it runs without error # lets just make sure it runs without error
@test isa(plot(rand(10)), Plots.Plot) == true @test isa(plot(rand(10)), Plots.Plot) == true
end end
end
# The plotlyjs testimages return a connection error on travis: # The plotlyjs testimages return a connection error on travis:
# connect: connection refused (ECONNREFUSED) # connect: connection refused (ECONNREFUSED)
# @testset "PlotlyJS" begin if :plotlyjs backends2test
# @test plotlyjs() == Plots.PlotlyJSBackend() @testset "PlotlyJS" begin
# @test backend() == Plots.PlotlyJSBackend() @test plotlyjs() == Plots.PlotlyJSBackend()
# @test backend() == Plots.PlotlyJSBackend()
# if is_linux() && isinteractive() if is_linux() && isinteractive()
# image_comparison_facts(:plotlyjs, image_comparison_facts(:plotlyjs,
# skip=[ skip=[
# 2, # animation (skipped for speed) 2, # animation (skipped for speed)
# 27, # (polar plots) takes very long / not working 27, # (polar plots) takes very long / not working
# 31, # animation (skipped for speed) 31, # animation (skipped for speed)
# ], ],
# eps=img_eps) eps=img_eps)
# end end
# end end
end
# InspectDR returns that error on travis: # InspectDR returns that error on travis:
# ERROR: LoadError: InitError: Cannot open display: # ERROR: LoadError: InitError: Cannot open display:
# in Gtk.GLib.GError(::Gtk.##229#230) at /home/travis/.julia/v0.5/Gtk/src/GLib/gerror.jl:17 # in Gtk.GLib.GError(::Gtk.##229#230) at /home/travis/.julia/v0.5/Gtk/src/GLib/gerror.jl:17
# @testset "InspectDR" begin if :inspectdr backends2test
# @test inspectdr() == Plots.InspectDRBackend() @testset "InspectDR" begin
# @test backend() == Plots.InspectDRBackend() @test inspectdr() == Plots.InspectDRBackend()
# @test backend() == Plots.InspectDRBackend()
# image_comparison_facts(:inspectdr,
# skip=[
# 2, # animation
# 6, # heatmap not defined
# 10, # heatmap not defined
# 22, # contour not defined
# 23, # pie not defined
# 27, # polar plot not working
# 28, # heatmap not defined
# 31, # animation
# ],
# eps=img_eps)
# end
image_comparison_facts(:inspectdr,
skip=[
2, # animation
6, # heatmap not defined
10, # heatmap not defined
22, # contour not defined
23, # pie not defined
27, # polar plot not working
28, # heatmap not defined
31, # animation
],
eps=img_eps)
end
end
# @testset "Plotly" begin if :plotly backends2test
# @test plotly() == Plots.PlotlyBackend() @testset "Plotly" begin
# @test backend() == Plots.PlotlyBackend() @test plotly() == Plots.PlotlyBackend()
# @test backend() == Plots.PlotlyBackend()
# # # until png generation is reliable on OSX, just test on linux
# # @static is_linux() && image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], eps=img_eps)
# end
# until png generation is reliable on OSX, just test on linux
@static is_linux() && image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], eps=img_eps)
end
end
# @testset "Immerse" begin # @testset "Immerse" begin
# @test immerse() == Plots.ImmerseBackend() # @test immerse() == Plots.ImmerseBackend()

View File

@ -1,15 +1,30 @@
# This script works around some problems with
# the automated testing infrastructure
import Pkg
Pkg.add("ImageMagick") Pkg.add("ImageMagick")
Pkg.build("ImageMagick") Pkg.build("ImageMagick")
# Pkg.clone("GR") if Sys.isapple()
# Pkg.build("GR") Pkg.add("QuartzImageIO")
end
Pkg.add("VisualRegressionTests")
Pkg.add("UnicodePlots")
Pkg.clone("https://github.com/JuliaPlots/PlotReferenceImages.jl.git") # GR is currently a standard dep of Plots
# Pkg.develop("GR")
# Pkg.build("GR")
# Pkg.clone("https://github.com/JuliaStats/KernelDensity.jl.git") # Pkg.clone("https://github.com/JuliaStats/KernelDensity.jl.git")
Pkg.clone("StatPlots") # FIXME: pending working dependencies
# Pkg.checkout("PlotUtils") # Pkg.develop("StatPlots")
# Pkg.add("RDatasets")
Pkg.develop("RecipesBase")
Pkg.develop("ColorVectorSpace")
Pkg.add("https://github.com/JuliaPlots/PlotReferenceImages.jl.git")
# Pkg.clone("Blink") # Pkg.clone("Blink")
# Pkg.build("Blink") # Pkg.build("Blink")
@ -21,11 +36,15 @@ Pkg.clone("StatPlots")
# Pkg.checkout("RecipesBase") # Pkg.checkout("RecipesBase")
# Pkg.clone("VisualRegressionTests") # Pkg.clone("VisualRegressionTests")
# uncomment the following if CI tests pyplot backend:
# need this to use Conda # need this to use Conda
ENV["PYTHON"] = "" # ENV["PYTHON"] = ""
Pkg.add("PyPlot") # Pkg.add("PyPlot")
Pkg.build("PyPlot") # Pkg.build("PyPlot")
# Pkg.add("InspectDR") # Pkg.add("InspectDR")
Pkg.test("Plots"; coverage=false) # We want to run in the env we just set up, so we can't use Pkg.test()
# Pkg.test("Plots"; coverage=false)
include("runtests.jl")