From e53ab857459fefe45b26f8bfd59f22be02f44fdb Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Thu, 7 Jul 2016 21:46:34 -0400 Subject: [PATCH] color fixes; pyplot shape iteration; KernelDensity in travis and warning; attribute accessors --- src/Plots.jl | 4 +- src/args.jl | 35 +++- src/backends/gr.jl | 140 +++++++------ src/backends/pyplot.jl | 440 ++++++++++++++-------------------------- src/components.jl | 14 +- src/recipes.jl | 8 +- src/series.jl | 6 +- src/utils.jl | 19 +- test/runtests.jl | 4 +- test/travis_commands.jl | 2 + 10 files changed, 279 insertions(+), 393 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index 4ccea9af..838d328e 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -5,12 +5,12 @@ module Plots using Compat using Reexport -@reexport using Colors +# @reexport using Colors # using Requires using FixedSizeArrays @reexport using RecipesBase using Base.Meta -using PlotUtils +@reexport using PlotUtils export AbstractPlot, diff --git a/src/args.jl b/src/args.jl index fa0d939c..c18b2150 100644 --- a/src/args.jl +++ b/src/args.jl @@ -499,7 +499,7 @@ function handleColors!(d::KW, arg, csym::Symbol) d[csym] = :auto else # c = colorscheme(arg) - c = plot_color(arg, nothing) + c = plot_color(arg) d[csym] = c end return true @@ -520,13 +520,13 @@ function processLineArg(d::KW, arg) elseif typeof(arg) <: Stroke arg.width == nothing || (d[:linewidth] = arg.width) - arg.color == nothing || (d[:linecolor] = arg.color == :auto ? :auto : colorscheme(arg.color)) + arg.color == nothing || (d[:linecolor] = arg.color == :auto ? :auto : plot_color(arg.color)) arg.alpha == nothing || (d[:linealpha] = arg.alpha) arg.style == nothing || (d[:linestyle] = arg.style) elseif typeof(arg) <: Brush arg.size == nothing || (d[:fillrange] = arg.size) - arg.color == nothing || (d[:fillcolor] = arg.color == :auto ? :auto : colorscheme(arg.color)) + arg.color == nothing || (d[:fillcolor] = arg.color == :auto ? :auto : plot_color(arg.color)) arg.alpha == nothing || (d[:fillalpha] = arg.alpha) elseif typeof(arg) <: Arrow || arg in (:arrow, :arrows) @@ -559,13 +559,13 @@ function processMarkerArg(d::KW, arg) elseif typeof(arg) <: Stroke arg.width == nothing || (d[:markerstrokewidth] = arg.width) - arg.color == nothing || (d[:markerstrokecolor] = arg.color == :auto ? :auto : colorscheme(arg.color)) + arg.color == nothing || (d[:markerstrokecolor] = arg.color == :auto ? :auto : plot_color(arg.color)) arg.alpha == nothing || (d[:markerstrokealpha] = arg.alpha) arg.style == nothing || (d[:markerstrokestyle] = arg.style) elseif typeof(arg) <: Brush arg.size == nothing || (d[:markersize] = arg.size) - arg.color == nothing || (d[:markercolor] = arg.color == :auto ? :auto : colorscheme(arg.color)) + arg.color == nothing || (d[:markercolor] = arg.color == :auto ? :auto : plot_color(arg.color)) arg.alpha == nothing || (d[:markeralpha] = arg.alpha) # linealpha @@ -587,7 +587,7 @@ end function processFillArg(d::KW, arg) if typeof(arg) <: Brush arg.size == nothing || (d[:fillrange] = arg.size) - arg.color == nothing || (d[:fillcolor] = arg.color == :auto ? :auto : colorscheme(arg.color)) + arg.color == nothing || (d[:fillcolor] = arg.color == :auto ? :auto : plot_color(arg.color)) arg.alpha == nothing || (d[:fillalpha] = arg.alpha) # fillrange function @@ -850,7 +850,7 @@ end # d[k] = if v == :match # match_color # elseif v == nothing -# colorscheme(RGBA(0,0,0,0)) +# plot_color(RGBA(0,0,0,0)) # else # v # end @@ -859,7 +859,9 @@ end function color_or_nothing!(d::KW, k::Symbol) v = d[k] d[k] = if v == nothing || v == false - colorscheme(RGBA(0,0,0,0)) + plot_color(RGBA(0,0,0,0)) + elseif v != :match + plot_color(v) else v end @@ -935,6 +937,17 @@ function Base.getindex(series::Series, k::Symbol) series.d[k] end +Base.setindex!(plt::Plot, v, k::Symbol) = (plt.attr[k] = v) +Base.setindex!(sp::Subplot, v, k::Symbol) = (sp.attr[k] = v) +Base.setindex!(axis::Axis, v, k::Symbol) = (axis.d[k] = v) +Base.setindex!(series::Series, v, k::Symbol) = (series.d[k] = v) + +Base.get(plt::Plot, k::Symbol, v) = get(plt.attr, k, v) +Base.get(sp::Subplot, k::Symbol, v) = get(sp.attr, k, v) +Base.get(axis::Axis, k::Symbol, v) = get(axis.d, k, v) +Base.get(series::Series, k::Symbol, v) = get(series.d, k, v) + + # ----------------------------------------------------------------------------- # update attr from an input dictionary @@ -1048,7 +1061,7 @@ end # ----------------------------------------------------------------------------- function has_black_border_for_default(st::Symbol) - like_histogram(st) || st in (:hexbin, :bar) + like_histogram(st) || st in (:hexbin, :bar, :shape) end @@ -1100,7 +1113,7 @@ function _add_defaults!(d::KW, plt::Plot, sp::Subplot, commandIndex::Int) for s in (:line, :marker, :fill) csym, asym = Symbol(s,:color), Symbol(s,:alpha) d[csym] = if d[csym] == :match - if has_black_border_for_default(d[:seriestype]) && csym == :line + if has_black_border_for_default(d[:seriestype]) && s == :line plot_color(:black, d[asym]) else d[:seriescolor] @@ -1112,7 +1125,7 @@ function _add_defaults!(d::KW, plt::Plot, sp::Subplot, commandIndex::Int) # update markerstrokecolor d[:markerstrokecolor] = if d[:markerstrokecolor] == :match - sp[:foreground_color_subplot] + plot_color(sp[:foreground_color_subplot], d[:markerstrokealpha]) else getSeriesRGBColor(d[:markerstrokecolor], d[:markerstrokealpha], sp, plotIndex) end diff --git a/src/backends/gr.jl b/src/backends/gr.jl index e69df3d2..3546a1f1 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -112,10 +112,10 @@ function gr_getcolorind(c) convert(Int, GR.inqcolorfromrgb(red(c), green(c), blue(c))) end -gr_set_linecolor(c) = GR.setlinecolorind(gr_getcolorind(c)) -gr_set_fillcolor(c) = GR.setfillcolorind(gr_getcolorind(c)) -gr_set_markercolor(c) = GR.setmarkercolorind(gr_getcolorind(c)) -gr_set_textcolor(c) = GR.settextcolorind(gr_getcolorind(c)) +gr_set_linecolor(c) = GR.setlinecolorind(gr_getcolorind(cycle(c,1))) +gr_set_fillcolor(c) = GR.setfillcolorind(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))) # -------------------------------------------------------------------------------------- @@ -271,8 +271,8 @@ end # draw the markers, one at a time -function gr_draw_markers(d::KW, x, y, msize, mz) - shape = d[:markershape] +function gr_draw_markers(series::Series, x, y, msize, mz) + shape = series[:markershape] if shape != :none for i=1:length(x) msi = cycle(msize, i) @@ -280,18 +280,19 @@ function gr_draw_markers(d::KW, x, y, msize, mz) cfuncind = isa(shape, Shape) ? GR.setfillcolorind : GR.setmarkercolorind # draw a filled in shape, slightly bigger, to estimate a stroke - if d[:markerstrokewidth] > 0 - cfunc(cycle(d[:markerstrokecolor], i)) #, d[:markerstrokealpha]) - gr_draw_marker(x[i], y[i], msi + d[:markerstrokewidth], shape) + if series[:markerstrokewidth] > 0 + cfunc(cycle(series[:markerstrokecolor], i)) #, series[:markerstrokealpha]) + gr_draw_marker(x[i], y[i], msi + series[:markerstrokewidth], shape) end # draw the shape if mz == nothing - cfunc(cycle(d[:markercolor], i)) #, d[:markeralpha]) + cfunc(cycle(series[:markercolor], i)) #, series[:markeralpha]) else # pick a color from the pre-loaded gradient ci = round(Int, 1000 + cycle(mz, i) * 255) cfuncind(ci) + GR.settransparency(_gr_gradient_alpha[ci-999]) end gr_draw_marker(x[i], y[i], msi, shape) end @@ -300,12 +301,11 @@ end function gr_draw_markers(series::Series, x, y) isempty(x) && return - d = series.d - mz = normalize_zvals(d[:marker_z]) + mz = normalize_zvals(series[:marker_z]) GR.setfillintstyle(GR.INTSTYLE_SOLID) - gr_draw_markers(d, x, y, d[:markersize], mz) + gr_draw_markers(series, x, y, series[:markersize], mz) if mz != nothing - gr_colorbar(d[:subplot]) + gr_colorbar(series[:subplot]) end end @@ -403,13 +403,14 @@ gr_view_ydiff() = viewport_plotarea[4] - viewport_plotarea[3] # -------------------------------------------------------------------------------------- +const _gr_gradient_alpha = ones(256) -function gr_set_gradient(c) #, a) +function gr_set_gradient(c) grad = isa(c, ColorGradient) ? c : cgrad() - # grad = ColorGradient(grad, alpha=a) for (i,z) in enumerate(linspace(0, 1, 256)) c = grad[z] - GR.setcolorrep(999+i, red(c), green(c), blue(c), alpha(c)) + GR.setcolorrep(999+i, red(c), green(c), blue(c)) + _gr_gradient_alpha[i] = alpha(c) end grad end @@ -474,8 +475,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) draw_axes = true # axes_2d = true for series in series_list(sp) - st = series.d[:seriestype] - if st in (:contour, :surface, :heatmap) || series.d[:marker_z] != nothing + st = series[:seriestype] + if st in (:contour, :surface, :heatmap) || series[:marker_z] != nothing cmap = true end if st == :pie @@ -613,14 +614,13 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.setcolormap(1000 + GR.COLORMAP_COOLWARM) for (idx, series) in enumerate(series_list(sp)) - d = series.d - st = d[:seriestype] + st = series[:seriestype] # update the current stored gradient if st in (:contour, :surface, :wireframe, :heatmap) - gr_set_gradient(d[:fillcolor]) #, d[:fillalpha]) - elseif d[:marker_z] != nothing - d[:markercolor] = gr_set_gradient(d[:markercolor], d[:markeralpha]) + gr_set_gradient(series[:fillcolor]) #, series[:fillalpha]) + elseif series[:marker_z] != nothing + series[:markercolor] = gr_set_gradient(series[:markercolor]) end GR.savestate() @@ -635,12 +635,12 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end end - x, y, z = d[:x], d[:y], d[:z] - frng = d[:fillrange] + x, y, z = series[:x], series[:y], series[:z] + frng = series[:fillrange] # recompute data if st in (:contour, :surface, :wireframe) - z = vec(transpose_z(d, z.surf, false)) + z = vec(transpose_z(series, z.surf, false)) elseif ispolar(sp) if frng != nothing _, frng = convert_to_polar(x, frng, (rmin, rmax)) @@ -653,7 +653,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # do area fill if frng != nothing - gr_set_fillcolor(d[:fillcolor]) #, d[:fillalpha]) + gr_set_fillcolor(series[:fillcolor]) #, series[:fillalpha]) GR.setfillintstyle(GR.INTSTYLE_SOLID) frng = isa(frng, Number) ? Float64[frng] : frng nx, ny, nf = length(x), length(y), length(frng) @@ -669,24 +669,24 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # draw the line(s) if st == :path - gr_set_line(d[:linewidth], d[:linestyle], d[:linecolor]) #, d[:linealpha]) + gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha]) gr_polyline(x, y) end end - if d[:markershape] != :none + if series[:markershape] != :none gr_draw_markers(series, x, y) end elseif st == :contour zmin, zmax = gr_lims(zaxis, false) - if typeof(d[:levels]) <: Array - h = d[:levels] + if typeof(series[:levels]) <: Array + h = series[:levels] else - h = linspace(zmin, zmax, d[:levels]) + h = linspace(zmin, zmax, series[:levels]) end GR.setspace(zmin, zmax, 0, 90) - if d[:fillrange] != nothing + if series[:fillrange] != nothing GR.surface(x, y, z, GR.OPTION_CELL_ARRAY) else GR.contour(x, y, h, z, 1000) @@ -713,7 +713,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) cmap && gr_colorbar(sp) elseif st == :heatmap - z = vec(transpose_z(d, z.surf, false)) + z = vec(transpose_z(series, z.surf, false)) zmin, zmax = gr_lims(zaxis, true) GR.setspace(zmin, zmax, 0, 90) GR.surface(x, y, z, GR.OPTION_COLORED_MESH) @@ -723,13 +723,13 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # draw path if st == :path3d if length(x) > 1 - gr_set_line(d[:linewidth], d[:linestyle], d[:linecolor]) #, d[:linealpha]) + gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha]) GR.polyline3d(x, y, z) end end # draw markers - if st == :scatter3d || d[:markershape] != :none + if st == :scatter3d || series[:markershape] != :none x2, y2 = unzip(map(GR.wc3towc, x, y, z)) gr_draw_markers(series, x2, y2) end @@ -750,7 +750,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) ymin, ymax = ycenter - r, ycenter + r end labels = pie_labels(sp, series) - slices = d[:y] + slices = series[:y] numslices = length(slices) total = sum(slices) a1 = 0 @@ -783,17 +783,27 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.selntran(1) elseif st == :shape - # draw the interior - gr_set_fill(d[:fillcolor]) #, d[:fillalpha]) - gr_polyline(d[:x], d[:y], GR.fillarea) + for (i,rng) in enumerate(iter_segments(series[:x], series[:y])) + if length(rng) > 1 + # connect to the beginning + rng = vcat(rng, rng[1]) - # draw the shapes - gr_set_line(d[:linewidth], :solid, d[:linecolor]) #, d[:linealpha]) - gr_polyline(d[:x], d[:y]) + # get the segments + x, y = series[:x][rng], series[:y][rng] + + # draw the interior + gr_set_fill(cycle(series[:fillcolor], i)) + GR.fillarea(x, y) + + # draw the shapes + gr_set_line(series[:linewidth], :solid, cycle(series[:linecolor], i)) + GR.polyline(x, y) + end + end elseif st == :image - img = d[:z].surf + img = series[:z].surf w, h = size(img) if eltype(img) <: Colors.AbstractGray grey = round(UInt8, float(img) * 255) @@ -823,11 +833,11 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) for series in series_list(sp) should_add_to_legend(series) || continue n += 1 - if typeof(series.d[:label]) <: Array + if typeof(series[:label]) <: Array i += 1 - lab = series.d[:label][i] + lab = series[:label][i] else - lab = series.d[:label] + lab = series[:label] end tbx, tby = gr_inqtext(0, 0, lab) w = max(w, tbx[3] - tbx[1]) @@ -845,13 +855,12 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) i = 0 for series in series_list(sp) should_add_to_legend(series) || continue - d = series.d - st = d[:seriestype] - gr_set_line(d[:linewidth], d[:linestyle], d[:linecolor]) #, d[:linealpha]) + st = series[:seriestype] + gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha]) if st == :path GR.polyline([xpos - 0.07, xpos - 0.01], [ypos, ypos]) elseif st == :shape - gr_set_fill(d[:fillcolor]) #, d[:fillalpha]) + gr_set_fill(series[:fillcolor]) #, series[:fillalpha]) l, r = xpos-0.07, xpos-0.01 b, t = ypos-0.4dy, ypos+0.4dy x = [l, r, r, l, l] @@ -860,28 +869,15 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) gr_polyline(x, y) end - gr_draw_markers(d, xpos-[0.06,0.02], [ypos,ypos], 10, nothing) - # shape = d[:markershape] - # if shape != :none #st == :scatter || d[:markershape] != :none - # msize = 10 - # for xoff in [0.06,0.02] - # gr_set_markercolor(d[:markerstrokecolor]) #, d[:markerstrokealpha]) - # gr_draw_marker(xpos-xoff, ypos, msize*1.1, shape) - # gr_set_markercolor(d[:markercolor], d[:markeralpha]) - # gr_draw_marker(xpos-xoff, ypos, msize, shape) - # end - # # gr_setmarkershape(d) - # # if st == :path - # # gr_polymarker(d, [xpos - 0.06, xpos - 0.02], [ypos, ypos]) - # # else - # # gr_polymarker(d, [xpos - 0.06, xpos - 0.04, xpos - 0.02], [ypos, ypos, ypos]) - # # end - # end - if typeof(d[:label]) <: Array + if series[:markershape] != :none + gr_draw_markers(series, xpos-[0.06,0.02], [ypos,ypos], 10, nothing) + end + + if typeof(series[:label]) <: Array i += 1 - lab = d[:label][i] + lab = series[:label][i] else - lab = d[:label] + lab = series[:label] end GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF) gr_set_textcolor(sp[:foreground_color_legend]) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 42ca4229..1f248ab1 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -104,7 +104,7 @@ py_color(cs::AVec) = map(py_color, cs) py_color(grad::ColorGradient) = py_color(grad.colors) function py_colormap(grad::ColorGradient) - pyvals = [(z, py_color(c[z])) for z in c.values] + pyvals = [(z, py_color(grad[z])) for z in grad.values] pycolors.LinearSegmentedColormap[:from_list]("tmp", pyvals) end py_colormap(c) = py_colormap(cgrad()) @@ -143,27 +143,27 @@ const _path_MOVETO = UInt8(1) const _path_LINETO = UInt8(2) const _path_CLOSEPOLY = UInt8(79) -# see http://matplotlib.org/users/path_tutorial.html -# and http://matplotlib.org/api/path_api.html#matplotlib.path.Path -function py_path(x, y) - n = length(x) - mat = zeros(n+1, 2) - codes = zeros(UInt8, n+1) - lastnan = true - for i=1:n - mat[i,1] = x[i] - mat[i,2] = y[i] - nan = !ok(x[i], y[i]) - codes[i] = if nan && i>1 - _path_CLOSEPOLY - else - lastnan ? _path_MOVETO : _path_LINETO - end - lastnan = nan - end - codes[n+1] = _path_CLOSEPOLY - pypath.pymember("Path")(mat, codes) -end +# # see http://matplotlib.org/users/path_tutorial.html +# # and http://matplotlib.org/api/path_api.html#matplotlib.path.Path +# function py_path(x, y) +# n = length(x) +# mat = zeros(n+1, 2) +# codes = zeros(UInt8, n+1) +# lastnan = true +# for i=1:n +# mat[i,1] = x[i] +# mat[i,2] = y[i] +# nan = !ok(x[i], y[i]) +# codes[i] = if nan && i>1 +# _path_CLOSEPOLY +# else +# lastnan ? _path_MOVETO : _path_LINETO +# end +# lastnan = nan +# end +# codes[n+1] = _path_CLOSEPOLY +# pypath.pymember("Path")(mat, codes) +# end # get the marker shape function py_marker(marker::Symbol) @@ -220,29 +220,17 @@ function add_pyfixedformatter(cbar, vals::AVec) cbar[:update_ticks]() end -# # TODO: smoothing should be moved into the SliceIt method, should not touch backends -# function handleSmooth(plt::Plot{PyPlotBackend}, ax, d::KW, smooth::Bool) -# if smooth -# xs, ys = regressionXY(d[:x], d[:y]) -# ax[:plot](xs, ys, -# # linestyle = py_linestyle(:path, :dashdot), -# color = py_color(d[:linecolor]), -# linewidth = 2 -# ) -# end -# end -# handleSmooth(plt::Plot{PyPlotBackend}, ax, d::KW, smooth::Real) = handleSmooth(plt, ax, d, true) # --------------------------------------------------------------------------- -function fix_xy_lengths!(plt::Plot{PyPlotBackend}, d::KW) - x, y = d[:x], d[:y] +function fix_xy_lengths!(plt::Plot{PyPlotBackend}, series::Series) + x, y = series[:x], series[:y] nx, ny = length(x), length(y) - if !isa(get(d, :z, nothing), Surface) && nx != ny + if !isa(get(series.d, :z, nothing), Surface) && nx != ny if nx < ny - d[:x] = Float64[x[mod1(i,nx)] for i=1:ny] + series[:x] = Float64[x[mod1(i,nx)] for i=1:ny] else - d[:y] = Float64[y[mod1(i,ny)] for i=1:nx] + series[:y] = Float64[y[mod1(i,ny)] for i=1:nx] end end end @@ -258,14 +246,14 @@ function py_color_fix(c, x) end end -py_linecolor(d::KW) = py_color(d[:linecolor]) #, d[:linealpha]) -py_markercolor(d::KW) = py_color(d[:markercolor]) #, d[:markeralpha]) -py_markerstrokecolor(d::KW) = py_color(d[:markerstrokecolor]) #, d[:markerstrokealpha]) -py_fillcolor(d::KW) = py_color(d[:fillcolor]) #, d[:fillalpha]) +py_linecolor(series::Series) = py_color(series[:linecolor]) +py_markercolor(series::Series) = py_color(series[:markercolor]) +py_markerstrokecolor(series::Series) = py_color(series[:markerstrokecolor]) +py_fillcolor(series::Series) = py_color(series[:fillcolor]) -py_linecolormap(d::KW) = py_colormap(d[:linecolor]) #, d[:linealpha]) -py_markercolormap(d::KW) = py_colormap(d[:markercolor]) #, d[:markeralpha]) -py_fillcolormap(d::KW) = py_colormap(d[:fillcolor]) #, d[:fillalpha]) +py_linecolormap(series::Series) = py_colormap(series[:linecolor]) +py_markercolormap(series::Series) = py_colormap(series[:markercolor]) +py_fillcolormap(series::Series) = py_colormap(series[:fillcolor]) # --------------------------------------------------------------------------- @@ -392,9 +380,9 @@ end # function _series_added(plt::Plot{PyPlotBackend}, series::Series) function py_add_series(plt::Plot{PyPlotBackend}, series::Series) - d = series.d - st = d[:seriestype] - sp = d[:subplot] + # d = series.d + st = series[:seriestype] + sp = series[:subplot] ax = sp.o if !(st in supported_types(plt.backend)) @@ -402,10 +390,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end # PyPlot doesn't handle mismatched x/y - fix_xy_lengths!(plt, d) + fix_xy_lengths!(plt, series) # ax = getAxis(plt, series) - x, y, z = d[:x], d[:y], d[:z] + x, y, z = series[:x], series[:y], series[:z] xyargs = (st in _3dTypes ? (x,y,z) : (x,y)) # handle zcolor and get c/cmap @@ -418,7 +406,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # pass in an integer value as an arg, but a levels list as a keyword arg - levels = d[:levels] + levels = series[:levels] levelargs = if isscalar(levels) (levels) elseif isvector(levels) @@ -432,14 +420,14 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # line plot if st in (:path, :path3d, :steppre, :steppost) - if d[:linewidth] > 0 - if d[:line_z] == nothing + if series[:linewidth] > 0 + if series[:line_z] == nothing handle = ax[:plot](xyargs...; - label = d[:label], - zorder = d[:series_plotindex], - color = py_linecolor(d), - linewidth = py_dpi_scale(plt, d[:linewidth]), - linestyle = py_linestyle(st, d[:linestyle]), + label = series[:label], + zorder = series[:series_plotindex], + color = py_linecolor(series), + linewidth = py_dpi_scale(plt, series[:linewidth]), + linestyle = py_linestyle(st, series[:linestyle]), solid_capstyle = "round", drawstyle = py_stepstyle(st) )[1] @@ -450,18 +438,18 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) n = length(x) - 1 segments = Array(Any,n) kw = KW( - :label => d[:label], + :label => series[:label], :zorder => plt.n, - :cmap => py_linecolormap(d), - :linewidth => py_dpi_scale(plt, d[:linewidth]), - :linestyle => py_linestyle(st, d[:linestyle]) + :cmap => py_linecolormap(series), + :linewidth => py_dpi_scale(plt, series[:linewidth]), + :linestyle => py_linestyle(st, series[:linestyle]) ) handle = if is3d(st) for i=1:n segments[i] = [(cycle(x,i), cycle(y,i), cycle(z,i)), (cycle(x,i+1), cycle(y,i+1), cycle(z,i+1))] end lc = pyart3d.Line3DCollection(segments; kw...) - lc[:set_array](d[:line_z]) + lc[:set_array](series[:line_z]) ax[:add_collection3d](lc, zs=z) #, zdir='y') lc else @@ -469,7 +457,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) segments[i] = [(cycle(x,i), cycle(y,i)), (cycle(x,i+1), cycle(y,i+1))] end lc = pycollections.LineCollection(segments; kw...) - lc[:set_array](d[:line_z]) + lc[:set_array](series[:line_z]) ax[:add_collection](lc) lc end @@ -477,7 +465,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) needs_colorbar = true end - a = d[:arrow] + a = series[:arrow] if a != nothing && !is3d(st) # TODO: handle 3d later if typeof(a) != Arrow warn("Unexpected type for arrow: $(typeof(a))") @@ -486,10 +474,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) :arrowstyle => "simple,head_length=$(a.headlength),head_width=$(a.headwidth)", :shrinkA => 0, :shrinkB => 0, - :edgecolor => py_linecolor(d), - :facecolor => py_linecolor(d), - :linewidth => py_dpi_scale(plt, d[:linewidth]), - :linestyle => py_linestyle(st, d[:linestyle]), + :edgecolor => py_linecolor(series), + :facecolor => py_linecolor(series), + :linewidth => py_dpi_scale(plt, series[:linewidth]), + :linestyle => py_linestyle(st, series[:linestyle]), ) add_arrows(x, y) do xyprev, xy ax[:annotate]("", @@ -504,53 +492,16 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end end - # if st == :bar - # bw = d[:bar_width] - # if bw == nothing - # bw = mean(diff(isvertical(d) ? x : y)) - # end - # extrakw[isvertical(d) ? :width : :height] = bw - # fr = get(d, :fillrange, nothing) - # if fr != nothing - # extrakw[:bottom] = fr - # d[:fillrange] = nothing - # end - # handle = ax[isvertical(d) ? :bar : :barh](x, y; - # label = d[:label], - # zorder = d[:series_plotindex], - # color = py_fillcolor(d), - # edgecolor = py_linecolor(d), - # linewidth = d[:linewidth], - # align = d[:bar_edges] ? "edge" : "center", - # extrakw... - # )[1] - # push!(handles, handle) - # end - - # if st == :sticks - # extrakw[isvertical(d) ? :width : :height] = 0.0 - # handle = ax[isvertical(d) ? :bar : :barh](x, y; - # label = d[:label], - # zorder = d[:series_plotindex], - # color = py_linecolor(d), - # edgecolor = py_linecolor(d), - # linewidth = d[:linewidth], - # align = "center", - # extrakw... - # )[1] - # push!(handles, handle) - # end - # add markers? - if d[:markershape] != :none && st in (:path, :scatter, :path3d, + if series[:markershape] != :none && st in (:path, :scatter, :path3d, :scatter3d, :steppre, :steppost, :bar) extrakw = KW() - if d[:marker_z] == nothing - extrakw[:c] = py_color_fix(py_markercolor(d), x) + if series[:marker_z] == nothing + extrakw[:c] = py_color_fix(py_markercolor(series), x) else - extrakw[:c] = convert(Vector{Float64}, d[:marker_z]) - extrakw[:cmap] = py_markercolormap(d) + extrakw[:c] = convert(Vector{Float64}, series[:marker_z]) + extrakw[:cmap] = py_markercolormap(series) clims = sp[:clims] if is_2tuple(clims) isfinite(clims[1]) && (extrakw[:vmin] = clims[1]) @@ -558,72 +509,23 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end needs_colorbar = true end - xyargs = if st == :bar && !isvertical(d) + xyargs = if st == :bar && !isvertical(series) (y, x) else xyargs end handle = ax[:scatter](xyargs...; - label = d[:label], - zorder = d[:series_plotindex] + 0.5, - marker = py_marker(d[:markershape]), - s = py_dpi_scale(plt, d[:markersize] .^ 2), - edgecolors = py_markerstrokecolor(d), - linewidths = py_dpi_scale(plt, d[:markerstrokewidth]), + label = series[:label], + zorder = series[:series_plotindex] + 0.5, + marker = py_marker(series[:markershape]), + s = py_dpi_scale(plt, series[:markersize] .^ 2), + edgecolors = py_markerstrokecolor(series), + linewidths = py_dpi_scale(plt, series[:markerstrokewidth]), extrakw... ) push!(handles, handle) end - # if st == :histogram - # handle = ax[:hist](y; - # label = d[:label], - # zorder = d[:series_plotindex], - # color = py_fillcolor(d), - # edgecolor = py_linecolor(d), - # linewidth = d[:linewidth], - # bins = d[:bins], - # normed = d[:normalize], - # weights = d[:weights], - # orientation = (isvertical(d) ? "vertical" : "horizontal"), - # histtype = (d[:bar_position] == :stack ? "barstacked" : "bar") - # )[3] - # push!(handles, handle) - - # # expand the extrema... handle is a list of Rectangle objects - # for rect in handle - # xmin, ymin, xmax, ymax = rect[:get_bbox]()[:extents] - # expand_extrema!(sp, xmin, xmax, ymin, ymax) - # # expand_extrema!(sp[:xaxis], (xmin, xmax)) - # # expand_extrema!(sp[:yaxis], (ymin, ymax)) - # end - # end - - # if st == :histogram2d - # clims = sp[:clims] - # if is_2tuple(clims) - # isfinite(clims[1]) && (extrakw[:vmin] = clims[1]) - # isfinite(clims[2]) && (extrakw[:vmax] = clims[2]) - # end - # handle = ax[:hist2d](x, y; - # label = d[:label], - # zorder = d[:series_plotindex], - # bins = d[:bins], - # normed = d[:normalize], - # weights = d[:weights], - # cmap = py_fillcolormap(d), # applies to the pcolorfast object - # extrakw... - # )[4] - # push!(handles, handle) - # needs_colorbar = true - - # # expand the extrema... handle is a AxesImage object - # expand_extrema!(sp, handle[:get_extent]()...) - # # xmin, xmax, ymin, ymax = handle[:get_extent]() - # # expand_extrema!(sp[:xaxis], (xmin, xmax)) - # # expand_extrema!(sp[:yaxis], (ymin, ymax)) - # end - if st == :hexbin clims = sp[:clims] if is_2tuple(clims) @@ -631,33 +533,20 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) isfinite(clims[2]) && (extrakw[:vmax] = clims[2]) end handle = ax[:hexbin](x, y; - label = d[:label], - zorder = d[:series_plotindex], - gridsize = d[:bins], - linewidths = py_dpi_scale(plt, d[:linewidth]), - edgecolors = py_linecolor(d), - cmap = py_fillcolormap(d), # applies to the pcolorfast object + label = series[:label], + zorder = series[:series_plotindex], + gridsize = series[:bins], + linewidths = py_dpi_scale(plt, series[:linewidth]), + edgecolors = py_linecolor(series), + cmap = py_fillcolormap(series), # applies to the pcolorfast object extrakw... ) push!(handles, handle) needs_colorbar = true end - # if st in (:hline,:vline) - # for yi in d[:y] - # func = ax[st == :hline ? :axhline : :axvline] - # handle = func(yi; - # linewidth=d[:linewidth], - # color=py_linecolor(d), - # linestyle=py_linestyle(st, d[:linestyle]) - # ) - # push!(handles, handle) - # end - # end - if st in (:contour, :contour3d) - # z = z.surf' - z = transpose_z(d, z.surf) + z = transpose_z(series, z.surf) needs_colorbar = true clims = sp[:clims] @@ -672,21 +561,21 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # contour lines handle = ax[:contour](x, y, z, levelargs...; - label = d[:label], - zorder = d[:series_plotindex], - linewidths = py_dpi_scale(plt, d[:linewidth]), - linestyles = py_linestyle(st, d[:linestyle]), - cmap = py_linecolormap(d), + label = series[:label], + zorder = series[:series_plotindex], + linewidths = py_dpi_scale(plt, series[:linewidth]), + linestyles = py_linestyle(st, series[:linestyle]), + cmap = py_linecolormap(series), extrakw... ) push!(handles, handle) # contour fills - if d[:fillrange] != nothing + if series[:fillrange] != nothing handle = ax[:contourf](x, y, z, levelargs...; - label = d[:label], - zorder = d[:series_plotindex] + 0.5, - cmap = py_fillcolormap(d), + label = series[:label], + zorder = series[:series_plotindex] + 0.5, + cmap = py_fillcolormap(series), extrakw... ) push!(handles, handle) @@ -698,13 +587,13 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) x, y, z = map(Array, (x,y,z)) if !ismatrix(x) || !ismatrix(y) x = repmat(x', length(y), 1) - y = repmat(y, 1, length(d[:x])) + y = repmat(y, 1, length(series[:x])) end # z = z' - z = transpose_z(d, z) + z = transpose_z(series, z) if st == :surface - if d[:marker_z] != nothing - extrakw[:facecolors] = py_shading(d[:fillcolor], d[:marker_z], d[:fillalpha]) + if series[:marker_z] != nothing + extrakw[:facecolors] = py_shading(series[:fillcolor], series[:marker_z], series[:fillalpha]) extrakw[:shade] = false clims = sp[:clims] if is_2tuple(clims) @@ -712,28 +601,28 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) isfinite(clims[2]) && (extrakw[:vmax] = clims[2]) end else - extrakw[:cmap] = py_fillcolormap(d) + extrakw[:cmap] = py_fillcolormap(series) needs_colorbar = true end end handle = ax[st == :surface ? :plot_surface : :plot_wireframe](x, y, z; - label = d[:label], - zorder = d[:series_plotindex], + label = series[:label], + zorder = series[:series_plotindex], rstride = 1, cstride = 1, - linewidth = py_dpi_scale(plt, d[:linewidth]), - edgecolor = py_linecolor(d), + linewidth = py_dpi_scale(plt, series[:linewidth]), + edgecolor = py_linecolor(series), extrakw... ) push!(handles, handle) # contours on the axis planes - if d[:contours] + if series[:contours] for (zdir,mat) in (("x",x), ("y",y), ("z",z)) offset = (zdir == "y" ? maximum : minimum)(mat) handle = ax[:contourf](x, y, z, levelargs...; zdir = zdir, - cmap = py_fillcolormap(d), + cmap = py_fillcolormap(series), offset = (zdir == "y" ? maximum : minimum)(mat) # where to draw the contour plane ) push!(handles, handle) @@ -754,11 +643,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) isfinite(clims[2]) && (extrakw[:vmax] = clims[2]) end handle = ax[:plot_trisurf](x, y, z; - label = d[:label], - zorder = d[:series_plotindex], - cmap = py_fillcolormap(d), - linewidth = py_dpi_scale(plt, d[:linewidth]), - edgecolor = py_linecolor(d), + label = series[:label], + zorder = series[:series_plotindex], + cmap = py_fillcolormap(series), + linewidth = py_dpi_scale(plt, series[:linewidth]), + edgecolor = py_linecolor(series), extrakw... ) push!(handles, handle) @@ -770,7 +659,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) if st == :image # @show typeof(z) - img = Array(transpose_z(d, z.surf)) + img = Array(transpose_z(series, z.surf)) z = if eltype(img) <: Colors.AbstractGray float(img) elseif eltype(img) <: Colorant @@ -779,7 +668,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) z # hopefully it's in a data format that will "just work" with imshow end handle = ax[:imshow](z; - zorder = d[:series_plotindex], + zorder = series[:series_plotindex], cmap = py_colormap([:black, :white]), vmin = 0.0, vmax = 1.0 @@ -789,11 +678,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # expand extrema... handle is AxesImage object xmin, xmax, ymax, ymin = handle[:get_extent]() expand_extrema!(sp, xmin, xmax, ymin, ymax) - # sp[:yaxis].d[:flip] = true + # sp[:yaxis].series[:flip] = true end if st == :heatmap - x, y, z = heatmap_edges(x), heatmap_edges(y), transpose_z(d, z.surf) + x, y, z = heatmap_edges(x), heatmap_edges(y), transpose_z(series, z.surf) # if !(eltype(z) <: Number) # z, discrete_colorbar_values = indices_and_unique_values(z) # end @@ -809,10 +698,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end handle = ax[:pcolormesh](x, y, z; - label = d[:label], - zorder = d[:series_plotindex], - cmap = py_fillcolormap(d), - edgecolors = (d[:linewidth] > 0 ? py_linecolor(d) : "face"), + label = series[:label], + zorder = series[:series_plotindex], + cmap = py_fillcolormap(series), + edgecolors = (series[:linewidth] > 0 ? py_linecolor(series) : "face"), extrakw... ) push!(handles, handle) @@ -830,16 +719,32 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end if st == :shape - path = py_path(x, y) - patches = pypatches.pymember("PathPatch")(path; - label = d[:label], - zorder = d[:series_plotindex], - edgecolor = py_linecolor(d), - facecolor = py_fillcolor(d), - linewidth = py_dpi_scale(plt, d[:linewidth]), - fill = true - ) - handle = ax[:add_patch](patches) + handle = [] + for (i,rng) in enumerate(iter_segments(x, y)) + if length(rng) > 1 + path = pypath.pymember("Path")(hcat(x[rng], y[rng])) + patches = pypatches.pymember("PathPatch")( + path; + label = series[:label], + zorder = series[:series_plotindex], + edgecolor = py_color(cycle(series[:linecolor], i)), + facecolor = py_color(cycle(series[:fillcolor], i)), + linewidth = py_dpi_scale(plt, series[:linewidth]), + fill = true + ) + push!(handle, ax[:add_patch](patches)) + end + end + # path = py_path(x, y) + # patches = pypatches.pymember("PathPatch")(path; + # label = series[:label], + # zorder = series[:series_plotindex], + # edgecolor = py_linecolor(series), + # facecolor = py_fillcolor(series), + # linewidth = py_dpi_scale(plt, series[:linewidth]), + # fill = true + # ) + # handle = ax[:add_patch](patches) push!(handles, handle) end @@ -858,10 +763,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) expand_extrema!(sp, -lim, lim, -lim, lim) end - d[:serieshandle] = handles + series[:serieshandle] = handles # # smoothing - # handleSmooth(plt, ax, d, d[:smooth]) + # handleSmooth(plt, ax, series, series[:smooth]) # add the colorbar legend if needs_colorbar && sp[:colorbar] != :none @@ -886,55 +791,29 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end # handle area filling - fillrange = d[:fillrange] + fillrange = series[:fillrange] if fillrange != nothing && st != :contour - f, dim1, dim2 = if isvertical(d) + f, dim1, dim2 = if isvertical(series) :fill_between, x, y else :fill_betweenx, y, x end + n = length(dim1) args = if typeof(fillrange) <: Union{Real, AVec} - dim1, fillrange, dim2 - else - dim1, fillrange... + dim1, expand_data(fillrange, n), dim2 + elseif is_2tuple(fillrange) + dim1, expand_data(fillrange[1], n), expand_data(fillrange[2], n) end handle = ax[f](args...; - zorder = d[:series_plotindex], - facecolor = py_fillcolor(d), + zorder = series[:series_plotindex], + facecolor = py_fillcolor(series), linewidths = 0 ) push!(handles, handle) end end - -# -------------------------------------------------------------------------- - -# function update_limits!(sp::Subplot{PyPlotBackend}, series::Series, letters) -# for letter in letters -# py_set_lims(sp.o, sp[Symbol(letter, :axis)]) -# end -# end - -# function _series_updated(plt::Plot{PyPlotBackend}, series::Series) -# d = series.d -# for handle in get(d, :serieshandle, []) -# if is3d(series) -# handle[:set_data](d[:x], d[:y]) -# handle[:set_3d_properties](d[:z]) -# else -# try -# handle[:set_data](d[:x], d[:y]) -# catch -# handle[:set_offsets](hcat(d[:x], d[:y])) -# end -# end -# end -# update_limits!(d[:subplot], series, is3d(series) ? (:x,:y,:z) : (:x,:y)) -# end - - # -------------------------------------------------------------------------- function py_set_lims(ax, axis::Axis) @@ -1029,7 +908,6 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) w, h = plt[:size] fig = plt.o fig[:clear]() - # fig[:set_size_inches](px2inch(w), px2inch(h), forward = true) dpi = plt[:dpi] fig[:set_size_inches](w/dpi, h/dpi, forward = true) fig[:set_facecolor](py_color(plt[:background_color_outside])) @@ -1175,21 +1053,6 @@ end # ----------------------------------------------------------------- -# function _remove_axis(plt::Plot{PyPlotBackend}, isx::Bool) -# if isx -# plot!(plt, xticks=zeros(0), xlabel="") -# else -# plot!(plt, yticks=zeros(0), ylabel="") -# end -# end -# -# function _expand_limits(lims, plt::Plot{PyPlotBackend}, isx::Bool) -# pltlims = plt.o.ax[isx ? :get_xbound : :get_ybound]() -# _expand_limits(lims, pltlims) -# end - -# ----------------------------------------------------------------- - const _pyplot_legend_pos = KW( :right => "right", :left => "center left", @@ -1210,12 +1073,15 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) for series in series_list(sp) if should_add_to_legend(series) # add a line/marker and a label - push!(handles, if series.d[:seriestype] == :histogram - PyPlot.plt[:Line2D]((0,1),(0,0), color=py_fillcolor(series.d), linewidth=py_dpi_scale(plt, 4)) + push!(handles, if series[:seriestype] == :shape + PyPlot.plt[:Line2D]((0,1),(0,0), + color = py_color(cycle(series[:fillcolor],1)), + linewidth = py_dpi_scale(plt, 4) + ) else - series.d[:serieshandle][1] + series[:serieshandle][1] end) - push!(labels, series.d[:label]) + push!(labels, series[:label]) end end diff --git a/src/components.jl b/src/components.jl index bddb53bb..348a6426 100644 --- a/src/components.jl +++ b/src/components.jl @@ -14,13 +14,13 @@ compute_angle(v::P2) = (angle = atan2(v[2], v[1]); angle < 0 ? 2π - angle : ang immutable Shape x::Vector{Float64} y::Vector{Float64} - function Shape(x::AVec, y::AVec) - if x[1] != x[end] || y[1] != y[end] - new(vcat(x, x[1]), vcat(y, y[1])) - else - new(x, y) - end - end + # function Shape(x::AVec, y::AVec) + # # if x[1] != x[end] || y[1] != y[end] + # # new(vcat(x, x[1]), vcat(y, y[1])) + # # else + # new(x, y) + # end + # end end Shape(verts::AVec) = Shape(unzip(verts)...) diff --git a/src/recipes.jl b/src/recipes.jl index 9544d916..2bfb36cc 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -653,6 +653,8 @@ end # --------------------------------------------------------------------------- # Violin Plot +const _violin_warned = [false] + # if the user has KernelDensity installed, use this for violin plots. # otherwise, just use a histogram if is_installed("KernelDensity") @@ -668,7 +670,11 @@ if is_installed("KernelDensity") end else @eval function violin_coords(y; trim::Bool=false) - edges, widths = hist(y, 30) + if !_violin_warned[1] + warn("Install the KernelDensity package for best results.") + _violin_warned[1] = true + end + edges, widths = my_hist(y, 10) centers = 0.5 * (edges[1:end-1] + edges[2:end]) ymin, ymax = extrema(y) vcat(0.0, widths, 0.0), vcat(ymin, centers, ymax) diff --git a/src/series.jl b/src/series.jl index aa80af1a..df2d8d28 100644 --- a/src/series.jl +++ b/src/series.jl @@ -257,17 +257,17 @@ end # # plotting arbitrary shapes/polygons @recipe function f(shape::Shape) - seriestype := :shape + seriestype --> :shape shape_coords(shape) end @recipe function f(shapes::AVec{Shape}) - seriestype := :shape + seriestype --> :shape shape_coords(shapes) end @recipe function f(shapes::AMat{Shape}) - seriestype := :shape + seriestype --> :shape for j in 1:size(shapes,2) @series shape_coords(vec(shapes[:,j])) end diff --git a/src/utils.jl b/src/utils.jl index 1ff21004..e407ab46 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -166,7 +166,6 @@ end type SegmentsIterator args::Tuple - # nextidx::Int n::Int end function iter_segments(args...) @@ -176,13 +175,13 @@ function iter_segments(args...) end # helpers to figure out if there are NaN values in a list of array types -anynan(i::Int, args...) = any(a -> !isfinite(cycle(a,i)), args) -anynan(istart::Int, iend::Int, args...) = any(i -> anynan(i, args...), istart:iend) -allnan(istart::Int, iend::Int, args...) = all(i -> anynan(i, args...), istart:iend) +anynan(i::Int, args::Tuple) = any(a -> !isfinite(cycle(a,i)), args) +anynan(istart::Int, iend::Int, args::Tuple) = any(i -> anynan(i, args), istart:iend) +allnan(istart::Int, iend::Int, args::Tuple) = all(i -> anynan(i, args), istart:iend) function Base.start(itr::SegmentsIterator) nextidx = 1 - if anynan(1, itr.args...) + if anynan(1, itr.args) _, nextidx = next(itr, 1) end nextidx @@ -193,7 +192,7 @@ function Base.next(itr::SegmentsIterator, nextidx::Int) # find the next NaN, and iend is the one before while i <= itr.n + 1 - if i > itr.n || anynan(i, itr.args...) + if i > itr.n || anynan(i, itr.args) # done... array end or found NaN iend = i-1 break @@ -203,7 +202,7 @@ function Base.next(itr::SegmentsIterator, nextidx::Int) # find the next non-NaN, and set nextidx while i <= itr.n - if !anynan(i, itr.args...) + if !anynan(i, itr.args) break end i += 1 @@ -229,6 +228,8 @@ Base.cycle(v::AVec, indices::AVec{Int}) = map(i -> cycle(v,i), indices) Base.cycle(v::AMat, indices::AVec{Int}) = map(i -> cycle(v,i), indices) Base.cycle(v, idx::AVec{Int}) = v +Base.cycle(grad::ColorGradient, idx) = cycle(grad.colors, idx) + makevec(v::AVec) = v makevec{T}(v::T) = T[v] @@ -264,6 +265,7 @@ function _expand_limits(lims, x) nothing end +expand_data(v, n::Integer) = [cycle(v, i) for i=1:n] # if the type exists in a list, replace the first occurence. otherwise add it to the end function addOrReplace(v::AbstractVector, t::DataType, args...; kw...) @@ -368,6 +370,7 @@ is_2tuple(v) = typeof(v) <: Tuple && length(v) == 2 isvertical(d::KW) = get(d, :orientation, :vertical) in (:vertical, :v, :vert) +isvertical(series::Series) = isvertical(series.d) # ticksType{T<:Real,S<:Real}(ticks::@compat(Tuple{T,S})) = :limits @@ -427,7 +430,7 @@ end # this is a helper function to determine whether we need to transpose a surface matrix. # it depends on whether the backend matches rows to x (transpose_on_match == true) or vice versa # for example: PyPlot sends rows to y, so transpose_on_match should be true -function transpose_z(d::KW, z, transpose_on_match::Bool = true) +function transpose_z(d, z, transpose_on_match::Bool = true) if d[:match_dimensions] == transpose_on_match z' else diff --git a/test/runtests.jl b/test/runtests.jl index 56dc55b8..1c86e54e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -23,14 +23,14 @@ facts("PyPlot") do @fact pyplot() --> Plots.PyPlotBackend() @fact backend() --> Plots.PyPlotBackend() - image_comparison_facts(:pyplot, skip=[30], eps=img_eps) + image_comparison_facts(:pyplot, skip=[], eps=img_eps) end facts("GR") do @fact gr() --> Plots.GRBackend() @fact backend() --> Plots.GRBackend() - @linux_only image_comparison_facts(:gr, skip=[30], eps=img_eps) + @linux_only image_comparison_facts(:gr, skip=[], eps=img_eps) end facts("Plotly") do diff --git a/test/travis_commands.jl b/test/travis_commands.jl index a304b73e..49c285b8 100644 --- a/test/travis_commands.jl +++ b/test/travis_commands.jl @@ -11,6 +11,8 @@ Pkg.build("GR") # Pkg.clone("https://github.com/tbreloff/ExamplePlots.jl.git"); Pkg.clone("https://github.com/JuliaPlots/PlotReferenceImages.jl.git") +Pkg.clone("https://github.com/JuliaStats/KernelDensity.jl.git") + # Pkg.clone("https://github.com/JunoLab/Blink.jl.git") # Pkg.build("Blink") # import Blink