palette fixes and working on imgcmp

This commit is contained in:
Thomas Breloff 2015-10-24 15:09:13 -04:00
parent f28e65a26c
commit 7e740861d8
4 changed files with 12868 additions and 767 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,125 +1,20 @@
# https://github.com/dcjones/Gadfly.jl # https://github.com/dcjones/Gadfly.jl
# immutable GadflyPackage <: PlottingPackage end
# export gadfly
# gadfly() = backend(:gadfly)
# # supportedArgs(::GadflyPackage) = setdiff(_allArgs, [:heatmap_c, :pos, :screen, :yrightlabel])
# supportedArgs(::GadflyPackage) = [
# :annotation,
# # :axis,
# :background_color,
# :color,
# :color_palette,
# :fillrange,
# :fillcolor,
# :fillopacity,
# :foreground_color,
# :group,
# :label,
# :layout,
# :legend,
# :linestyle,
# :linetype,
# :linewidth,
# :lineopacity,
# :markershape,
# :markercolor,
# :markersize,
# :markeropacity,
# :n,
# :nbins,
# :nc,
# :nr,
# # :pos,
# :smooth,
# :show,
# :size,
# :title,
# :windowtitle,
# :x,
# :xlabel,
# :xlims,
# :xticks,
# :y,
# :ylabel,
# :ylims,
# # :yrightlabel,
# :yticks,
# :xscale,
# :yscale,
# :xflip,
# :yflip,
# :z,
# :tickfont,
# :guidefont,
# :legendfont,
# :grid,
# ]
# supportedAxes(::GadflyPackage) = [:auto, :left]
# supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
# supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
# supportedMarkers(::GadflyPackage) = vcat(_allMarkers, Shape)
# supportedScales(::GadflyPackage) = [:identity, :log, :log2, :log10, :asinh, :sqrt]
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
function createGadflyPlotObject(d::Dict) function createGadflyPlotObject(d::Dict)
# @eval import DataFrames
gplt = Gadfly.Plot() gplt = Gadfly.Plot()
gplt.mapping = Dict() gplt.mapping = Dict()
gplt.data_source = DataFrames.DataFrame() gplt.data_source = DataFrames.DataFrame()
gplt.layers = gplt.layers[1:0] gplt.layers = gplt.layers[1:0]
# add the title, axis labels, and theme
gplt.guides = Gadfly.GuideElement[Gadfly.Guide.xlabel(d[:xlabel]), gplt.guides = Gadfly.GuideElement[Gadfly.Guide.xlabel(d[:xlabel]),
Gadfly.Guide.ylabel(d[:ylabel]), Gadfly.Guide.ylabel(d[:ylabel]),
Gadfly.Guide.title(d[:title])] Gadfly.Guide.title(d[:title])]
# kwargs = Dict()
# # hide the legend?
# if !get(d, :legend, true)
# kwargs[:key_position] = :none
# end
# if !get(d, :grid, true)
# kwargs[:grid_color] = getColor(d[:background_color])
# end
# # fonts
# tfont, gfont, lfont = d[:tickfont], d[:guidefont], d[:legendfont]
# fg = getColor(d[:foreground_color])
# gplt.theme = Gadfly.Theme(;
# background_color = getColor(d[:background_color]),
# minor_label_color = fg,
# minor_label_font = tfont.family,
# minor_label_font_size = tfont.pointsize * Gadfly.pt,
# major_label_color = fg,
# major_label_font = gfont.family,
# major_label_font_size = gfont.pointsize * Gadfly.pt,
# key_title_color = fg,
# key_title_font = gfont.family,
# key_title_font_size = gfont.pointsize * Gadfly.pt,
# key_label_color = fg,
# key_label_font = lfont.family,
# key_label_font_size = lfont.pointsize * Gadfly.pt,
# plot_padding = 1 * Gadfly.mm,
# kwargs...
# )
gplt gplt
end end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@ -204,7 +99,6 @@ function addGadflyLine!(plt::Plot, d::Dict, geoms...)
# add the layer # add the layer
x = d[d[:linetype] == :hist ? :y : :x] x = d[d[:linetype] == :hist ? :y : :x]
Gadfly.layer(gfargs...; x = x, y = d[:y], kwargs...) Gadfly.layer(gfargs...; x = x, y = d[:y], kwargs...)
# prepend!(gplt.layers, )
end end
@ -228,7 +122,6 @@ function getGadflyMarkerTheme(d::Dict, initargs::Dict)
Gadfly.Theme( Gadfly.Theme(
default_color = c, default_color = c,
default_point_size = d[:markersize] * Gadfly.px, default_point_size = d[:markersize] * Gadfly.px,
# highlight_color = getColor(initargs[:foreground_color]),
discrete_highlight_color = c -> fg, discrete_highlight_color = c -> fg,
highlight_width = d[:linewidth] * Gadfly.px, highlight_width = d[:linewidth] * Gadfly.px,
) )
@ -251,7 +144,6 @@ function addGadflyMarker!(plt::Plot, d::Dict, initargs::Dict, geoms...)
end end
Gadfly.layer(gfargs...; x = d[:x], y = d[:y], kwargs...) Gadfly.layer(gfargs...; x = d[:x], y = d[:y], kwargs...)
# prepend!(gplt.layers, )
end end
@ -308,7 +200,6 @@ function addGadflySeries!(plt::Plot, d::Dict)
# add a regression line? # add a regression line?
# TODO: make more flexible # TODO: make more flexible
# smooth = d[:smooth] ? [Gadfly.Geom.smooth(method=:lm)] : Any[]
smooth = getGadflySmoothing(d[:smooth]) smooth = getGadflySmoothing(d[:smooth])
# lines # lines
@ -680,7 +571,6 @@ setGadflyDisplaySize(subplt::Subplot) = setGadflyDisplaySize(getinitargs(subplt,
function dowritemime{P<:GadflyOrImmerse}(io::IO, func, plt::PlottingObject{P}) function dowritemime{P<:GadflyOrImmerse}(io::IO, func, plt::PlottingObject{P})
gplt = getGadflyContext(plt) gplt = getGadflyContext(plt)
# setGadflyDisplaySize(plt.initargs[:size]...)
setGadflyDisplaySize(plt) setGadflyDisplaySize(plt)
Gadfly.draw(func(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt) Gadfly.draw(func(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end end

View File

@ -211,40 +211,41 @@ end
# -------------------------------------------------------------- # --------------------------------------------------------------
# Methods to automatically generate gradients for color selection based on # # Methods to automatically generate gradients for color selection based on
# background color and a short list of seed colors # # background color and a short list of seed colors
function adjust_lch(color, l, c) # function adjust_lch(color, l, c)
lch = LCHab(color) # lch = LCHab(color)
convert(RGB, LCHab(l, c, lch.h)) # convert(RGB, LCHab(l, c, lch.h))
end # end
function lightness_from_background(bgcolor) # function lightness_from_background(bgcolor)
bglight = LCHab(bgcolor).l # bglight = LCHab(bgcolor).l
0.45bglight + 55.0 * (bglight < 50.0) # 0.5bglight + 0.5 * 100.0 * (bglight < 50.0)
end # end
function gradient_from_list(cs) # function gradient_from_list(cs)
zvalues = Plots.get_zvalues(length(cs)) # zvalues = Plots.get_zvalues(length(cs))
indices = sortperm(zvalues) # indices = sortperm(zvalues)
sorted_colors = map(RGB, cs[indices]) # sorted_colors = map(RGB, cs[indices])
sorted_zvalues = zvalues[indices] # sorted_zvalues = zvalues[indices]
ColorGradient(sorted_colors, sorted_zvalues) # ColorGradient(sorted_colors, sorted_zvalues)
end # end
function generate_colorgradient(bgcolor = colorant"white"; # function generate_colorgradient(bgcolor = colorant"white";
color_bases = [colorant"steelblue", colorant"indianred"], # color_bases = [colorant"steelblue", colorant"indianred"],
lightness = lightness_from_background(bgcolor), # lightness = lightness_from_background(bgcolor),
n = 9) # chroma = 50,
seed_colors = map(c -> adjust_lch(c,lightness,50), vcat(bgcolor, color_bases)) # n = 9)
colors = distinguishable_colors(n, # seed_colors = map(c -> adjust_lch(c,lightness,chroma), vcat(bgcolor, color_bases))
seed_colors, # colors = distinguishable_colors(n,
lchoices=Float64[lightness], # seed_colors,
cchoices=Float64[50], # lchoices=Float64[lightness],
hchoices=linspace(0, 340, 20) # cchoices=Float64[chroma],
)[2:end] # hchoices=linspace(0, 340, 20)
gradient_from_list(colors) # )[2:end]
end # gradient_from_list(colors)
# end
# -------------------------------------------------------------- # --------------------------------------------------------------
@ -355,8 +356,9 @@ const _defaultNumColors = 17
# background color and a short list of seed colors # background color and a short list of seed colors
# here are some magic constants that could be changed if you really want # here are some magic constants that could be changed if you really want
const _bgratio = [0.4] const _lightness_darkbg = [80.0]
const _lch_c_const = [50] const _lightness_lightbg = [60.0]
const _lch_c_const = [60]
function adjust_lch(color, l, c) function adjust_lch(color, l, c)
lch = LCHab(color) lch = LCHab(color)
@ -365,7 +367,8 @@ end
function lightness_from_background(bgcolor) function lightness_from_background(bgcolor)
bglight = LCHab(bgcolor).l bglight = LCHab(bgcolor).l
_bgratio[1] * bglight + 100.0 * (1 - _bgratio[1]) * (bglight < 50.0) # _bgratio[1] * bglight + 100.0 * (1 - _bgratio[1]) * (bglight < 50.0)
bglight < 50.0 ? _lightness_darkbg[1] : _lightness_lightbg[1]
end end
function gradient_from_list(cs) function gradient_from_list(cs)
@ -377,14 +380,15 @@ function gradient_from_list(cs)
end end
function generate_colorgradient(bgcolor = colorant"white"; function generate_colorgradient(bgcolor = colorant"white";
color_bases = [colorant"steelblue", colorant"indianred"], color_bases = color_bases=[colorant"steelblue",colorant"orangered"],
lightness = lightness_from_background(bgcolor), lightness = lightness_from_background(bgcolor),
chroma = _lch_c_const[1],
n = _defaultNumColors) n = _defaultNumColors)
seed_colors = map(c -> adjust_lch(c,lightness, _lch_c_const[1]), vcat(bgcolor, color_bases)) seed_colors = vcat(bgcolor, map(c -> adjust_lch(c, lightness, chroma), color_bases))
colors = distinguishable_colors(n, colors = distinguishable_colors(n,
seed_colors, seed_colors,
lchoices=Float64[lightness], lchoices=Float64[lightness],
cchoices=Float64[_lch_c_const[1]], cchoices=Float64[chroma],
hchoices=linspace(0, 340, 20) hchoices=linspace(0, 340, 20)
)[2:end] )[2:end]
gradient_from_list(colors) gradient_from_list(colors)

View File

@ -126,7 +126,7 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, sigma = [1
# run the comparison test... a difference will throw an error # run the comparison test... a difference will throw an error
# NOTE: sigma is a 2-length vector with x/y values for the number of pixels # NOTE: sigma is a 2-length vector with x/y values for the number of pixels
# to blur together when comparing images # to blur together when comparing images
Images.@test_approx_eq_sigma_eps(tmpimg, refimg, sigma, eps) Images.test_approx_eq_sigma_eps(tmpimg, refimg, sigma, eps)
# we passed! # we passed!
info("Reference image $reffn matches") info("Reference image $reffn matches")