From 3cf428d7ea9c2811f892d2cb085a470549b3c6e3 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Mon, 6 Jun 2016 14:06:55 -0400 Subject: [PATCH] pyplot colorbar fix; annotation fix; new contour example; travis fix --- src/args.jl | 11 ++++++++--- src/backends/pyplot.jl | 2 +- src/examples.jl | 22 +++++++++++++++++----- src/plot.jl | 15 ++++++++++----- test/travis_commands.jl | 2 +- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/args.jl b/src/args.jl index 2006b320..6745a0dc 100644 --- a/src/args.jl +++ b/src/args.jl @@ -911,14 +911,19 @@ end # update a subplots args and axes -function _update_subplot_args(plt::Plot, sp::Subplot, d_in::KW, subplot_index::Integer) +function _update_subplot_args(plt::Plot, sp::Subplot, d_in::KW, subplot_index::Integer; remove_pair = true) pargs = plt.attr spargs = sp.attr - # @show subplot_index, sp + anns = pop!(sp.attr, :annotations, []) + + # grab those args which apply to this subplot for (k,v) in _subplot_defaults - slice_arg!(d_in, spargs, k, v, subplot_index) + slice_arg!(d_in, spargs, k, v, subplot_index, remove_pair = remove_pair) end + # extend annotations + sp.attr[:annotations] = vcat(anns, sp[:annotations]) + # handle legend/colorbar spargs[:legend] = convertLegendValue(spargs[:legend]) spargs[:colorbar] = convertLegendValue(spargs[:colorbar]) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index ff52554c..a63df531 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -815,7 +815,7 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series) # create and store the colorbar object (handle) and the axis that it is drawn on. # note: the colorbar axis is positioned independently from the subplot axis fig = plt.o - cbax = fig[:add_axes]([0.8,0.1,0.03,0.8]) + cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym())) sp.attr[:cbar_handle] = fig[:colorbar](handle; cax = cbax, kw...) sp.attr[:cbar_ax] = cbax end diff --git a/src/examples.jl b/src/examples.jl index e5ccd347..1a500427 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -179,6 +179,7 @@ PlotExample("Adding to subplots", PlotExample("", "", [:(begin + srand(111) plot!(Plots.fakedata(100,10)) end)] ), @@ -220,13 +221,24 @@ PlotExample("Custom Markers", ), PlotExample("Contours", - "", + "Any value for fill works here. We first build a filled contour from a function, then an unfilled contour from a matrix.", [:(begin - x = 1:0.3:20 - y = x - f(x,y) = sin(x)+cos(y) - contour(x, y, f, fill=true) + x = 1:0.5:20 + y = 1:0.5:10 + f(x,y) = (3x+y^2)*abs(sin(x)+cos(y)) + X = repmat(x', length(y), 1) + Y = repmat(y, 1, length(x)) + Z = map(f, X, Y) + p1 = contour(x, y, f, fill=true) + p2 = contour(x, y, Z) + plot(p1, p2) end)] + # [:(begin + # x = 1:0.3:20 + # y = x + # f(x,y) = sin(x)+cos(y) + # contour(x, y, f, fill=true) + # end)] ), PlotExample("Pie", diff --git a/src/plot.jl b/src/plot.jl index 844cb86e..88c7bb7c 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -283,9 +283,14 @@ function _plot!(plt::Plot, d::KW, args...) # merge in anything meant for plot/subplot for kw in kw_list for (k,v) in kw - if haskey(_plot_defaults, k) || haskey(_subplot_defaults, k) - d[k] = v + for defdict in (_plot_defaults, _subplot_defaults) + if haskey(defdict, k) + d[k] = pop!(kw, k) + end end + # if haskey(_plot_defaults, k) || haskey(_subplot_defaults, k) + # d[k] = v + # end end end @@ -309,11 +314,11 @@ function _plot!(plt::Plot, d::KW, args...) # first apply any args for the subplots for (idx,sp) in enumerate(plt.subplots) - _update_subplot_args(plt, sp, d, idx) + _update_subplot_args(plt, sp, d, idx, remove_pair = false) end # do we need to link any axes together? - link_axes!(plt.layout, plt.attr[:link]) + link_axes!(plt.layout, plt[:link]) # !!! note: At this point, kw_list is fully decomposed into individual series... one KW per series. !!! # !!! The next step is to recursively apply series recipes until the backend supports that series type !!! @@ -337,7 +342,7 @@ function _plot!(plt::Plot, d::KW, args...) # strip out series annotations (those which are based on series x/y coords) # and add them to the subplot attr - sp_anns = annotations(sp.attr[:annotations]) + sp_anns = annotations(sp[:annotations]) anns = annotations(pop!(kw, :series_annotations, [])) if length(anns) > 0 x, y = kw[:x], kw[:y] diff --git a/test/travis_commands.jl b/test/travis_commands.jl index 13d3b2f0..a304b73e 100644 --- a/test/travis_commands.jl +++ b/test/travis_commands.jl @@ -18,7 +18,7 @@ Pkg.clone("https://github.com/JuliaPlots/PlotReferenceImages.jl.git") # Pkg.clone("https://github.com/spencerlyon2/PlotlyJS.jl.git") Pkg.checkout("RecipesBase") -Pkg.checkout("VisualRegressionTests") +Pkg.clone("VisualRegressionTests") ENV["PYTHON"] = "" Pkg.add("PyPlot")