subcategories for background/foreground colors, implemented in pyplot; add_theme/set_theme and ggplot2; add_aliases function; nbins renamed bins

This commit is contained in:
Thomas Breloff 2016-04-25 11:37:14 -04:00
parent 40a121198d
commit 77c2d7d846
11 changed files with 400 additions and 197 deletions

View File

@ -20,6 +20,8 @@ export
AVec, AVec,
AMat, AMat,
KW, KW,
set_theme,
add_theme,
plot, plot,
plot!, plot!,

View File

@ -120,14 +120,10 @@ _seriesDefaults[:linestyle] = :solid
_seriesDefaults[:linewidth] = 1 _seriesDefaults[:linewidth] = 1
_seriesDefaults[:linecolor] = :match _seriesDefaults[:linecolor] = :match
_seriesDefaults[:linealpha] = nothing _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[:fillrange] = nothing # ribbons, areas, etc
_seriesDefaults[:fillcolor] = :match _seriesDefaults[:fillcolor] = :match
_seriesDefaults[:fillalpha] = nothing _seriesDefaults[:fillalpha] = nothing
_seriesDefaults[:markershape] = :none _seriesDefaults[:markershape] = :none
# _seriesDefaults[:markerstroke] = Stroke(1, :match_foreground, nothing, :solid)
# _seriesDefaults[:markerbrush] = Brush(6, :match, nothing)
_seriesDefaults[:markercolor] = :match _seriesDefaults[:markercolor] = :match
_seriesDefaults[:markeralpha] = nothing _seriesDefaults[:markeralpha] = nothing
_seriesDefaults[:markersize] = 6 _seriesDefaults[:markersize] = 6
@ -135,18 +131,13 @@ _seriesDefaults[:markerstrokestyle] = :solid
_seriesDefaults[:markerstrokewidth] = 1 _seriesDefaults[:markerstrokewidth] = 1
_seriesDefaults[:markerstrokecolor] = :match _seriesDefaults[:markerstrokecolor] = :match
_seriesDefaults[:markerstrokealpha] = nothing _seriesDefaults[:markerstrokealpha] = nothing
# _seriesDefaults[:ribbon] = nothing _seriesDefaults[:bins] = 30 # number of bins for hists
# _seriesDefaults[:ribboncolor] = :match
_seriesDefaults[:nbins] = 30 # number of bins for hists
_seriesDefaults[:smooth] = false # regression line? _seriesDefaults[:smooth] = false # regression line?
_seriesDefaults[:group] = nothing # groupby vector _seriesDefaults[:group] = nothing # groupby vector
# _seriesDefaults[:annotation] = nothing # annotation tuple(s)... (x,y,annotation)
_seriesDefaults[:x] = nothing _seriesDefaults[:x] = nothing
_seriesDefaults[:y] = nothing _seriesDefaults[:y] = nothing
_seriesDefaults[:z] = nothing # depth for contour, surface, etc _seriesDefaults[:z] = nothing # depth for contour, surface, etc
_seriesDefaults[:marker_z] = nothing # value for color scale _seriesDefaults[:marker_z] = nothing # value for color scale
# _seriesDefaults[:surface] = nothing
# _seriesDefaults[:nlevels] = 15
_seriesDefaults[:levels] = 15 _seriesDefaults[:levels] = 15
_seriesDefaults[:orientation] = :vertical _seriesDefaults[:orientation] = :vertical
_seriesDefaults[:bar_position] = :overlay # for bar plots and histograms: could also be stack (stack up) or dodge (side by side) _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[:yrightlabel] = ""
_plotDefaults[:legend] = :best _plotDefaults[:legend] = :best
_plotDefaults[:colorbar] = :legend _plotDefaults[:colorbar] = :legend
_plotDefaults[:background_color] = colorant"white" _plotDefaults[:background_color] = colorant"white" # default for all backgrounds
_plotDefaults[:foreground_color] = :auto _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[:xlims] = :auto
_plotDefaults[:ylims] = :auto _plotDefaults[:ylims] = :auto
_plotDefaults[:zlims] = :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 # Alternate args
@compat const _keyAliases = KW( # @compat const _keyAliases = KW(
:c => :seriescolor, # :c => :seriescolor,
:color => :seriescolor, # :color => :seriescolor,
:colour => :seriescolor, # :colour => :seriescolor,
:alpha => :seriesalpha, # :alpha => :seriesalpha,
:α => :seriesalpha, # :α => :seriesalpha,
:opacity => :seriesalpha, # :opacity => :seriesalpha,
:lc => :linecolor, # :lc => :linecolor,
:lcolor => :linecolor, # :lcolor => :linecolor,
:lcolour => :linecolor, # :lcolour => :linecolor,
:lab => :label, # :lab => :label,
:l => :line, # :l => :line,
:w => :linewidth, # :w => :linewidth,
:width => :linewidth, # :width => :linewidth,
:lw => :linewidth, # :lw => :linewidth,
:la => :linealpha, # :la => :linealpha,
:lalpha => :linealpha, # :lalpha => :linealpha,
:lineopacity => :linealpha, # :lineopacity => :linealpha,
:type => :linetype, # :type => :linetype,
:lt => :linetype, # :lt => :linetype,
:t => :linetype, # :t => :linetype,
:seriestype => :linetype, # :seriestype => :linetype,
:style => :linestyle, # :style => :linestyle,
:s => :linestyle, # :s => :linestyle,
:ls => :linestyle, # :ls => :linestyle,
:m => :marker, # :m => :marker,
:mark => :marker, # :mark => :marker,
:shape => :markershape, # :shape => :markershape,
:mc => :markercolor, # :mc => :markercolor,
:mcolor => :markercolor, # :mcolor => :markercolor,
:markercolour => :markercolor, # :markercolour => :markercolor,
:ms => :markersize, # :ms => :markersize,
:msize => :markersize, # :msize => :markersize,
:ma => :markeralpha, # :ma => :markeralpha,
:malpha => :markeralpha, # :malpha => :markeralpha,
:mopacity => :markeralpha, # :mopacity => :markeralpha,
:markeropacity => :markeralpha, # :markeropacity => :markeralpha,
:zcolor => :marker_z, # :zcolor => :marker_z,
:f => :fill, # :f => :fill,
:area => :fill, # :area => :fill,
:fillrng => :fillrange, # :fillrng => :fillrange,
:fc => :fillcolor, # :fc => :fillcolor,
:fcolor => :fillcolor, # :fcolor => :fillcolor,
:fillcolour => :fillcolor, # :fillcolour => :fillcolor,
:fa => :fillalpha, # :fa => :fillalpha,
:falpha => :fillalpha, # :falpha => :fillalpha,
:fillopacity => :fillalpha, # :fillopacity => :fillalpha,
:g => :group, # :g => :group,
:nb => :nbins, # :nb => :nbins,
:nbin => :nbins, # :nbin => :nbins,
:rib => :ribbon, # :rib => :ribbon,
:ann => :annotation, # :ann => :annotation,
:anns => :annotation, # :anns => :annotation,
:annotate => :annotation, # :annotate => :annotation,
:annotations => :annotation, # :annotations => :annotation,
:xlab => :xlabel, # :xlab => :xlabel,
:ylab => :ylabel, # :ylab => :ylabel,
:zlab => :zlabel, # :zlab => :zlabel,
:yrlab => :yrightlabel, # :yrlab => :yrightlabel,
:ylabr => :yrightlabel, # :ylabr => :yrightlabel,
:y2lab => :yrightlabel, # :y2lab => :yrightlabel,
:ylab2 => :yrightlabel, # :ylab2 => :yrightlabel,
:ylabelright => :yrightlabel, # :ylabelright => :yrightlabel,
:ylabel2 => :yrightlabel, # :ylabel2 => :yrightlabel,
:y2label => :yrightlabel, # :y2label => :yrightlabel,
:leg => :legend, # :leg => :legend,
:key => :legend, # :key => :legend,
:cbar => :colorbar, # :cbar => :colorbar,
:cb => :colorbar, # :cb => :colorbar,
:bg => :background_color, # :bg => :background_color,
:bgcolor => :background_color, # :bgcolor => :background_color,
:bg_color => :background_color, # :bg_color => :background_color,
:background => :background_color, # :background => :background_color,
:background_colour => :background_color, # :background_colour => :background_color,
:fg => :foreground_color, # :fg => :foreground_color,
:fgcolor => :foreground_color, # :fgcolor => :foreground_color,
:fg_color => :foreground_color, # :fg_color => :foreground_color,
:foreground => :foreground_color, # :foreground => :foreground_color,
:foreground_colour => :foreground_color, # :foreground_colour => :foreground_color,
:regression => :smooth, # :bglegend => :background_color_legend,
:reg => :smooth, # :bg_legend => :background_color_legend,
:nlevels => :levels, # :bgcolor_legend => :background_color_legend,
:nlev => :levels, # :background_legend => :background_color_legend,
:levs => :levels, # :bglegend => :background_color_legend,
:xlim => :xlims, # :regression => :smooth,
:xlimit => :xlims, # :reg => :smooth,
:xlimits => :xlims, # :nlevels => :levels,
:ylim => :ylims, # :nlev => :levels,
:ylimit => :ylims, # :levs => :levels,
:ylimits => :ylims, # :xlim => :xlims,
:zlim => :zlims, # :xlimit => :xlims,
:zlimit => :zlims, # :xlimits => :xlims,
:zlimits => :zlims, # :ylim => :ylims,
:xtick => :xticks, # :ylimit => :ylims,
:ytick => :yticks, # :ylimits => :ylims,
:windowsize => :size, # :zlim => :zlims,
:wsize => :size, # :zlimit => :zlims,
:wtitle => :windowtitle, # :zlimits => :zlims,
:gui => :show, # :xtick => :xticks,
:display => :show, # :ytick => :yticks,
:palette => :color_palette, # :windowsize => :size,
:xlink => :linkx, # :wsize => :size,
:ylink => :linky, # :wtitle => :windowtitle,
:nrow => :nr, # :gui => :show,
:nrows => :nr, # :display => :show,
:ncol => :nc, # :palette => :color_palette,
:ncols => :nc, # :xlink => :linkx,
:clf => :overwrite_figure, # :ylink => :linky,
:clearfig => :overwrite_figure, # :nrow => :nr,
:overwrite => :overwrite_figure, # :nrows => :nr,
:reuse => :overwrite_figure, # :ncol => :nc,
:err => :yerror, # :ncols => :nc,
:errorbar => :yerror, # :clf => :overwrite_figure,
:xerr => :xerror, # :clearfig => :overwrite_figure,
:xerrorbar => :xerror, # :overwrite => :overwrite_figure,
:yerr => :yerror, # # :reuse => :overwrite_figure,
:yerrorbar => :yerror, # :err => :yerror,
:velocity => :quiver, # :errorbar => :yerror,
:quiver2d => :quiver, # :xerr => :xerror,
:gradient => :quiver, # :xerrorbar => :xerror,
:norm => :normalize, # :yerr => :yerror,
:normed => :normalize, # :yerrorbar => :yerror,
:normalized => :normalize, # :velocity => :quiver,
) # :quiver2d => :quiver,
# :gradient => :quiver,
# :norm => :normalize,
# :normed => :normalize,
# :normalized => :normalize,
# )
# add all pluralized forms to the _keyAliases dict # add all pluralized forms to the _keyAliases dict
for arg in keys(_seriesDefaults) 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 # if arg is a valid color value, then set d[csym] and return true
function handleColors!(d::KW, arg, csym::Symbol) function handleColors!(d::KW, arg, csym::Symbol)
try try

View File

@ -33,7 +33,7 @@ end
function getLineGeom(d::KW) function getLineGeom(d::KW)
lt = d[:linetype] lt = d[:linetype]
xbins, ybins = maketuple(d[:nbins]) xbins, ybins = maketuple(d[:bins])
if lt == :hexb if lt == :hexb
Gadfly.Geom.hexbin(xbincount = xbins, ybincount = ybins) Gadfly.Geom.hexbin(xbincount = xbins, ybincount = ybins)
elseif lt == :hist2d elseif lt == :hist2d

View File

@ -165,10 +165,10 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
E = zeros(length(p[:x]),2) E = zeros(length(p[:x]),2)
E[:,1] = p[:x] E[:,1] = p[:x]
E[:,2] = p[:y] E[:,2] = p[:y]
if isa(p[:nbins], Tuple) if isa(p[:bins], Tuple)
xbins, ybins = p[:nbins] xbins, ybins = p[:bins]
else else
xbins = ybins = p[:nbins] xbins = ybins = p[:bins]
end end
cmap = true cmap = true
x, y, H = Base.hist2d(E, xbins, ybins) 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 = zeros(length(p[:x]),2)
E[:,1] = p[:x] E[:,1] = p[:x]
E[:,2] = p[:y] E[:,2] = p[:y]
if isa(p[:nbins], Tuple) if isa(p[:bins], Tuple)
xbins, ybins = p[:nbins] xbins, ybins = p[:bins]
else else
xbins = ybins = p[:nbins] xbins = ybins = p[:bins]
end end
x, y, H = Base.hist2d(E, xbins, ybins) x, y, H = Base.hist2d(E, xbins, ybins)
counts = round(Int32, 1000 + 255 * H / maximum(H)) counts = round(Int32, 1000 + 255 * H / maximum(H))

View File

@ -308,10 +308,10 @@ function plotly_series(d::KW, plotargs::KW; plot_index = nothing)
elseif lt == :hist2d elseif lt == :hist2d
d_out[:type] = "histogram2d" d_out[:type] = "histogram2d"
d_out[:x], d_out[:y] = x, y d_out[:x], d_out[:y] = x, y
if isa(d[:nbins], Tuple) if isa(d[:bins], Tuple)
xbins, ybins = d[:nbins] xbins, ybins = d[:bins]
else else
xbins = ybins = d[:nbins] xbins = ybins = d[:bins]
end end
d_out[:nbinsx] = xbins d_out[:nbinsx] = xbins
d_out[:nbinsy] = ybins d_out[:nbinsy] = ybins
@ -320,7 +320,7 @@ function plotly_series(d::KW, plotargs::KW; plot_index = nothing)
d_out[:type] = "histogram" d_out[:type] = "histogram"
isvert = isvertical(d) isvert = isvertical(d)
d_out[isvert ? :x : :y] = y d_out[isvert ? :x : :y] = y
d_out[isvert ? :nbinsx : :nbinsy] = d[:nbins] d_out[isvert ? :nbinsx : :nbinsy] = d[:bins]
if lt == :density if lt == :density
d_out[:histnorm] = "probability density" d_out[:histnorm] = "probability density"
end end

View File

@ -223,7 +223,8 @@ end
function pyplot_figure(plotargs::KW) function pyplot_figure(plotargs::KW)
w,h = map(px2inch, plotargs[:size]) w,h = map(px2inch, plotargs[:size])
bgcolor = getPyPlotColor(plotargs[:background_color]) # bgcolor = getPyPlotColor(plotargs[:background_color])
# reuse the current figure? # reuse the current figure?
fig = if plotargs[:overwrite_figure] fig = if plotargs[:overwrite_figure]
@ -235,7 +236,8 @@ function pyplot_figure(plotargs::KW)
# update the specs # update the specs
# fig[:set_size_inches](w,h, (isijulia() ? [] : [true])...) # fig[:set_size_inches](w,h, (isijulia() ? [] : [true])...)
fig[:set_size_inches](w, h, forward = 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_dpi](DPI)
fig[:set_tight_layout](true) fig[:set_tight_layout](true)
@ -451,7 +453,7 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
color = pyfillcolor(d), color = pyfillcolor(d),
edgecolor = pylinecolor(d), edgecolor = pylinecolor(d),
linewidth = d[:linewidth], linewidth = d[:linewidth],
bins = d[:nbins], bins = d[:bins],
normed = d[:normalize], normed = d[:normalize],
weights = d[:weights], weights = d[:weights],
orientation = (isvertical(d) ? "vertical" : "horizontal"), orientation = (isvertical(d) ? "vertical" : "horizontal"),
@ -465,7 +467,7 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
handle = ax[:hist2d](x, y; handle = ax[:hist2d](x, y;
label = d[:label], label = d[:label],
zorder = plt.n + 0.5, zorder = plt.n + 0.5,
bins = d[:nbins], bins = d[:bins],
normed = d[:normalize], normed = d[:normalize],
weights = d[:weights], weights = d[:weights],
cmap = pyfillcolormap(d) # applies to the pcolorfast object 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; handle = ax[:hexbin](x, y;
label = d[:label], label = d[:label],
zorder = plt.n + 0.5, zorder = plt.n + 0.5,
gridsize = d[:nbins], gridsize = d[:bins],
linewidths = d[:linewidth], linewidths = d[:linewidth],
edgecolors = pylinecolor(d), edgecolors = pylinecolor(d),
cmap = pyfillcolormap(d) # applies to the pcolorfast object cmap = pyfillcolormap(d) # applies to the pcolorfast object
@ -498,7 +500,8 @@ function _add_series(pkg::PyPlotBackend, plt::Plot, d::KW)
end end
# this sets the bg color inside the grid # 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 # handle area filling
fillrange = d[:fillrange] fillrange = d[:fillrange]
@ -571,7 +574,7 @@ function _add_series2(pkg::PyPlotBackend, plt::Plot, d::KW)
# extra_kwargs[:bottom] = d[:fill] # extra_kwargs[:bottom] = d[:fill]
if like_histogram(lt) if like_histogram(lt)
extra_kwargs[:bins] = d[:nbins] extra_kwargs[:bins] = d[:bins]
extra_kwargs[:normed] = lt == :density extra_kwargs[:normed] = lt == :density
extra_kwargs[:orientation] = isvertical(d) ? "vertical" : "horizontal" extra_kwargs[:orientation] = isvertical(d) ? "vertical" : "horizontal"
extra_kwargs[:histtype] = d[:bar_position] == :stack ? "barstacked" : "bar" extra_kwargs[:histtype] = d[:bar_position] == :stack ? "barstacked" : "bar"
@ -580,7 +583,7 @@ function _add_series2(pkg::PyPlotBackend, plt::Plot, d::KW)
end end
elseif lt in (:hist2d, :hexbin) elseif lt in (:hist2d, :hexbin)
extra_kwargs[:gridsize] = d[:nbins] extra_kwargs[:gridsize] = d[:bins]
extra_kwargs[:cmap] = linecmap extra_kwargs[:cmap] = linecmap
elseif lt == :contour elseif lt == :contour
@ -858,18 +861,21 @@ function applyPyPlotScale(ax, scaleType::Symbol, letter)
end end
function updateAxisColors(ax, fgcolor) function updateAxisColors(ax, d::KW)
guidecolor = getPyPlotColor(d[:guidefont].color)
for (loc, spine) in ax[:spines] for (loc, spine) in ax[:spines]
spine[:set_color](fgcolor) spine[:set_color](getPyPlotColor(d[:foreground_color_border]))
end end
for letter in ("x", "y", "z") for letter in ("x", "y", "z")
axis = axis_symbol(letter, "axis") axis = axis_symbol(letter, "axis")
if haskey(ax, axis) if haskey(ax, axis)
ax[:tick_params](axis=letter, colors=fgcolor, which="both") ax[:tick_params](axis=letter, which="both",
ax[axis][:label][:set_color](fgcolor) colors=getPyPlotColor(d[:foreground_color_axis]),
labelcolor=getPyPlotColor(d[:foreground_color_text]))
ax[axis][:label][:set_color](guidecolor)
end end
end end
ax[:title][:set_color](fgcolor) ax[:title][:set_color](guidecolor)
end end
function usingRightAxis(plt::Plot{PyPlotBackend}) function usingRightAxis(plt::Plot{PyPlotBackend})
@ -917,7 +923,8 @@ function _update_plot(plt::Plot{PyPlotBackend}, d::KW)
lab[:set_fontsize](ticksz) lab[:set_fontsize](ticksz)
end end
if get(d, :grid, false) 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[axis][:grid](true, color = fgcolor)
tmpax[:set_axisbelow](true) tmpax[:set_axisbelow](true)
end end
@ -1038,10 +1045,16 @@ function addPyPlotLegend(plt::Plot, ax)
leg = ax[:legend]([d[:serieshandle][1] for d in args], leg = ax[:legend]([d[:serieshandle][1] for d in args],
[d[:label] for d in args], [d[:label] for d in args],
loc = get(_pyplot_legend_pos, leg, "best"), loc = get(_pyplot_legend_pos, leg, "best"),
scatterpoints = 1,
fontsize = plt.plotargs[:legendfont].pointsize fontsize = plt.plotargs[:legendfont].pointsize
# framealpha = 0.6 # framealpha = 0.6
) )
leg[:set_zorder](1000) 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 end
end end
@ -1051,7 +1064,9 @@ end
function finalizePlot(plt::Plot{PyPlotBackend}) function finalizePlot(plt::Plot{PyPlotBackend})
ax = getLeftAxis(plt) ax = getLeftAxis(plt)
addPyPlotLegend(plt, ax) 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() PyPlot.draw()
end end
@ -1060,7 +1075,9 @@ function finalizePlot(subplt::Subplot{PyPlotBackend})
for (i,plt) in enumerate(subplt.plts) for (i,plt) in enumerate(subplt.plts)
ax = getLeftAxis(plt) ax = getLeftAxis(plt)
addPyPlotLegend(plt, ax) 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 end
# fig[:tight_layout]() # fig[:tight_layout]()
PyPlot.draw() PyPlot.draw()

View File

@ -12,7 +12,7 @@ end
# ------------------------------- # -------------------------------
@compat const _qwtAliases = KW( @compat const _qwtAliases = KW(
:nbins => :heatmap_n, :bins => :heatmap_n,
:fillrange => :fillto, :fillrange => :fillto,
:linewidth => :width, :linewidth => :width,
:markershape => :marker, :markershape => :marker,

View File

@ -30,7 +30,7 @@ supportedArgs(::GadflyBackend) = [
:markershape, :markercolor, :markersize, :markeralpha, :markershape, :markercolor, :markersize, :markeralpha,
:markerstrokewidth, :markerstrokecolor, :markerstrokealpha, :markerstrokewidth, :markerstrokecolor, :markerstrokealpha,
:fillrange, :fillcolor, :fillalpha, :fillrange, :fillcolor, :fillalpha,
:nbins, :bins,
:n, :nc, :nr, :layout, :n, :nc, :nr, :layout,
:smooth, :smooth,
:title, :windowtitle, :show, :size, :title, :windowtitle, :show, :size,
@ -76,6 +76,9 @@ subplotSupported(::ImmerseBackend) = true
supportedArgs(::PyPlotBackend) = [ supportedArgs(::PyPlotBackend) = [
:annotation, :annotation,
:background_color, :foreground_color, :color_palette, :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, :group,
:label, :label,
:linetype, :linetype,
@ -84,7 +87,7 @@ supportedArgs(::PyPlotBackend) = [
:markershape, :markercolor, :markersize, :markeralpha, :markershape, :markercolor, :markersize, :markeralpha,
:markerstrokewidth, :markerstrokecolor, :markerstrokealpha, :markerstrokewidth, :markerstrokecolor, :markerstrokealpha,
:fillrange, :fillcolor, :fillalpha, :fillrange, :fillcolor, :fillalpha,
:nbins, :bins,
:n, :nc, :nr, :layout, :n, :nc, :nr, :layout,
:smooth, :smooth,
:title, :windowtitle, :show, :size, :title, :windowtitle, :show, :size,
@ -146,7 +149,7 @@ supportedArgs(::GRBackend) = [
:markerstrokecolor, :markerstrokecolor,
# :markerstrokestyle, # :markerstrokestyle,
:n, :n,
:nbins, :bins,
:nc, :nc,
:nr, :nr,
# :pos, # :pos,
@ -228,7 +231,7 @@ supportedArgs(::QwtBackend) = [
# :markerstrokecolor, # :markerstrokecolor,
# :markerstrokestyle, # :markerstrokestyle,
:n, :n,
:nbins, :bins,
:nc, :nc,
:nr, :nr,
:pos, :pos,
@ -287,7 +290,7 @@ supportedArgs(::UnicodePlotsBackend) = [
# :markerstrokecolor, # :markerstrokecolor,
# :markerstrokestyle, # :markerstrokestyle,
# :n, # :n,
:nbins, :bins,
# :nc, # :nc,
# :nr, # :nr,
# :pos, # :pos,
@ -352,7 +355,7 @@ supportedArgs(::WinstonBackend) = [
# :markerstrokecolor, # :markerstrokecolor,
# :markerstrokestyle, # :markerstrokestyle,
# :n, # :n,
:nbins, :bins,
# :nc, # :nc,
# :nr, # :nr,
# :pos, # :pos,
@ -416,7 +419,7 @@ supportedArgs(::BokehBackend) = [
# :markerstrokecolor, # :markerstrokecolor,
# :markerstrokestyle, # :markerstrokestyle,
# :n, # :n,
# :nbins, # :bins,
# :nc, # :nc,
# :nr, # :nr,
# :pos, # :pos,
@ -483,7 +486,7 @@ supportedArgs(::PlotlyBackend) = [
:markerstrokecolor, :markerstrokecolor,
:markerstrokestyle, :markerstrokestyle,
:n, :n,
:nbins, :bins,
:nc, :nc,
:nr, :nr,
# :pos, # :pos,
@ -560,7 +563,7 @@ supportedArgs(::PlotlyJSBackend) = [
:markerstrokecolor, :markerstrokecolor,
:markerstrokestyle, :markerstrokestyle,
:n, :n,
:nbins, :bins,
:nc, :nc,
:nr, :nr,
# :pos, # :pos,
@ -636,7 +639,7 @@ supportedArgs(::GLVisualizeBackend) = [
# :markerstrokecolor, # :markerstrokecolor,
# :markerstrokestyle, # :markerstrokestyle,
# :n, # :n,
# :nbins, # :bins,
# :nc, # :nc,
# :nr, # :nr,
# :pos, # :pos,
@ -702,7 +705,7 @@ supportedArgs(::PGFPlotsBackend) = [
# :markerstrokecolor, # :markerstrokecolor,
# :markerstrokestyle, # :markerstrokestyle,
# :n, # :n,
# :nbins, # :bins,
# :nc, # :nc,
# :nr, # :nr,
# :pos, # :pos,

View File

@ -127,8 +127,8 @@ function _add_series(::WinstonBackend, plt::Plot, d::KW)
# fn = Winston.XXX # fn = Winston.XXX
elseif d[:linetype] == :hist elseif d[:linetype] == :hist
hst = hist(d[:y], d[:nbins]) hst = hist(d[:y], d[:bins])
Winston.add(wplt, Winston.Histogram(hst...; copy_remove(e, :nbins)...)) Winston.add(wplt, Winston.Histogram(hst...; copy_remove(e, :bins)...))
# elseif d[:linetype] == :bar # elseif d[:linetype] == :bar
# # fn = Winston.XXX # # fn = Winston.XXX

View File

@ -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? # TODO: allow the setting of the algorithm, either by passing a symbol (:colordiff, :fixed, etc) or a function?
function handlePlotColors(::AbstractBackend, d::KW) function handlePlotColors(::AbstractBackend, d::KW)
if :background_color in supportedArgs() if :background_color in supportedArgs()
bgcolor = convertColor(d[:background_color]) bgcolor = convertColor(d[:background_color])
else else
bgcolor = _plotDefaults[:background_color] bgcolor = _plotDefaults[:background_color]
if d[:background_color] != _plotDefaults[:background_color] if d[:background_color] != _plotDefaults[:background_color]
warn("Cannot set background_color with backend $(backend())") warn("Cannot set background_color with backend $(backend())")
end
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 # set the foreground color (text, ticks, gridlines) to be white or black depending
# on how dark the background is. # on how dark the background is.
fgcolor = get(d, :foreground_color, :auto) fgcolor = get(d, :foreground_color, :auto)
fgcolor = if fgcolor == :auto fgcolor = if fgcolor == :auto
isdark(bgcolor) ? colorant"white" : colorant"black" isdark(bgcolor) ? colorant"white" : colorant"black"
else else
convertColor(fgcolor) convertColor(fgcolor)
end 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 end
# converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically # converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically

View File

@ -22,7 +22,7 @@ function histogramHack(; kw...)
d = KW(kw) d = KW(kw)
# we assume that the y kwarg is set with the data to be binned, and nbins is also defined # 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[:x] = midpoints
d[:y] = float(counts) d[:y] = float(counts)
d[:linetype] = :bar d[:linetype] = :bar