From 77c2d7d846f27246b3420f7eca942fbea5001560 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Mon, 25 Apr 2016 11:37:14 -0400 Subject: [PATCH] subcategories for background/foreground colors, implemented in pyplot; add_theme/set_theme and ggplot2; add_aliases function; nbins renamed bins --- src/Plots.jl | 2 + src/args.jl | 435 ++++++++++++++++++++++++++------------ src/backends/gadfly.jl | 2 +- src/backends/gr.jl | 12 +- src/backends/plotly.jl | 8 +- src/backends/pyplot.jl | 49 +++-- src/backends/qwt.jl | 2 +- src/backends/supported.jl | 25 ++- src/backends/winston.jl | 4 +- src/colors.jl | 56 +++-- src/utils.jl | 2 +- 11 files changed, 400 insertions(+), 197 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index 1a043782..9e5b3cd1 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -20,6 +20,8 @@ export AVec, AMat, KW, + set_theme, + add_theme, plot, plot!, diff --git a/src/args.jl b/src/args.jl index d6a88a46..eb95d488 100644 --- a/src/args.jl +++ b/src/args.jl @@ -120,14 +120,10 @@ _seriesDefaults[:linestyle] = :solid _seriesDefaults[:linewidth] = 1 _seriesDefaults[:linecolor] = :match _seriesDefaults[:linealpha] = nothing -# _seriesDefaults[:linestroke] = Stroke(1, :auto, nothing, :solid) # linewidth, linecolor, linealpha, linestyle -# _seriesDefaults[:fillbrush] = Brush(nothing, :match, nothing) # fillrange, fillcolor, fillalpha _seriesDefaults[:fillrange] = nothing # ribbons, areas, etc _seriesDefaults[:fillcolor] = :match _seriesDefaults[:fillalpha] = nothing _seriesDefaults[:markershape] = :none -# _seriesDefaults[:markerstroke] = Stroke(1, :match_foreground, nothing, :solid) -# _seriesDefaults[:markerbrush] = Brush(6, :match, nothing) _seriesDefaults[:markercolor] = :match _seriesDefaults[:markeralpha] = nothing _seriesDefaults[:markersize] = 6 @@ -135,18 +131,13 @@ _seriesDefaults[:markerstrokestyle] = :solid _seriesDefaults[:markerstrokewidth] = 1 _seriesDefaults[:markerstrokecolor] = :match _seriesDefaults[:markerstrokealpha] = nothing -# _seriesDefaults[:ribbon] = nothing -# _seriesDefaults[:ribboncolor] = :match -_seriesDefaults[:nbins] = 30 # number of bins for hists +_seriesDefaults[:bins] = 30 # number of bins for hists _seriesDefaults[:smooth] = false # regression line? _seriesDefaults[:group] = nothing # groupby vector -# _seriesDefaults[:annotation] = nothing # annotation tuple(s)... (x,y,annotation) _seriesDefaults[:x] = nothing _seriesDefaults[:y] = nothing _seriesDefaults[:z] = nothing # depth for contour, surface, etc _seriesDefaults[:marker_z] = nothing # value for color scale -# _seriesDefaults[:surface] = nothing -# _seriesDefaults[:nlevels] = 15 _seriesDefaults[:levels] = 15 _seriesDefaults[:orientation] = :vertical _seriesDefaults[:bar_position] = :overlay # for bar plots and histograms: could also be stack (stack up) or dodge (side by side) @@ -168,8 +159,16 @@ _plotDefaults[:zlabel] = "" _plotDefaults[:yrightlabel] = "" _plotDefaults[:legend] = :best _plotDefaults[:colorbar] = :legend -_plotDefaults[:background_color] = colorant"white" -_plotDefaults[:foreground_color] = :auto +_plotDefaults[:background_color] = colorant"white" # default for all backgrounds +_plotDefaults[:background_color_legend] = :match # background of legend +_plotDefaults[:background_color_inside] = :match # background inside grid +_plotDefaults[:background_color_outside] = :match # background outside grid +_plotDefaults[:foreground_color] = :auto # default for all foregrounds +_plotDefaults[:foreground_color_legend] = :match # foreground of legend +_plotDefaults[:foreground_color_grid] = :match # grid color +_plotDefaults[:foreground_color_axis] = :match # axis border/tick colors +_plotDefaults[:foreground_color_text] = :match # tick/guide text color +_plotDefaults[:foreground_color_border] = :match # plot area border/spines _plotDefaults[:xlims] = :auto _plotDefaults[:ylims] = :auto _plotDefaults[:zlims] = :auto @@ -236,132 +235,230 @@ end # ----------------------------------------------------------------------------- +const _keyAliases = KW() + +function add_aliases(sym::Symbol, aliases::Symbol...) + for alias in aliases + if haskey(_keyAliases, alias) + error("Already an alias $alias => $(_keyAliases[alias])... can't also alias $sym") + end + _keyAliases[alias] = sym + end +end + +# colors +add_aliases(:seriescolor, :c, :color, :colour) +add_aliases(:linecolor, :lc, :lcolor, :lcolour, :linecolour) +add_aliases(:markercolor, :mc, :mcolor, :mcolour, :markercolour) +add_aliases(:markerstokecolor, :msc, :mscolor, :mscolour, :markerstokecolour) +add_aliases(:fillcolor, :fc, :fcolor, :fcolour, :fillcolour) + +add_aliases(:background_color, :bg, :bgcolor, :bg_color, :background, + :background_colour, :bgcolour, :bg_colour) +add_aliases(:background_color_legend, :bg_legend, :bglegend, :bgcolor_legend, :bg_color_legend, :background_legend, + :background_colour_legend, :bgcolour_legend, :bg_colour_legend) +add_aliases(:background_color_inside, :bg_inside, :bginside, :bgcolor_inside, :bg_color_inside, :background_inside, + :background_colour_inside, :bgcolour_inside, :bg_colour_inside) +add_aliases(:background_color_outside, :bg_outside, :bgoutside, :bgcolor_outside, :bg_color_outside, :background_outside, + :background_colour_outside, :bgcolour_outside, :bg_colour_outside) +add_aliases(:foreground_color, :fg, :fgcolor, :fg_color, :foreground, + :foreground_colour, :fgcolour, :fg_colour) +add_aliases(:foreground_color_legend, :fg_legend, :fglegend, :fgcolor_legend, :fg_color_legend, :foreground_legend, + :foreground_colour_legend, :fgcolour_legend, :fg_colour_legend) +add_aliases(:foreground_color_grid, :fg_grid, :fggrid, :fgcolor_grid, :fg_color_grid, :foreground_grid, + :foreground_colour_grid, :fgcolour_grid, :fg_colour_grid) +add_aliases(:foreground_color_axis, :fg_axis, :fgaxis, :fgcolor_axis, :fg_color_axis, :foreground_axis, + :foreground_colour_axis, :fgcolour_axis, :fg_colour_axis) +add_aliases(:foreground_color_text, :fg_text, :fgtext, :fgcolor_text, :fg_color_text, :foreground_text, + :foreground_colour_text, :fgcolour_text, :fg_colour_text) +add_aliases(:foreground_color_border, :fg_border, :fgborder, :fgcolor_border, :fg_color_border, :foreground_border, + :foreground_colour_border, :fgcolour_border, :fg_colour_border) + +# alphas +add_aliases(:seriesalpha, :alpha, :α, :opacity) +add_aliases(:linealpha, :la, :lalpha, :lα, :lineopacity, :lopacity) +add_aliases(:makeralpha, :ma, :malpha, :mα, :makeropacity, :mopacity) +add_aliases(:markerstrokealpha, :msa, :msalpha, :msα, :markerstrokeopacity, :msopacity) +add_aliases(:fillalpha, :fa, :falpha, :fα, :fillopacity, :fopacity) + +add_aliases(:label, :lab) +add_aliases(:line, :l) +add_aliases(:linewidth, :w, :width, :lw) +add_aliases(:linetype, :lt, :t, :seriestype) +add_aliases(:linestyle, :style, :s, :ls) +add_aliases(:marker, :m, :mark) +add_aliases(:markershape, :shape) +add_aliases(:markersize, :ms, :msize) +add_aliases(:marker_z, :markerz, :zcolor) +add_aliases(:fill, :f, :area) +add_aliases(:fillrange, :fillrng, :frange, :fillto, :fill_between) +add_aliases(:group, :g, :grouping) +add_aliases(:bins, :bin, :nbin, :nbins, :nb) +add_aliases(:ribbon, :rib) +add_aliases(:annotation, :ann, :anns, :annotate, :annotations) +add_aliases(:xlabel, :xlab, :xl) +add_aliases(:xlims, :xlim, :xlimit, :xlimits) +add_aliases(:xticks, :xtick) +add_aliases(:ylabel, :ylab, :yl) +add_aliases(:ylims, :ylim, :ylimit, :ylimits) +add_aliases(:yticks, :ytick) +add_aliases(:yrightlabel, :yrlab, :yrl, :ylabel2, :y2label, :ylab2, :y2lab, :ylabr, :ylabelright) +add_aliases(:yrightlims, :yrlim, :yrlimit, :yrlimits) +add_aliases(:yrightticks, :yrtick) +add_aliases(:zlabel, :zlab, :zl) +add_aliases(:zlims, :zlim, :zlimit, :zlimits) +add_aliases(:zticks, :ztick) +add_aliases(:legend, :leg, :key) +add_aliases(:colorbar, :cb, :cbar, :colorkey) +add_aliases(:smooth, :regression, :reg) +add_aliases(:levels, :nlevels, :nlev, :levs) +add_aliases(:size, :windowsize, :wsize) +add_aliases(:windowtitle, :wtitle) +add_aliases(:show, :gui, :display) +add_aliases(:color_palette, :palette) +add_aliases(:linkx, :xlink) +add_aliases(:linky, :ylink) +add_aliases(:nr, :nrow, :nrows, :rows) +add_aliases(:nc, :ncol, :ncols, :cols, :ncolumns, :columns) +add_aliases(:overwrite_figure, :clf, :clearfig, :overwrite, :reuse) +add_aliases(:xerror, :xerr, :xerrorbar) +add_aliases(:yerror, :yerr, :yerrorbar, :err, :errorbar) +add_aliases(:quiver, :velocity, :quiver2d, :gradient) +add_aliases(:normalize, :norm, :normed, :normalized) + + + # Alternate args -@compat const _keyAliases = KW( - :c => :seriescolor, - :color => :seriescolor, - :colour => :seriescolor, - :alpha => :seriesalpha, - :α => :seriesalpha, - :opacity => :seriesalpha, - :lc => :linecolor, - :lcolor => :linecolor, - :lcolour => :linecolor, - :lab => :label, - :l => :line, - :w => :linewidth, - :width => :linewidth, - :lw => :linewidth, - :la => :linealpha, - :lalpha => :linealpha, - :lineopacity => :linealpha, - :type => :linetype, - :lt => :linetype, - :t => :linetype, - :seriestype => :linetype, - :style => :linestyle, - :s => :linestyle, - :ls => :linestyle, - :m => :marker, - :mark => :marker, - :shape => :markershape, - :mc => :markercolor, - :mcolor => :markercolor, - :markercolour => :markercolor, - :ms => :markersize, - :msize => :markersize, - :ma => :markeralpha, - :malpha => :markeralpha, - :mopacity => :markeralpha, - :markeropacity => :markeralpha, - :zcolor => :marker_z, - :f => :fill, - :area => :fill, - :fillrng => :fillrange, - :fc => :fillcolor, - :fcolor => :fillcolor, - :fillcolour => :fillcolor, - :fa => :fillalpha, - :falpha => :fillalpha, - :fillopacity => :fillalpha, - :g => :group, - :nb => :nbins, - :nbin => :nbins, - :rib => :ribbon, - :ann => :annotation, - :anns => :annotation, - :annotate => :annotation, - :annotations => :annotation, - :xlab => :xlabel, - :ylab => :ylabel, - :zlab => :zlabel, - :yrlab => :yrightlabel, - :ylabr => :yrightlabel, - :y2lab => :yrightlabel, - :ylab2 => :yrightlabel, - :ylabelright => :yrightlabel, - :ylabel2 => :yrightlabel, - :y2label => :yrightlabel, - :leg => :legend, - :key => :legend, - :cbar => :colorbar, - :cb => :colorbar, - :bg => :background_color, - :bgcolor => :background_color, - :bg_color => :background_color, - :background => :background_color, - :background_colour => :background_color, - :fg => :foreground_color, - :fgcolor => :foreground_color, - :fg_color => :foreground_color, - :foreground => :foreground_color, - :foreground_colour => :foreground_color, - :regression => :smooth, - :reg => :smooth, - :nlevels => :levels, - :nlev => :levels, - :levs => :levels, - :xlim => :xlims, - :xlimit => :xlims, - :xlimits => :xlims, - :ylim => :ylims, - :ylimit => :ylims, - :ylimits => :ylims, - :zlim => :zlims, - :zlimit => :zlims, - :zlimits => :zlims, - :xtick => :xticks, - :ytick => :yticks, - :windowsize => :size, - :wsize => :size, - :wtitle => :windowtitle, - :gui => :show, - :display => :show, - :palette => :color_palette, - :xlink => :linkx, - :ylink => :linky, - :nrow => :nr, - :nrows => :nr, - :ncol => :nc, - :ncols => :nc, - :clf => :overwrite_figure, - :clearfig => :overwrite_figure, - :overwrite => :overwrite_figure, - :reuse => :overwrite_figure, - :err => :yerror, - :errorbar => :yerror, - :xerr => :xerror, - :xerrorbar => :xerror, - :yerr => :yerror, - :yerrorbar => :yerror, - :velocity => :quiver, - :quiver2d => :quiver, - :gradient => :quiver, - :norm => :normalize, - :normed => :normalize, - :normalized => :normalize, - ) +# @compat const _keyAliases = KW( + # :c => :seriescolor, + # :color => :seriescolor, + # :colour => :seriescolor, + # :alpha => :seriesalpha, + # :α => :seriesalpha, + # :opacity => :seriesalpha, + # :lc => :linecolor, + # :lcolor => :linecolor, + # :lcolour => :linecolor, + # :lab => :label, + # :l => :line, + # :w => :linewidth, + # :width => :linewidth, + # :lw => :linewidth, + # :la => :linealpha, + # :lalpha => :linealpha, + # :lineopacity => :linealpha, + # :type => :linetype, + # :lt => :linetype, + # :t => :linetype, + # :seriestype => :linetype, + # :style => :linestyle, + # :s => :linestyle, + # :ls => :linestyle, + # :m => :marker, + # :mark => :marker, + # :shape => :markershape, + # :mc => :markercolor, + # :mcolor => :markercolor, + # :markercolour => :markercolor, + # :ms => :markersize, + # :msize => :markersize, + # :ma => :markeralpha, + # :malpha => :markeralpha, + # :mopacity => :markeralpha, + # :markeropacity => :markeralpha, + # :zcolor => :marker_z, + # :f => :fill, + # :area => :fill, + # :fillrng => :fillrange, + # :fc => :fillcolor, + # :fcolor => :fillcolor, + # :fillcolour => :fillcolor, + # :fa => :fillalpha, + # :falpha => :fillalpha, + # :fillopacity => :fillalpha, + # :g => :group, + # :nb => :nbins, + # :nbin => :nbins, + # :rib => :ribbon, + # :ann => :annotation, + # :anns => :annotation, + # :annotate => :annotation, + # :annotations => :annotation, + # :xlab => :xlabel, + # :ylab => :ylabel, + # :zlab => :zlabel, + # :yrlab => :yrightlabel, + # :ylabr => :yrightlabel, + # :y2lab => :yrightlabel, + # :ylab2 => :yrightlabel, + # :ylabelright => :yrightlabel, + # :ylabel2 => :yrightlabel, + # :y2label => :yrightlabel, + # :leg => :legend, + # :key => :legend, + # :cbar => :colorbar, + # :cb => :colorbar, + # :bg => :background_color, + # :bgcolor => :background_color, + # :bg_color => :background_color, + # :background => :background_color, + # :background_colour => :background_color, + # :fg => :foreground_color, + # :fgcolor => :foreground_color, + # :fg_color => :foreground_color, + # :foreground => :foreground_color, + # :foreground_colour => :foreground_color, + # :bglegend => :background_color_legend, + # :bg_legend => :background_color_legend, + # :bgcolor_legend => :background_color_legend, + # :background_legend => :background_color_legend, + # :bglegend => :background_color_legend, + # :regression => :smooth, + # :reg => :smooth, + # :nlevels => :levels, + # :nlev => :levels, + # :levs => :levels, + # :xlim => :xlims, + # :xlimit => :xlims, + # :xlimits => :xlims, + # :ylim => :ylims, + # :ylimit => :ylims, + # :ylimits => :ylims, + # :zlim => :zlims, + # :zlimit => :zlims, + # :zlimits => :zlims, + # :xtick => :xticks, + # :ytick => :yticks, + # :windowsize => :size, + # :wsize => :size, + # :wtitle => :windowtitle, + # :gui => :show, + # :display => :show, + # :palette => :color_palette, + # :xlink => :linkx, + # :ylink => :linky, + # :nrow => :nr, + # :nrows => :nr, + # :ncol => :nc, + # :ncols => :nc, + # :clf => :overwrite_figure, + # :clearfig => :overwrite_figure, + # :overwrite => :overwrite_figure, + # # :reuse => :overwrite_figure, + # :err => :yerror, + # :errorbar => :yerror, + # :xerr => :xerror, + # :xerrorbar => :xerror, + # :yerr => :yerror, + # :yerrorbar => :yerror, + # :velocity => :quiver, + # :quiver2d => :quiver, + # :gradient => :quiver, + # :norm => :normalize, + # :normed => :normalize, + # :normalized => :normalize, + # ) # add all pluralized forms to the _keyAliases dict for arg in keys(_seriesDefaults) @@ -410,6 +507,72 @@ end # ----------------------------------------------------------------------------- +const _invisible = RGBA(0,0,0,0) + +const _themes = KW( + :default => KW( + :bg => :white, + :bglegend => :match, + :bginside => :match, + :bgoutside => :match, + :fg => :auto, + :fglegend => :match, + :fggrid => :match, + :fgaxis => :match, + :fgtext => :match, + :fgborder => :match, + ), + :ggplot2 => KW( + :bg => :white, + :bglegend => _invisible, + :bginside => :lightgray, + :bgoutside => :match, + :fg => :white, + :fglegend => _invisible, + :fggrid => :match, + :fgaxis => :match, + :fgtext => :gray, + :fgborder => :match, + ), +) + +function add_theme(sym::Symbol, theme::KW) + _themes[sym] = theme +end + +# add a new theme, using an existing theme as the base +function add_theme(sym::Symbol; + base = :default, # start with this theme + bg = _themes[base][:bg], + bglegend = _themes[base][:bglegend], + bginside = _themes[base][:bginside], + bgoutside = _themes[base][:bgoutside], + fg = _themes[base][:fg], + fglegend = _themes[base][:fglegend], + fggrid = _themes[base][:fggrid], + fgaxis = _themes[base][:fgaxis], + fgtext = _themes[base][:fgtext], + fgborder = _themes[base][:fgborder]) + _themes[sym] = KW( + :bg => bg, + :bglegend => bglegend, + :bginside => bginside, + :bgoutside => bgoutside, + :fg => fg, + :fglegend => fglegend, + :fggrid => fggrid, + :fgaxis => fgaxis, + :fgtext => fgtext, + :fgborder => fgborder, + ) +end + +function set_theme(sym::Symbol) + default(; _themes[sym]...) +end + +# ----------------------------------------------------------------------------- + # if arg is a valid color value, then set d[csym] and return true function handleColors!(d::KW, arg, csym::Symbol) try diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index a1bbc5b5..9f48085c 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -33,7 +33,7 @@ end function getLineGeom(d::KW) lt = d[:linetype] - xbins, ybins = maketuple(d[:nbins]) + xbins, ybins = maketuple(d[:bins]) if lt == :hexb Gadfly.Geom.hexbin(xbincount = xbins, ybincount = ybins) elseif lt == :hist2d diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 74ecfa4c..460b4c68 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -165,10 +165,10 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, E = zeros(length(p[:x]),2) E[:,1] = p[:x] E[:,2] = p[:y] - if isa(p[:nbins], Tuple) - xbins, ybins = p[:nbins] + if isa(p[:bins], Tuple) + xbins, ybins = p[:bins] else - xbins = ybins = p[:nbins] + xbins = ybins = p[:bins] end cmap = true x, y, H = Base.hist2d(E, xbins, ybins) @@ -434,10 +434,10 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true, E = zeros(length(p[:x]),2) E[:,1] = p[:x] E[:,2] = p[:y] - if isa(p[:nbins], Tuple) - xbins, ybins = p[:nbins] + if isa(p[:bins], Tuple) + xbins, ybins = p[:bins] else - xbins = ybins = p[:nbins] + xbins = ybins = p[:bins] end x, y, H = Base.hist2d(E, xbins, ybins) counts = round(Int32, 1000 + 255 * H / maximum(H)) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 921cb84a..fb443ebd 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -308,10 +308,10 @@ function plotly_series(d::KW, plotargs::KW; plot_index = nothing) elseif lt == :hist2d d_out[:type] = "histogram2d" d_out[:x], d_out[:y] = x, y - if isa(d[:nbins], Tuple) - xbins, ybins = d[:nbins] + if isa(d[:bins], Tuple) + xbins, ybins = d[:bins] else - xbins = ybins = d[:nbins] + xbins = ybins = d[:bins] end d_out[:nbinsx] = xbins d_out[:nbinsy] = ybins @@ -320,7 +320,7 @@ function plotly_series(d::KW, plotargs::KW; plot_index = nothing) d_out[:type] = "histogram" isvert = isvertical(d) d_out[isvert ? :x : :y] = y - d_out[isvert ? :nbinsx : :nbinsy] = d[:nbins] + d_out[isvert ? :nbinsx : :nbinsy] = d[:bins] if lt == :density d_out[:histnorm] = "probability density" end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 43a4124d..9e8cf32f 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -223,7 +223,8 @@ end function pyplot_figure(plotargs::KW) w,h = map(px2inch, plotargs[:size]) - bgcolor = getPyPlotColor(plotargs[:background_color]) + # bgcolor = getPyPlotColor(plotargs[:background_color]) + # reuse the current figure? fig = if plotargs[:overwrite_figure] @@ -235,7 +236,8 @@ function pyplot_figure(plotargs::KW) # update the specs # fig[:set_size_inches](w,h, (isijulia() ? [] : [true])...) fig[:set_size_inches](w, h, forward = true) - fig[:set_facecolor](bgcolor) + # fig[:set_facecolor](bgcolor) + fig[:set_facecolor](getPyPlotColor(plotargs[:background_color_outside])) fig[:set_dpi](DPI) fig[:set_tight_layout](true) @@ -451,7 +453,7 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW) color = pyfillcolor(d), edgecolor = pylinecolor(d), linewidth = d[:linewidth], - bins = d[:nbins], + bins = d[:bins], normed = d[:normalize], weights = d[:weights], orientation = (isvertical(d) ? "vertical" : "horizontal"), @@ -465,7 +467,7 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW) handle = ax[:hist2d](x, y; label = d[:label], zorder = plt.n + 0.5, - bins = d[:nbins], + bins = d[:bins], normed = d[:normalize], weights = d[:weights], cmap = pyfillcolormap(d) # applies to the pcolorfast object @@ -478,7 +480,7 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW) handle = ax[:hexbin](x, y; label = d[:label], zorder = plt.n + 0.5, - gridsize = d[:nbins], + gridsize = d[:bins], linewidths = d[:linewidth], edgecolors = pylinecolor(d), cmap = pyfillcolormap(d) # applies to the pcolorfast object @@ -498,7 +500,8 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW) end # this sets the bg color inside the grid - ax[:set_axis_bgcolor](getPyPlotColor(plt.plotargs[:background_color])) + # ax[:set_axis_bgcolor](getPyPlotColor(plt.plotargs[:background_color])) + ax[:set_axis_bgcolor](getPyPlotColor(plt.plotargs[:background_color_inside])) # handle area filling fillrange = d[:fillrange] @@ -571,7 +574,7 @@ function _add_series2(pkg::PyPlotBackend, plt::Plot, d::KW) # extra_kwargs[:bottom] = d[:fill] if like_histogram(lt) - extra_kwargs[:bins] = d[:nbins] + extra_kwargs[:bins] = d[:bins] extra_kwargs[:normed] = lt == :density extra_kwargs[:orientation] = isvertical(d) ? "vertical" : "horizontal" extra_kwargs[:histtype] = d[:bar_position] == :stack ? "barstacked" : "bar" @@ -580,7 +583,7 @@ function _add_series2(pkg::PyPlotBackend, plt::Plot, d::KW) end elseif lt in (:hist2d, :hexbin) - extra_kwargs[:gridsize] = d[:nbins] + extra_kwargs[:gridsize] = d[:bins] extra_kwargs[:cmap] = linecmap elseif lt == :contour @@ -858,18 +861,21 @@ function applyPyPlotScale(ax, scaleType::Symbol, letter) end -function updateAxisColors(ax, fgcolor) +function updateAxisColors(ax, d::KW) + guidecolor = getPyPlotColor(d[:guidefont].color) for (loc, spine) in ax[:spines] - spine[:set_color](fgcolor) + spine[:set_color](getPyPlotColor(d[:foreground_color_border])) end for letter in ("x", "y", "z") axis = axis_symbol(letter, "axis") if haskey(ax, axis) - ax[:tick_params](axis=letter, colors=fgcolor, which="both") - ax[axis][:label][:set_color](fgcolor) + ax[:tick_params](axis=letter, which="both", + colors=getPyPlotColor(d[:foreground_color_axis]), + labelcolor=getPyPlotColor(d[:foreground_color_text])) + ax[axis][:label][:set_color](guidecolor) end end - ax[:title][:set_color](fgcolor) + ax[:title][:set_color](guidecolor) end function usingRightAxis(plt::Plot{PyPlotBackend}) @@ -917,7 +923,8 @@ function _update_plot(plt::Plot{PyPlotBackend}, d::KW) lab[:set_fontsize](ticksz) end if get(d, :grid, false) - fgcolor = getPyPlotColor(plt.plotargs[:foreground_color]) + # fgcolor = getPyPlotColor(plt.plotargs[:foreground_color]) + fgcolor = getPyPlotColor(plt.plotargs[:foreground_color_grid]) tmpax[axis][:grid](true, color = fgcolor) tmpax[:set_axisbelow](true) end @@ -1038,10 +1045,16 @@ function addPyPlotLegend(plt::Plot, ax) leg = ax[:legend]([d[:serieshandle][1] for d in args], [d[:label] for d in args], loc = get(_pyplot_legend_pos, leg, "best"), + scatterpoints = 1, fontsize = plt.plotargs[:legendfont].pointsize # framealpha = 0.6 ) leg[:set_zorder](1000) + + # set some legend properties + frame = leg[:get_frame]() + frame[:set_facecolor](getPyPlotColor(plt.plotargs[:background_color_legend])) + frame[:set_edgecolor](getPyPlotColor(plt.plotargs[:foreground_color_legend])) end end end @@ -1051,7 +1064,9 @@ end function finalizePlot(plt::Plot{PyPlotBackend}) ax = getLeftAxis(plt) addPyPlotLegend(plt, ax) - updateAxisColors(ax, getPyPlotColor(plt.plotargs[:foreground_color])) + updateAxisColors(ax, plt.plotargs) + # updateAxisColors(ax, getPyPlotColor(plt.plotargs[:foreground_color_axis]), + # getPyPlotColor(plt.plotargs[:foreground_color_text])) PyPlot.draw() end @@ -1060,7 +1075,9 @@ function finalizePlot(subplt::Subplot{PyPlotBackend}) for (i,plt) in enumerate(subplt.plts) ax = getLeftAxis(plt) addPyPlotLegend(plt, ax) - updateAxisColors(ax, getPyPlotColor(plt.plotargs[:foreground_color])) + updateAxisColors(ax, plt.plotargs) + # updateAxisColors(ax, getPyPlotColor(plt.plotargs[:foreground_color_axis]), + # getPyPlotColor(plt.plotargs[:foreground_color_text])) end # fig[:tight_layout]() PyPlot.draw() diff --git a/src/backends/qwt.jl b/src/backends/qwt.jl index 2728c8a5..218b1ca2 100644 --- a/src/backends/qwt.jl +++ b/src/backends/qwt.jl @@ -12,7 +12,7 @@ end # ------------------------------- @compat const _qwtAliases = KW( - :nbins => :heatmap_n, + :bins => :heatmap_n, :fillrange => :fillto, :linewidth => :width, :markershape => :marker, diff --git a/src/backends/supported.jl b/src/backends/supported.jl index 0d269bb1..ab261166 100644 --- a/src/backends/supported.jl +++ b/src/backends/supported.jl @@ -30,7 +30,7 @@ supportedArgs(::GadflyBackend) = [ :markershape, :markercolor, :markersize, :markeralpha, :markerstrokewidth, :markerstrokecolor, :markerstrokealpha, :fillrange, :fillcolor, :fillalpha, - :nbins, + :bins, :n, :nc, :nr, :layout, :smooth, :title, :windowtitle, :show, :size, @@ -76,6 +76,9 @@ subplotSupported(::ImmerseBackend) = true supportedArgs(::PyPlotBackend) = [ :annotation, :background_color, :foreground_color, :color_palette, + :background_color_legend, :background_color_inside, :background_color_outside, + :foreground_color_legend, :foreground_color_grid, :foreground_color_axis, + :foreground_color_text, :foreground_color_border, :group, :label, :linetype, @@ -84,7 +87,7 @@ supportedArgs(::PyPlotBackend) = [ :markershape, :markercolor, :markersize, :markeralpha, :markerstrokewidth, :markerstrokecolor, :markerstrokealpha, :fillrange, :fillcolor, :fillalpha, - :nbins, + :bins, :n, :nc, :nr, :layout, :smooth, :title, :windowtitle, :show, :size, @@ -146,7 +149,7 @@ supportedArgs(::GRBackend) = [ :markerstrokecolor, # :markerstrokestyle, :n, - :nbins, + :bins, :nc, :nr, # :pos, @@ -228,7 +231,7 @@ supportedArgs(::QwtBackend) = [ # :markerstrokecolor, # :markerstrokestyle, :n, - :nbins, + :bins, :nc, :nr, :pos, @@ -287,7 +290,7 @@ supportedArgs(::UnicodePlotsBackend) = [ # :markerstrokecolor, # :markerstrokestyle, # :n, - :nbins, + :bins, # :nc, # :nr, # :pos, @@ -352,7 +355,7 @@ supportedArgs(::WinstonBackend) = [ # :markerstrokecolor, # :markerstrokestyle, # :n, - :nbins, + :bins, # :nc, # :nr, # :pos, @@ -416,7 +419,7 @@ supportedArgs(::BokehBackend) = [ # :markerstrokecolor, # :markerstrokestyle, # :n, - # :nbins, + # :bins, # :nc, # :nr, # :pos, @@ -483,7 +486,7 @@ supportedArgs(::PlotlyBackend) = [ :markerstrokecolor, :markerstrokestyle, :n, - :nbins, + :bins, :nc, :nr, # :pos, @@ -560,7 +563,7 @@ supportedArgs(::PlotlyJSBackend) = [ :markerstrokecolor, :markerstrokestyle, :n, - :nbins, + :bins, :nc, :nr, # :pos, @@ -636,7 +639,7 @@ supportedArgs(::GLVisualizeBackend) = [ # :markerstrokecolor, # :markerstrokestyle, # :n, - # :nbins, + # :bins, # :nc, # :nr, # :pos, @@ -702,7 +705,7 @@ supportedArgs(::PGFPlotsBackend) = [ # :markerstrokecolor, # :markerstrokestyle, # :n, - # :nbins, + # :bins, # :nc, # :nr, # :pos, diff --git a/src/backends/winston.jl b/src/backends/winston.jl index dc9fc138..e4c85195 100644 --- a/src/backends/winston.jl +++ b/src/backends/winston.jl @@ -127,8 +127,8 @@ function _add_series(::WinstonBackend, plt::Plot, d::KW) # fn = Winston.XXX elseif d[:linetype] == :hist - hst = hist(d[:y], d[:nbins]) - Winston.add(wplt, Winston.Histogram(hst...; copy_remove(e, :nbins)...)) + hst = hist(d[:y], d[:bins]) + Winston.add(wplt, Winston.Histogram(hst...; copy_remove(e, :bins)...)) # elseif d[:linetype] == :bar # # fn = Winston.XXX diff --git a/src/colors.jl b/src/colors.jl index f5da9f2c..13dff212 100644 --- a/src/colors.jl +++ b/src/colors.jl @@ -361,31 +361,49 @@ webcolor(c, α) = webcolor(convertColor(getColor(c), α)) # TODO: allow the setting of the algorithm, either by passing a symbol (:colordiff, :fixed, etc) or a function? function handlePlotColors(::AbstractBackend, d::KW) - if :background_color in supportedArgs() - bgcolor = convertColor(d[:background_color]) - else - bgcolor = _plotDefaults[:background_color] - if d[:background_color] != _plotDefaults[:background_color] - warn("Cannot set background_color with backend $(backend())") + if :background_color in supportedArgs() + bgcolor = convertColor(d[:background_color]) + else + bgcolor = _plotDefaults[:background_color] + if d[:background_color] != _plotDefaults[:background_color] + warn("Cannot set background_color with backend $(backend())") + end end - end - d[:color_palette] = get_color_palette(get(d, :color_palette, :auto), bgcolor, 100) + d[:color_palette] = get_color_palette(get(d, :color_palette, :auto), bgcolor, 100) - # set the foreground color (text, ticks, gridlines) to be white or black depending - # on how dark the background is. - fgcolor = get(d, :foreground_color, :auto) - fgcolor = if fgcolor == :auto - isdark(bgcolor) ? colorant"white" : colorant"black" - else - convertColor(fgcolor) - end + # set the foreground color (text, ticks, gridlines) to be white or black depending + # on how dark the background is. + fgcolor = get(d, :foreground_color, :auto) + fgcolor = if fgcolor == :auto + isdark(bgcolor) ? colorant"white" : colorant"black" + else + convertColor(fgcolor) + end + + # bg/fg color + d[:background_color] = colorscheme(bgcolor) + d[:foreground_color] = colorscheme(fgcolor) + + # update sub-background colors + for bgtype in ("legend", "inside", "outside") + bgsym = symbol("background_color_" * bgtype) + if d[bgsym] == :match + d[bgsym] = d[:background_color] + end + end + + # update sub-foreground colors + for fgtype in ("legend", "grid", "axis", "text", "border") + fgsym = symbol("foreground_color_" * fgtype) + if d[fgsym] == :match + d[fgsym] = d[:foreground_color] + end + end + - # bgcolor - d[:background_color] = colorscheme(bgcolor) - d[:foreground_color] = colorscheme(fgcolor) end # converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically diff --git a/src/utils.jl b/src/utils.jl index f5766635..30f6106d 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -22,7 +22,7 @@ function histogramHack(; kw...) d = KW(kw) # we assume that the y kwarg is set with the data to be binned, and nbins is also defined - edges, midpoints, buckets, counts = binData(d[:y], d[:nbins]) + edges, midpoints, buckets, counts = binData(d[:y], d[:bins]) d[:x] = midpoints d[:y] = float(counts) d[:linetype] = :bar