From 0e0450ced5321831353004caa2a586fcd5314279 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Mon, 25 Apr 2016 12:24:03 -0400 Subject: [PATCH] gadfly color fixes; pyplot fill_between fix; pyplot hline/vline --- src/backends/gadfly.jl | 22 +++++++++++----------- src/backends/pyplot.jl | 23 ++++++++++++++--------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 9f48085c..1d9f5993 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -79,12 +79,13 @@ function get_extra_theme_args(d::KW, k::Symbol) end function getGadflyLineTheme(d::KW) + lt = d[:linetype] lc = convertColor(getColor(d[:linecolor]), d[:linealpha]) fc = convertColor(getColor(d[:fillcolor]), d[:fillalpha]) Gadfly.Theme(; - default_color = lc, - line_width = (d[:linetype] == :sticks ? 1 : d[:linewidth]) * Gadfly.px, + default_color = (lt in (:hist,:hist2d,:hexbin) ? fc : lc), + line_width = (lt == :sticks ? 1 : d[:linewidth]) * Gadfly.px, # line_style = Gadfly.get_stroke_vector(d[:linestyle]), lowlight_color = x->RGB(fc), # fill/ribbon lowlight_opacity = alpha(fc), # fill/ribbon @@ -262,8 +263,8 @@ function addGadflySeries!(plt::Plot, d::KW) lt = d[:linetype] if lt == :ohlc error("Haven't re-implemented after refactoring") - elseif lt in (:hist2d, :hexbin) && (isa(d[:linecolor], ColorGradient) || isa(d[:linecolor], ColorFunction)) - push!(gplt.scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(d[:linecolor], p)))) + elseif lt in (:hist2d, :hexbin) && (isa(d[:fillcolor], ColorGradient) || isa(d[:fillcolor], ColorFunction)) + push!(gplt.scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(d[:fillcolor], p)))) elseif lt == :scatter && d[:markershape] == :none d[:markershape] = :ellipse end @@ -463,25 +464,24 @@ function updateGadflyPlotTheme(plt::Plot, d::KW) end if !get(d, :grid, true) - kwargs[:grid_color] = getColor(d[:background_color]) + kwargs[:grid_color] = getColor(d[:background_color_grid]) end # fonts tfont, gfont, lfont = d[:tickfont], d[:guidefont], d[:legendfont] - fg = getColor(d[:foreground_color]) getGadflyContext(plt).theme = Gadfly.Theme(; - background_color = getColor(d[:background_color]), - minor_label_color = fg, + background_color = getColor(d[:background_color_inside]), + minor_label_color = getColor(d[:foreground_color_text]), minor_label_font = tfont.family, minor_label_font_size = tfont.pointsize * Gadfly.pt, - major_label_color = fg, + major_label_color = gfont.color, major_label_font = gfont.family, major_label_font_size = gfont.pointsize * Gadfly.pt, - key_title_color = fg, + key_title_color = gfont.color, key_title_font = gfont.family, key_title_font_size = gfont.pointsize * Gadfly.pt, - key_label_color = fg, + key_label_color = lfont.color, key_label_font = lfont.family, key_label_font_size = lfont.pointsize * Gadfly.pt, plot_padding = 1 * Gadfly.mm, diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index b672bc6d..5a45d739 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -367,7 +367,6 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW) extrakw = KW() # :shape, - # :hist2d, :hexbin, # :hline, :vline, :heatmap, # :contour, :surface, :wireframe @@ -489,6 +488,18 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW) needs_colorbar = true end + if lt in (:hline,:vline) + for yi in d[:y] + func = ax[lt == :hline ? :axhline : :axvline] + handle = func(yi; + linewidth=d[:linewidth], + color=pylinecolor(d), + linestyle=getPyPlotLineStyle(lt, d[:linestyle]) + ) + push!(handles, handle) + end + end + d[:serieshandle] = handles # smoothing @@ -507,9 +518,9 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW) fillrange = d[:fillrange] if fillrange != nothing && lt != :contour if typeof(fillrange) <: @compat(Union{Real, AVec}) - ax[:fill_between](d[:x], fillrange, d[:y], facecolor = fillcolor, zorder = plt.n) + ax[:fill_between](d[:x], fillrange, d[:y], facecolor = pyfillcolor(d), zorder = plt.n) else - ax[:fill_between](d[:x], fillrange..., facecolor = fillcolor, zorder = plt.n) + ax[:fill_between](d[:x], fillrange..., facecolor = pyfillcolor(d), zorder = plt.n) end end @@ -788,12 +799,6 @@ function setxy!{X,Y}(plt::Plot{PyPlotBackend}, xy::Tuple{X,Y}, i::Integer) handle[:set_offsets](hcat(xy...)) end end - # series = d[:serieshandle] - # try - # series[:set_data](d[:x], d[:y]) - # catch - # series[:set_offsets](hcat(d[:x], d[:y])) - # end set_lims!(plt, d[:axis]) plt end