Merge remote-tracking branch 'upstream/master'

t push
This commit is contained in:
Josef Heinen 2018-08-27 08:33:21 +02:00
commit 24e3fcbb6c
16 changed files with 177 additions and 181 deletions

View File

@ -43,10 +43,10 @@ before_install:
notifications: notifications:
email: true email: true
# 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 'import Pkg; Pkg.add(Pkg.PackageSpec(path=pwd())); Pkg.build("Plots")' # - julia -e 'import Pkg; Pkg.add(Pkg.PackageSpec(path=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")'
# # - julia -e 'Pkg.clone("https://github.com/tbreloff/ImageMagick.jl.git"); Pkg.checkout("ImageMagick","tb_write"); Pkg.build("ImageMagick")' # # - julia -e 'Pkg.clone("https://github.com/tbreloff/ImageMagick.jl.git"); Pkg.checkout("ImageMagick","tb_write"); Pkg.build("ImageMagick")'

View File

@ -31,8 +31,11 @@ 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, Pkg;
versioninfo();
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 "using Pkg; Pkg.test(\"Plots\")"
- C:\projects\julia\bin\julia -e "include(Pkg.dir(\"Plots\", \"test\", \"travis_commands.jl\"))"

View File

@ -116,7 +116,7 @@ ignorenan_minimum(x) = Base.minimum(x)
ignorenan_maximum(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.maximum(x) ignorenan_maximum(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.maximum(x)
ignorenan_maximum(x) = Base.maximum(x) ignorenan_maximum(x) = Base.maximum(x)
ignorenan_mean(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.mean(x) ignorenan_mean(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.mean(x)
ignorenan_mean(x) = Base.mean(x) ignorenan_mean(x) = Statistics.mean(x)
ignorenan_extrema(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.extrema(x) ignorenan_extrema(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.extrema(x)
ignorenan_extrema(x) = Base.extrema(x) ignorenan_extrema(x) = Base.extrema(x)
@ -293,18 +293,4 @@ end
const CURRENT_BACKEND = CurrentBackend(:none) const CURRENT_BACKEND = CurrentBackend(:none)
# for compatibility with Requires.jl:
@init begin
if isdefined(Main, :PLOTS_DEFAULTS)
if haskey(Main.PLOTS_DEFAULTS, :theme)
theme(Main.PLOTS_DEFAULTS[:theme])
end
for (k,v) in Main.PLOTS_DEFAULTS
k == :theme || default(k, v)
end
end
end
# ---------------------------------------------------------
end # module end # module

View File

@ -18,6 +18,7 @@ const _gr_attr = merge_with_base_supported([
:layout, :layout,
:title, :window_title, :title, :window_title,
:guide, :lims, :ticks, :scale, :flip, :guide, :lims, :ticks, :scale, :flip,
:match_dimensions,
:titlefontfamily, :titlefontsize, :titlefonthalign, :titlefontvalign, :titlefontfamily, :titlefontsize, :titlefonthalign, :titlefontvalign,
:titlefontrotation, :titlefontcolor, :titlefontrotation, :titlefontcolor,
:legendfontfamily, :legendfontsize, :legendfonthalign, :legendfontvalign, :legendfontfamily, :legendfontsize, :legendfonthalign, :legendfontvalign,
@ -338,7 +339,11 @@ end
# draw the markers, one at a time # draw the markers, one at a time
function gr_draw_markers(series::Series, x, y, msize, mz) function gr_draw_markers(series::Series, x, y, clims, msize = series[:markersize])
isempty(x) && return
GR.setfillintstyle(GR.INTSTYLE_SOLID)
shapes = series[:markershape] shapes = series[:markershape]
if shapes != :none if shapes != :none
for i=1:length(x) for i=1:length(x)
@ -355,7 +360,7 @@ function gr_draw_markers(series::Series, x, y, msize, mz)
# draw the shape - don't draw filled area if marker shape is 1D # draw the shape - don't draw filled area if marker shape is 1D
if !(shape in (:hline, :vline, :+, :x)) if !(shape in (:hline, :vline, :+, :x))
cfunc(get_markercolor(series, i)) cfunc(get_markercolor(series, clims, i))
gr_set_transparency(get_markeralpha(series, i)) gr_set_transparency(get_markeralpha(series, i))
gr_draw_marker(x[i], y[i], msi, shape) gr_draw_marker(x[i], y[i], msi, shape)
end end
@ -363,13 +368,6 @@ function gr_draw_markers(series::Series, x, y, msize, mz)
end end
end end
function gr_draw_markers(series::Series, x, y, clims)
isempty(x) && return
mz = normalize_zvals(series[:marker_z], clims)
GR.setfillintstyle(GR.INTSTYLE_SOLID)
gr_draw_markers(series, x, y, series[:markersize], mz)
end
# --------------------------------------------------------- # ---------------------------------------------------------
function gr_set_line(lw, style, c) #, a) function gr_set_line(lw, style, c) #, a)
@ -1038,7 +1036,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
GR.setfillintstyle(GR.INTSTYLE_SOLID) GR.setfillintstyle(GR.INTSTYLE_SOLID)
fr_from, fr_to = (is_2tuple(frng) ? frng : (y, frng)) fr_from, fr_to = (is_2tuple(frng) ? frng : (y, frng))
for (i, rng) in enumerate(segments) for (i, rng) in enumerate(segments)
gr_set_fillcolor(get_fillcolor(series, i)) gr_set_fillcolor(get_fillcolor(series, clims, i))
fx = _cycle(x, vcat(rng, reverse(rng))) fx = _cycle(x, vcat(rng, reverse(rng)))
fy = vcat(_cycle(fr_from,rng), _cycle(fr_to,reverse(rng))) fy = vcat(_cycle(fr_from,rng), _cycle(fr_to,reverse(rng)))
gr_set_transparency(get_fillalpha(series, i)) gr_set_transparency(get_fillalpha(series, i))
@ -1049,7 +1047,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# draw the line(s) # draw the line(s)
if st in (:path, :straightline) if st in (:path, :straightline)
for (i, rng) in enumerate(segments) for (i, rng) in enumerate(segments)
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, i)) #, series[:linealpha]) gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, clims, i)) #, series[:linealpha])
gr_set_transparency(get_linealpha(series, i)) gr_set_transparency(get_linealpha(series, i))
arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none
gr_polyline(x[rng], y[rng]; arrowside = arrowside) gr_polyline(x[rng], y[rng]; arrowside = arrowside)
@ -1129,7 +1127,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
lz = series[:line_z] lz = series[:line_z]
segments = iter_segments(series) segments = iter_segments(series)
for (i, rng) in enumerate(segments) for (i, rng) in enumerate(segments)
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, i)) #, series[:linealpha]) gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, clims, i)) #, series[:linealpha])
gr_set_transparency(get_linealpha(series, i)) gr_set_transparency(get_linealpha(series, i))
GR.polyline3d(x[rng], y[rng], z[rng]) GR.polyline3d(x[rng], y[rng], z[rng])
end end
@ -1201,12 +1199,12 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
xseg, yseg = x[rng], y[rng] xseg, yseg = x[rng], y[rng]
# draw the interior # draw the interior
gr_set_fill(get_fillcolor(series, i)) gr_set_fill(get_fillcolor(series, clims, i))
gr_set_transparency(get_fillalpha(series, i)) gr_set_transparency(get_fillalpha(series, i))
GR.fillarea(xseg, yseg) GR.fillarea(xseg, yseg)
# draw the shapes # draw the shapes
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, i)) gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, clims, i))
gr_set_transparency(get_linealpha(series, i)) gr_set_transparency(get_linealpha(series, i))
GR.polyline(xseg, yseg) GR.polyline(xseg, yseg)
end end
@ -1298,10 +1296,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
for series in series_list(sp) for series in series_list(sp)
should_add_to_legend(series) || continue should_add_to_legend(series) || continue
st = series[:seriestype] st = series[:seriestype]
gr_set_line(get_linewidth(series), get_linestyle(series), get_linecolor(series)) #, series[:linealpha]) gr_set_line(get_linewidth(series), get_linestyle(series), get_linecolor(series, clims)) #, series[:linealpha])
if (st == :shape || series[:fillrange] != nothing) && series[:ribbon] == nothing if (st == :shape || series[:fillrange] != nothing) && series[:ribbon] == nothing
gr_set_fill(get_fillcolor(series)) #, series[:fillalpha]) gr_set_fill(get_fillcolor(series, clims)) #, series[:fillalpha])
l, r = xpos-0.07, xpos-0.01 l, r = xpos-0.07, xpos-0.01
b, t = ypos-0.4dy, ypos+0.4dy b, t = ypos-0.4dy, ypos+0.4dy
x = [l, r, r, l, l] x = [l, r, r, l, l]
@ -1309,7 +1307,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
gr_set_transparency(get_fillalpha(series)) gr_set_transparency(get_fillalpha(series))
gr_polyline(x, y, GR.fillarea) gr_polyline(x, y, GR.fillarea)
gr_set_transparency(get_linealpha(series)) gr_set_transparency(get_linealpha(series))
gr_set_line(get_linewidth(series), get_linestyle(series), get_linecolor(series)) gr_set_line(get_linewidth(series), get_linestyle(series), get_linecolor(series, clims))
st == :shape && gr_polyline(x, y) st == :shape && gr_polyline(x, y)
end end
@ -1323,7 +1321,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end end
if series[:markershape] != :none if series[:markershape] != :none
gr_draw_markers(series, xpos - .035, ypos, 6, nothing) gr_draw_markers(series, xpos - .035, ypos, clims, 6)
end end
if typeof(series[:label]) <: Array if typeof(series[:label]) <: Array

View File

@ -530,11 +530,14 @@ as_gradient(grad, α) = cgrad(alpha = α)
# get a dictionary representing the series params (d is the Plots-dict, d_out is the Plotly-dict) # get a dictionary representing the series params (d is the Plots-dict, d_out is the Plotly-dict)
function plotly_series(plt::Plot, series::Series) function plotly_series(plt::Plot, series::Series)
st = series[:seriestype] st = series[:seriestype]
if st == :shape
return plotly_series_shapes(plt, series)
end
sp = series[:subplot] sp = series[:subplot]
clims = get_clims(sp)
if st == :shape
return plotly_series_shapes(plt, series, clims)
end
d_out = KW() d_out = KW()
# these are the axes that the series should be mapped to # these are the axes that the series should be mapped to
@ -564,14 +567,13 @@ function plotly_series(plt::Plot, series::Series)
d_out[:colorbar] = KW(:title => sp[:colorbar_title]) d_out[:colorbar] = KW(:title => sp[:colorbar_title])
clims = sp[:clims]
if is_2tuple(clims) if is_2tuple(clims)
d_out[:zmin], d_out[:zmax] = clims d_out[:zmin], d_out[:zmax] = clims
end end
# set the "type" # set the "type"
if st in (:path, :scatter, :scattergl, :straightline, :path3d, :scatter3d) if st in (:path, :scatter, :scattergl, :straightline, :path3d, :scatter3d)
return plotly_series_segments(series, d_out, x, y, z) return plotly_series_segments(series, d_out, x, y, z, clims)
elseif st == :heatmap elseif st == :heatmap
x = heatmap_edges(x, sp[:xaxis][:scale]) x = heatmap_edges(x, sp[:xaxis][:scale])
@ -643,7 +645,7 @@ function plotly_series(plt::Plot, series::Series)
return [d_out] return [d_out]
end end
function plotly_series_shapes(plt::Plot, series::Series) function plotly_series_shapes(plt::Plot, series::Series, clims)
segments = iter_segments(series) segments = iter_segments(series)
d_outs = Vector{KW}(undef, length(segments)) d_outs = Vector{KW}(undef, length(segments))
@ -673,11 +675,11 @@ function plotly_series_shapes(plt::Plot, series::Series)
:x => vcat(x[rng], x[rng[1]]), :x => vcat(x[rng], x[rng[1]]),
:y => vcat(y[rng], y[rng[1]]), :y => vcat(y[rng], y[rng[1]]),
:fill => "tozeroy", :fill => "tozeroy",
:fillcolor => rgba_string(plot_color(get_fillcolor(series, i), get_fillalpha(series, i))), :fillcolor => rgba_string(plot_color(get_fillcolor(series, clims, i), get_fillalpha(series, i))),
)) ))
if series[:markerstrokewidth] > 0 if series[:markerstrokewidth] > 0
d_out[:line] = KW( d_out[:line] = KW(
:color => rgba_string(plot_color(get_linecolor(series, i), get_linealpha(series, i))), :color => rgba_string(plot_color(get_linecolor(series, clims, i), get_linealpha(series, i))),
:width => get_linewidth(series, i), :width => get_linewidth(series, i),
:dash => string(get_linestyle(series, i)), :dash => string(get_linestyle(series, i)),
) )
@ -697,7 +699,7 @@ function plotly_series_shapes(plt::Plot, series::Series)
d_outs d_outs
end end
function plotly_series_segments(series::Series, d_base::KW, x, y, z) function plotly_series_segments(series::Series, d_base::KW, x, y, z, clims)
st = series[:seriestype] st = series[:seriestype]
sp = series[:subplot] sp = series[:subplot]
isscatter = st in (:scatter, :scatter3d, :scattergl) isscatter = st in (:scatter, :scatter3d, :scattergl)
@ -726,10 +728,10 @@ function plotly_series_segments(series::Series, d_base::KW, x, y, z)
end end
if series[:fillrange] == true || series[:fillrange] == 0 || isa(series[:fillrange], Tuple) if series[:fillrange] == true || series[:fillrange] == 0 || isa(series[:fillrange], Tuple)
d_out[:fill] = "tozeroy" d_out[:fill] = "tozeroy"
d_out[:fillcolor] = rgba_string(plot_color(get_fillcolor(series, i), get_fillalpha(series, i))) d_out[:fillcolor] = rgba_string(plot_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)))
elseif typeof(series[:fillrange]) <: Union{AbstractVector{<:Real}, Real} elseif typeof(series[:fillrange]) <: Union{AbstractVector{<:Real}, Real}
d_out[:fill] = "tonexty" d_out[:fill] = "tonexty"
d_out[:fillcolor] = rgba_string(plot_color(get_fillcolor(series, i), get_fillalpha(series, i))) d_out[:fillcolor] = rgba_string(plot_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)))
elseif !(series[:fillrange] in (false, nothing)) elseif !(series[:fillrange] in (false, nothing))
@warn("fillrange ignored... plotly only supports filling to zero and to a vector of values. fillrange: $(series[:fillrange])") @warn("fillrange ignored... plotly only supports filling to zero and to a vector of values. fillrange: $(series[:fillrange])")
end end
@ -751,7 +753,7 @@ function plotly_series_segments(series::Series, d_base::KW, x, y, z)
:symbol => get(_plotly_markers, _cycle(series[:markershape], i), string(_cycle(series[:markershape], i))), :symbol => get(_plotly_markers, _cycle(series[:markershape], i), string(_cycle(series[:markershape], i))),
# :opacity => series[:markeralpha], # :opacity => series[:markeralpha],
:size => 2 * _cycle(series[:markersize], i), :size => 2 * _cycle(series[:markersize], i),
:color => rgba_string(plot_color(get_markercolor(series, i), get_markeralpha(series, i))), :color => rgba_string(plot_color(get_markercolor(series, clims, i), get_markeralpha(series, i))),
:line => KW( :line => KW(
:color => rgba_string(plot_color(get_markerstrokecolor(series, i), get_markerstrokealpha(series, i))), :color => rgba_string(plot_color(get_markerstrokecolor(series, i), get_markerstrokealpha(series, i))),
:width => _cycle(series[:markerstrokewidth], i), :width => _cycle(series[:markerstrokewidth], i),
@ -762,7 +764,7 @@ function plotly_series_segments(series::Series, d_base::KW, x, y, z)
# add "line" # add "line"
if hasline if hasline
d_out[:line] = KW( d_out[:line] = KW(
:color => rgba_string(plot_color(get_linecolor(series, i), get_linealpha(series, i))), :color => rgba_string(plot_color(get_linecolor(series, clims, i), get_linealpha(series, i))),
:width => get_linewidth(series, i), :width => get_linewidth(series, i),
:shape => if st == :steppre :shape => if st == :steppre
"vh" "vh"

View File

@ -436,12 +436,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
# handle zcolor and get c/cmap # handle zcolor and get c/cmap
needs_colorbar = hascolorbar(sp) needs_colorbar = hascolorbar(sp)
extrakw = if needs_colorbar || is_2tuple(sp[:clims]) vmin, vmax = clims = get_clims(sp)
vmin, vmax = get_clims(sp)
KW(:vmin => vmin, :vmax => vmax) # Dict to store extra kwargs
else extrakw = KW(:vmin => vmin, :vmax => vmax)
KW()
end
# holds references to any python object representing the matplotlib series # holds references to any python object representing the matplotlib series
handles = [] handles = []
@ -502,7 +500,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
handle = ax[:plot]((arg[rng] for arg in xyargs)...; handle = ax[:plot]((arg[rng] for arg in xyargs)...;
label = i == 1 ? series[:label] : "", label = i == 1 ? series[:label] : "",
zorder = series[:series_plotindex], zorder = series[:series_plotindex],
color = py_color(get_linecolor(series, i), get_linealpha(series, i)), color = py_color(get_linecolor(series, clims, i), get_linealpha(series, i)),
linewidth = py_thickness_scale(plt, get_linewidth(series, i)), linewidth = py_thickness_scale(plt, get_linewidth(series, i)),
linestyle = py_linestyle(st, get_linestyle(series, i)), linestyle = py_linestyle(st, get_linestyle(series, i)),
solid_capstyle = "round", solid_capstyle = "round",
@ -544,7 +542,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
:scatter3d, :steppre, :steppost, :scatter3d, :steppre, :steppost,
:bar) :bar)
markercolor = if any(typeof(series[arg]) <: AVec for arg in (:markercolor, :markeralpha)) || series[:marker_z] != nothing markercolor = if any(typeof(series[arg]) <: AVec for arg in (:markercolor, :markeralpha)) || series[:marker_z] != nothing
py_color(plot_color.(get_markercolor.(series, eachindex(x)), get_markeralpha.(series, eachindex(x)))) # py_color(plot_color.(get_markercolor.(series, clims, eachindex(x)), get_markeralpha.(series, eachindex(x))))
[py_color(plot_color(get_markercolor(series, clims, i), get_markeralpha(series, i))) for i in eachindex(x)]
else else
py_color(plot_color(series[:markercolor], series[:markeralpha])) py_color(plot_color(series[:markercolor], series[:markeralpha]))
end end
@ -692,11 +691,6 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
elseif typeof(z) <: AbstractVector elseif typeof(z) <: AbstractVector
# tri-surface plot (http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#tri-surface-plots) # tri-surface plot (http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#tri-surface-plots)
clims = sp[:clims]
if is_2tuple(clims)
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
end
handle = ax[:plot_trisurf](x, y, z; handle = ax[:plot_trisurf](x, y, z;
label = series[:label], label = series[:label],
zorder = series[:series_plotindex], zorder = series[:series_plotindex],
@ -767,8 +761,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
path; path;
label = series[:label], label = series[:label],
zorder = series[:series_plotindex], zorder = series[:series_plotindex],
edgecolor = py_color(get_linecolor(series, i), get_linealpha(series, i)), edgecolor = py_color(get_linecolor(series, clims, i), get_linealpha(series, i)),
facecolor = py_color(get_fillcolor(series, i), get_fillalpha(series, i)), facecolor = py_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)),
linewidth = py_thickness_scale(plt, get_linewidth(series, i)), linewidth = py_thickness_scale(plt, get_linewidth(series, i)),
linestyle = py_linestyle(st, get_linestyle(series, i)), linestyle = py_linestyle(st, get_linestyle(series, i)),
fill = true fill = true
@ -817,7 +811,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
handle = ax[f](args..., trues(n), false, py_fillstepstyle(st); handle = ax[f](args..., trues(n), false, py_fillstepstyle(st);
zorder = series[:series_plotindex], zorder = series[:series_plotindex],
facecolor = py_color(get_fillcolor(series, i), get_fillalpha(series, i)), facecolor = py_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)),
linewidths = 0 linewidths = 0
) )
push!(handles, handle) push!(handles, handle)
@ -1227,6 +1221,7 @@ const _pyplot_legend_pos = KW(
function py_add_legend(plt::Plot, sp::Subplot, ax) function py_add_legend(plt::Plot, sp::Subplot, ax)
leg = sp[:legend] leg = sp[:legend]
clims = get_clims(sp)
if leg != :none if leg != :none
# gotta do this to ensure both axes are included # gotta do this to ensure both axes are included
labels = [] labels = []
@ -1236,19 +1231,19 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
# add a line/marker and a label # add a line/marker and a label
push!(handles, if series[:seriestype] == :shape || series[:fillrange] != nothing push!(handles, if series[:seriestype] == :shape || series[:fillrange] != nothing
pypatches[:Patch]( pypatches[:Patch](
edgecolor = py_color(get_linecolor(series), get_linealpha(series)), edgecolor = py_color(get_linecolor(series, clims), get_linealpha(series)),
facecolor = py_color(get_fillcolor(series), get_fillalpha(series)), facecolor = py_color(get_fillcolor(series, clims), get_fillalpha(series)),
linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)), linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)),
linestyle = py_linestyle(series[:seriestype], get_linestyle(series)) linestyle = py_linestyle(series[:seriestype], get_linestyle(series))
) )
elseif series[:seriestype] in (:path, :straightline) elseif series[:seriestype] in (:path, :straightline)
PyPlot.plt[:Line2D]((0,1),(0,0), PyPlot.plt[:Line2D]((0,1),(0,0),
color = py_color(get_linecolor(series), get_linealpha(series)), color = py_color(get_linecolor(series, clims), get_linealpha(series)),
linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)), linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)),
linestyle = py_linestyle(:path, get_linestyle(series)), linestyle = py_linestyle(:path, get_linestyle(series)),
marker = py_marker(series[:markershape]), marker = py_marker(series[:markershape]),
markeredgecolor = py_color(get_markerstrokecolor(series), get_markerstrokealpha(series)), markeredgecolor = py_color(get_markerstrokecolor(series), get_markerstrokealpha(series)),
markerfacecolor = series[:marker_z] == nothing ? py_color(get_markercolor(series), get_markeralpha(series)) : py_color(series[:markercolor][0.5]) markerfacecolor = series[:marker_z] == nothing ? py_color(get_markercolor(series, clims), get_markeralpha(series)) : py_color(series[:markercolor][0.5])
) )
else else
series[:serieshandle][1] series[:serieshandle][1]

View File

@ -52,7 +52,7 @@ the `z` argument to turn on series gradients.
[:(begin [:(begin
y = rand(100) y = rand(100)
plot(0:10:100,rand(11,4),lab="lines",w=3,palette=:grays,fill=0, α=0.6) plot(0:10:100,rand(11,4),lab="lines",w=3,palette=:grays,fill=0, α=0.6)
scatter!(y, zcolor=abs.(y.-0.5), m=(:heat,0.8,stroke(1,:green)), ms=10*abs.(y.-0.5).+4, scatter!(y, zcolor=abs.(y.-0.5), m=(:heat,0.8,Plots.stroke(1,:green)), ms=10*abs.(y.-0.5).+4,
lab="grad") lab="grad")
end)] end)]
), ),
@ -66,6 +66,7 @@ the preprocessing step. You can also use shorthand functions: `title!`, `xaxis!`
`yaxis!`, `xlabel!`, `ylabel!`, `xlims!`, `ylims!`, `xticks!`, `yticks!` `yaxis!`, `xlabel!`, `ylabel!`, `xlims!`, `ylims!`, `xticks!`, `yticks!`
""", """,
[:(begin [:(begin
using Statistics
y = rand(20,3) y = rand(20,3)
plot(y, xaxis=("XLABEL",(-5,30),0:2:20,:flip), background_color = RGB(0.2,0.2,0.2), plot(y, xaxis=("XLABEL",(-5,30),0:2:20,:flip), background_color = RGB(0.2,0.2,0.2),
leg=false) leg=false)
@ -85,8 +86,8 @@ yaxis!("YLABEL", :log10)
PlotExample("Images", PlotExample("Images",
"Plot an image. y-axis is set to flipped", "Plot an image. y-axis is set to flipped",
[:(begin [:(begin
import FileIO import FileIO, PlotReferenceImages
img = FileIO.load(Pkg.dir("PlotReferenceImages","Plots","pyplot","0.7.0","ref1.png")) img = FileIO.load(joinpath(dirname(pathof(PlotReferenceImages)), "..", "Plots","pyplot","0.7.0","ref1.png"))
plot(img) plot(img)
end)] end)]
), ),
@ -102,7 +103,7 @@ series.
""", """,
[:(begin [:(begin
ys = Vector[rand(10), rand(20)] ys = Vector[rand(10), rand(20)]
plot(ys, color=[:black :orange], line=(:dot,4), marker=([:hex :d],12,0.8,stroke(3,:gray))) plot(ys, color=[:black :orange], line=(:dot,4), marker=([:hex :d],12,0.8,Plots.stroke(3,:gray)))
end)] end)]
), ),
@ -202,7 +203,8 @@ plot(Plots.fakedata(100,10), layout=4, palette=[:grays :blues :heat :lightrainbo
PlotExample("", PlotExample("",
"", "",
[:(begin [:(begin
Random.srand(111) using Random
Random.seed!(111)
plot!(Plots.fakedata(100,10)) plot!(Plots.fakedata(100,10))
end)] end)]
), ),
@ -295,7 +297,7 @@ PlotExample("3D",
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
plot(x, y, z, zcolor=reverse(z), m=(10,0.8,:blues,stroke(0)), leg=false, cbar=true, w=5) plot(x, y, z, zcolor=reverse(z), m=(10,0.8,:blues,Plots.stroke(0)), leg=false, cbar=true, w=5)
plot!(zeros(n),zeros(n),1:n, w=10) plot!(zeros(n),zeros(n),1:n, w=10)
end)] end)]
), ),
@ -382,8 +384,9 @@ various different nonzero values, a colorbar is added. The colorbar can be disab
`legend = nothing`. `legend = nothing`.
""", """,
[:(begin [:(begin
a = spdiagm((ones(50), ones(49), ones(49), ones(40), ones(40)),(0, 1, -1, 10, -10)) using SparseArrays
b = spdiagm((1:50, 1:49, 1:49, 1:40, 1:40),(0, 1, -1, 10, -10)) a = spdiagm(0 => ones(50), 1 => ones(49), -1 => ones(49), 10 => ones(40), -10 => ones(40))
b = spdiagm(0 => 1:50, 1 => 1:49, -1 => 1:49, 10 => 1:40, -10 => 1:40)
plot(spy(a), spy(b), title = ["Unique nonzeros" "Different nonzeros"]) plot(spy(a), spy(b), title = ["Unique nonzeros" "Different nonzeros"])
end)] end)]
), ),
@ -411,7 +414,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 = permutedims(1:6), layout = 6, label = "", markerstrokewidth = 0,
ticks = -2:2) ticks = -2:2)
end)] end)]
), ),

View File

@ -1,4 +1,21 @@
function __init__() function __init__()
if isdefined(Main, :PLOTS_DEFAULTS)
if haskey(Main.PLOTS_DEFAULTS, :theme)
theme(Main.PLOTS_DEFAULTS[:theme])
end
for (k,v) in Main.PLOTS_DEFAULTS
k == :theme || default(k, v)
end
end
pushdisplay(PlotsDisplay())
atreplinit(i -> begin
if PlotDisplay() in Base.Multimedia.displays
popdisplay(PlotsDisplay())
end
pushdisplay(PlotsDisplay())
end)
include(joinpath(@__DIR__, "backends", "plotly.jl")) include(joinpath(@__DIR__, "backends", "plotly.jl"))
include(joinpath(@__DIR__, "backends", "gr.jl")) include(joinpath(@__DIR__, "backends", "gr.jl"))
include(joinpath(@__DIR__, "backends", "web.jl")) include(joinpath(@__DIR__, "backends", "web.jl"))

View File

@ -145,11 +145,6 @@ function Base.display(::PlotsDisplay, plt::Plot)
_display(plt) _display(plt)
end end
# override the REPL display to open a gui window
using REPL
Base.display(::REPL.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)
function _do_plot_show(plt, showval::Symbol) function _do_plot_show(plt, showval::Symbol)
showval == :gui && gui(plt) showval == :gui && gui(plt)

View File

@ -636,7 +636,7 @@ group_as_matrix(t) = false
x = g.args[1] x = g.args[1]
last_args = g.args[2:end] last_args = g.args[2:end]
end end
x_u = unique(x) x_u = unique(sort(x))
x_ind = Dict(zip(x_u, 1:length(x_u))) x_ind = Dict(zip(x_u, 1:length(x_u)))
for (key,val) in plotattributes for (key,val) in plotattributes
if splittable_kw(key, val, lengthGroup) if splittable_kw(key, val, lengthGroup)

View File

@ -617,20 +617,40 @@ function hascolorbar(sp::Subplot)
hascbar hascbar
end end
function get_linecolor(series, i::Int = 1) for comp in (:line, :fill, :marker)
lc = series[:linecolor]
lz = series[:line_z]
if lz == nothing
isa(lc, ColorGradient) ? lc : plot_color(_cycle(lc, i))
else
cmin, cmax = get_clims(series[:subplot])
grad = isa(lc, ColorGradient) ? lc : cgrad()
grad[clamp((_cycle(lz, i) - cmin) / (cmax - cmin), 0, 1)]
end
end
function get_linealpha(series, i::Int = 1) compcolor = string(comp, :color)
_cycle(series[:linealpha], i) get_compcolor = Symbol(:get_, compcolor)
comp_z = string(comp, :_z)
compalpha = string(comp, :alpha)
get_compalpha = Symbol(:get_, compalpha)
@eval begin
function $get_compcolor(series, cmin::Real, cmax::Real, i::Int = 1)
c = series[$Symbol($compcolor)]
z = series[$Symbol($comp_z)]
if z == nothing
isa(c, ColorGradient) ? c : plot_color(_cycle(c, i))
else
grad = isa(c, ColorGradient) ? c : cgrad()
grad[clamp((_cycle(z, i) - cmin) / (cmax - cmin), 0, 1)]
end
end
$get_compcolor(series, clims, i::Int = 1) = $get_compcolor(series, clims[1], clims[2], i)
function $get_compcolor(series, i::Int = 1)
if series[$Symbol($comp_z)] == nothing
$get_compcolor(series, 0, 1, i)
else
$get_compcolor(series, get_clims(series[:subplot]), i)
end
end
$get_compalpha(series, i::Int = 1) = _cycle(series[$Symbol($compalpha)], i)
end
end end
function get_linewidth(series, i::Int = 1) function get_linewidth(series, i::Int = 1)
@ -641,38 +661,6 @@ function get_linestyle(series, i::Int = 1)
_cycle(series[:linestyle], i) _cycle(series[:linestyle], i)
end end
function get_fillcolor(series, i::Int = 1)
fc = series[:fillcolor]
fz = series[:fill_z]
if fz == nothing
isa(fc, ColorGradient) ? fc : plot_color(_cycle(fc, i))
else
cmin, cmax = get_clims(series[:subplot])
grad = isa(fc, ColorGradient) ? fc : cgrad()
grad[clamp((_cycle(fz, i) - cmin) / (cmax - cmin), 0, 1)]
end
end
function get_fillalpha(series, i::Int = 1)
_cycle(series[:fillalpha], i)
end
function get_markercolor(series, i::Int = 1)
mc = series[:markercolor]
mz = series[:marker_z]
if mz == nothing
isa(mc, ColorGradient) ? mc : plot_color(_cycle(mc, i))
else
cmin, cmax = get_clims(series[:subplot])
grad = isa(mc, ColorGradient) ? mc : cgrad()
grad[clamp((_cycle(mz, i) - cmin) / (cmax - cmin), 0, 1)]
end
end
function get_markeralpha(series, i::Int = 1)
_cycle(series[:markeralpha], i)
end
function get_markerstrokecolor(series, i::Int = 1) function get_markerstrokecolor(series, i::Int = 1)
msc = series[:markerstrokecolor] msc = series[:markerstrokecolor]
isa(msc, ColorGradient) ? msc : _cycle(msc, i) isa(msc, ColorGradient) ? msc : _cycle(msc, i)

View File

@ -2,6 +2,7 @@ StatPlots
Images Images
ImageMagick ImageMagick
@osx QuartzImageIO @osx QuartzImageIO
FileIO
GR 0.31.0 GR 0.31.0
RDatasets RDatasets
VisualRegressionTests VisualRegressionTests

35
test/add_packages.jl Normal file
View File

@ -0,0 +1,35 @@
using Pkg
# need this to use Conda
# ENV["PYTHON"] = ""
to_add = [
PackageSpec(url="https://github.com/JuliaPlots/PlotReferenceImages.jl.git"),
# PackageSpec(url="https://github.com/JuliaStats/KernelDensity.jl.git"),
PackageSpec(name="PlotUtils", rev="master"),
PackageSpec(name="RecipesBase", rev="master"),
# PackageSpec(name="Blink", rev="master"),
# PackageSpec(name="Rsvg", rev="master"),
# PackageSpec(name="PlotlyJS", rev="master"),
# PackageSpec(name="VisualRegressionTests", rev="master"),
# PackageSpec("PyPlot"),
# PackageSpec("InspectDR"),
]
if isinteractive()
append!(to_add, [
PackageSpec(name="FileIO"),
PackageSpec(name="ImageMagick"),
PackageSpec(name="UnicodePlots"),
PackageSpec(name="VisualRegressionTests"),
])
end
Pkg.add(to_add)
Pkg.build("ImageMagick")
# Pkg.build("GR")
# Pkg.build("Blink")
# import Blink
# Blink.AtomShell.install()
# Pkg.build("PyPlot")

View File

@ -2,6 +2,10 @@
using VisualRegressionTests using VisualRegressionTests
# using ExamplePlots # using ExamplePlots
if isinteractive()
@eval Main import Gtk
end
# import DataFrames, RDatasets # import DataFrames, RDatasets
# don't let pyplot use a gui... it'll crash # don't let pyplot use a gui... it'll crash
@ -15,6 +19,8 @@ using VisualRegressionTests
using Plots using Plots
# using StatPlots # using StatPlots
import PlotReferenceImages
using Random
using Test using Test
default(size=(500,300)) default(size=(500,300))
@ -26,7 +32,7 @@ default(size=(500,300))
const _current_plots_version = v"0.17.4" const _current_plots_version = v"0.17.4"
function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = isinteractive(), sigma = [1,1], eps = 1e-2) function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = isinteractive(), sigma = [1,1], tol = 1e-2)
Plots._debugMode.on = debug Plots._debugMode.on = debug
example = Plots._examples[idx] example = Plots._examples[idx]
@info("Testing plot: $pkg:$idx:$(example.header)") @info("Testing plot: $pkg:$idx:$(example.header)")
@ -38,7 +44,7 @@ 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)) refdir = joinpath(dirname(pathof(PlotReferenceImages)), "..", "Plots", string(pkg))
fn = "ref$idx.png" fn = "ref$idx.png"
# firgure out version info # firgure out version info
@ -83,7 +89,7 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = is
# the test # the test
vtest = VisualTest(func, reffn, idx) vtest = VisualTest(func, reffn, idx)
test_images(vtest, popup=popup, sigma=sigma, eps=eps, newfn = newfn) test_images(vtest, popup=popup, sigma=sigma, tol=tol, newfn = newfn)
end end
function image_comparison_facts(pkg::Symbol; function image_comparison_facts(pkg::Symbol;
@ -91,11 +97,11 @@ function image_comparison_facts(pkg::Symbol;
only = nothing, # limit to these examples (int index) only = nothing, # limit to these examples (int index)
debug = false, # print debug information? debug = false, # print debug information?
sigma = [1,1], # number of pixels to "blur" sigma = [1,1], # number of pixels to "blur"
eps = 1e-2) # acceptable error (percent) tol = 1e-2) # acceptable error (percent)
for i in 1:length(Plots._examples) for i in 1:length(Plots._examples)
i in skip && continue i in skip && continue
if only == nothing || i in only if only == nothing || i in only
@test image_comparison_tests(pkg, i, debug=debug, sigma=sigma, eps=eps) |> success == true @test image_comparison_tests(pkg, i, debug=debug, sigma=sigma, tol=tol) |> success == true
end end
end end
end end

View File

@ -1,11 +1,12 @@
module PlotsTests module PlotsTests
include("add_packages.jl")
include("imgcomp.jl") include("imgcomp.jl")
# don't actually show the plots # don't actually show the plots
Random.seed!(1234) Random.seed!(1234)
default(show=false, reuse=true) default(show=false, reuse=true)
img_eps = isinteractive() ? 1e-2 : 10e-2 img_tol = isinteractive() ? 1e-2 : 10e-2
@testset "GR" begin @testset "GR" begin
ENV["PLOTS_TEST"] = "true" ENV["PLOTS_TEST"] = "true"
@ -13,7 +14,7 @@ img_eps = isinteractive() ? 1e-2 : 10e-2
@test gr() == Plots.GRBackend() @test gr() == Plots.GRBackend()
@test backend() == Plots.GRBackend() @test backend() == Plots.GRBackend()
image_comparison_facts(:gr, eps=img_eps, skip = [25, 30]) image_comparison_facts(:gr, tol=img_tol, skip = [25, 30])
end end
@ -21,7 +22,7 @@ end
# @test pyplot() == Plots.PyPlotBackend() # @test pyplot() == Plots.PyPlotBackend()
# @test backend() == Plots.PyPlotBackend() # @test backend() == Plots.PyPlotBackend()
# #
# image_comparison_facts(:pyplot, eps=img_eps) # image_comparison_facts(:pyplot, tol=img_tol)
#end #end
@testset "UnicodePlots" begin @testset "UnicodePlots" begin
@ -46,7 +47,7 @@ end
# 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) # tol=img_tol)
# end # end
# end # end
@ -70,7 +71,7 @@ end
# 28, # heatmap not defined # 28, # heatmap not defined
# 31, # animation # 31, # animation
# ], # ],
# eps=img_eps) # tol=img_tol)
# end # end
@ -79,7 +80,7 @@ end
# @test backend() == Plots.PlotlyBackend() # @test backend() == Plots.PlotlyBackend()
# #
# # # until png generation is reliable on OSX, just test on linux # # # until png generation is reliable on OSX, just test on linux
# # @static Sys.islinux() && image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], eps=img_eps) # # @static Sys.islinux() && image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], tol=img_tol)
# end # end
@ -88,7 +89,7 @@ end
# @test backend() == Plots.ImmerseBackend() # @test backend() == Plots.ImmerseBackend()
# #
# # as long as we can plot anything without error, it should be the same as Gadfly # # as long as we can plot anything without error, it should be the same as Gadfly
# image_comparison_facts(:immerse, only=[1], eps=img_eps) # image_comparison_facts(:immerse, only=[1], tol=img_tol)
# end # end
@ -97,7 +98,7 @@ end
# @test backend() == Plots.PlotlyJSBackend() # @test backend() == Plots.PlotlyJSBackend()
# #
# # as long as we can plot anything without error, it should be the same as Plotly # # as long as we can plot anything without error, it should be the same as Plotly
# image_comparison_facts(:plotlyjs, only=[1], eps=img_eps) # image_comparison_facts(:plotlyjs, only=[1], tol=img_tol)
# end # end
@ -110,7 +111,7 @@ end
# @test plot(sort(rand(10)), rand(Int, 10, 3)) == not(nothing) # @test plot(sort(rand(10)), rand(Int, 10, 3)) == not(nothing)
# @test plot!(rand(10,3), rand(10,3)) == not(nothing) # @test plot!(rand(10,3), rand(10,3)) == not(nothing)
# #
# image_comparison_facts(:gadfly, skip=[4,6,23,24,27], eps=img_eps) # image_comparison_facts(:gadfly, skip=[4,6,23,24,27], tol=img_tol)
# end # end

View File

@ -1,34 +0,0 @@
using Pkg
Pkg.add("ImageMagick")
Pkg.build("ImageMagick")
# Pkg.clone("GR")
# Pkg.build("GR")
Pkg.checkout("https://github.com/JuliaPlots/PlotReferenceImages.jl.git")
# Pkg.clone("https://github.com/JuliaStats/KernelDensity.jl.git")
# Pkg.add("StatPlots")
Pkg.checkout("PlotUtils")
Pkg.checkout("RecipesBase")
# Pkg.clone("Blink")
# Pkg.build("Blink")
# import Blink
# Blink.AtomShell.install()
# Pkg.add("Rsvg")
# Pkg.add("PlotlyJS")
# Pkg.checkout("RecipesBase")
# Pkg.clone("VisualRegressionTests")
# need this to use Conda
# ENV["PYTHON"] = ""
# Pkg.add("PyPlot")
# Pkg.build("PyPlot")
# Pkg.add("InspectDR")
Pkg.test("Plots"; coverage=false)