pyplot fixes

This commit is contained in:
Thomas Breloff 2015-10-17 01:26:58 -04:00
parent 60edccade5
commit d86f24dd35
5 changed files with 115 additions and 74 deletions

File diff suppressed because one or more lines are too long

View File

@ -110,11 +110,14 @@ _seriesDefaults[:label] = "AUTO"
_seriesDefaults[:linetype] = :path _seriesDefaults[:linetype] = :path
_seriesDefaults[:linestyle] = :solid _seriesDefaults[:linestyle] = :solid
_seriesDefaults[:linewidth] = 1 _seriesDefaults[:linewidth] = 1
_seriesDefaults[:lineopacity] = nothing
_seriesDefaults[:markershape] = :none _seriesDefaults[:markershape] = :none
_seriesDefaults[:markercolor] = :match _seriesDefaults[:markercolor] = :match
_seriesDefaults[:markeropacity] = nothing
_seriesDefaults[:markersize] = 6 _seriesDefaults[:markersize] = 6
_seriesDefaults[:fillrange] = nothing # ribbons, areas, etc _seriesDefaults[:fillrange] = nothing # ribbons, areas, etc
_seriesDefaults[:fillcolor] = :match _seriesDefaults[:fillcolor] = :match
_seriesDefaults[:fillopacity] = nothing
# _seriesDefaults[:ribbon] = nothing # _seriesDefaults[:ribbon] = nothing
# _seriesDefaults[:ribboncolor] = :match # _seriesDefaults[:ribboncolor] = :match
_seriesDefaults[:nbins] = 100 # number of bins for heatmaps and hists _seriesDefaults[:nbins] = 100 # number of bins for heatmaps and hists
@ -160,9 +163,10 @@ _plotDefaults[:link] = false
_plotDefaults[:linkx] = false _plotDefaults[:linkx] = false
_plotDefaults[:linky] = false _plotDefaults[:linky] = false
_plotDefaults[:linkfunc] = nothing _plotDefaults[:linkfunc] = nothing
_plotDefaults[:tickfont] = font(13) _plotDefaults[:tickfont] = font(11)
_plotDefaults[:guidefont] = font(16) _plotDefaults[:guidefont] = font(14)
_plotDefaults[:legendfont] = font(10) _plotDefaults[:legendfont] = font(9)
_plotDefaults[:grid] = true
@ -214,6 +218,7 @@ end
:w => :linewidth, :w => :linewidth,
:width => :linewidth, :width => :linewidth,
:lw => :linewidth, :lw => :linewidth,
:lo => :lineopacity,
:type => :linetype, :type => :linetype,
:lt => :linetype, :lt => :linetype,
:t => :linetype, :t => :linetype,
@ -227,11 +232,15 @@ end
:mcolor => :markercolor, :mcolor => :markercolor,
:ms => :markersize, :ms => :markersize,
:msize => :markersize, :msize => :markersize,
:mo => :markeropacity,
:opacity => :markeropacity,
:alpha => :markeropacity,
:f => :fill, :f => :fill,
:area => :fill, :area => :fill,
:fillrng => :fillrange, :fillrng => :fillrange,
:fc => :fillcolor, :fc => :fillcolor,
:fcolor => :fillcolor, :fcolor => :fillcolor,
:fo => :fillopacity,
:g => :group, :g => :group,
:nb => :nbins, :nb => :nbins,
:nbin => :nbins, :nbin => :nbins,
@ -391,9 +400,13 @@ function processLineArg(d::Dict, arg)
d[:linestyle] = arg d[:linestyle] = arg
# linewidth # linewidth
elseif trueOrAllTrue(a -> typeof(a) <: Real, arg) elseif trueOrAllTrue(a -> typeof(a) <: Integer, arg)
d[:linewidth] = arg d[:linewidth] = arg
# lineopacity
elseif trueOrAllTrue(a -> typeof(a) <: Real && a >= 0 && a <= 1, arg)
d[:lineopacity] = arg
# color # color
elseif !handleColors!(d, arg, :color) elseif !handleColors!(d, arg, :color)
warn("Skipped line arg $arg.") warn("Skipped line arg $arg.")
@ -411,9 +424,13 @@ function processMarkerArg(d::Dict, arg)
d[:markershape] = arg d[:markershape] = arg
# markersize # markersize
elseif trueOrAllTrue(a -> typeof(a) <: Real, arg) elseif trueOrAllTrue(a -> typeof(a) <: Integer, arg)
d[:markersize] = arg d[:markersize] = arg
# lineopacity
elseif trueOrAllTrue(a -> typeof(a) <: Real && a >= 0 && a <= 1, arg)
d[:markeropacity] = arg
# markercolor # markercolor
elseif !handleColors!(d, arg, :markercolor) elseif !handleColors!(d, arg, :markercolor)
warn("Skipped marker arg $arg.") warn("Skipped marker arg $arg.")

View File

@ -16,6 +16,7 @@ supportedArgs(::GadflyPackage) = [
:color_palette, :color_palette,
:fillrange, :fillrange,
:fillcolor, :fillcolor,
:fillopacity,
:foreground_color, :foreground_color,
:group, :group,
:label, :label,
@ -24,9 +25,11 @@ supportedArgs(::GadflyPackage) = [
:linestyle, :linestyle,
:linetype, :linetype,
:linewidth, :linewidth,
:lineopacity,
:markershape, :markershape,
:markercolor, :markercolor,
:markersize, :markersize,
:markeropacity,
:n, :n,
:nbins, :nbins,
:nc, :nc,
@ -54,6 +57,7 @@ supportedArgs(::GadflyPackage) = [
:tickfont, :tickfont,
:guidefont, :guidefont,
:legendfont, :legendfont,
:grid,
] ]
supportedAxes(::GadflyPackage) = [:auto, :left] supportedAxes(::GadflyPackage) = [:auto, :left]
supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc] supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
@ -86,6 +90,10 @@ function createGadflyPlotObject(d::Dict)
kwargs[:key_position] = :none kwargs[:key_position] = :none
end end
if !get(d, :grid, true)
kwargs[:grid_color] = getColor(d[:background_color])
end
# fonts # fonts
tfont, gfont, lfont = d[:tickfont], d[:guidefont], d[:legendfont] tfont, gfont, lfont = d[:tickfont], d[:guidefont], d[:legendfont]
@ -142,8 +150,19 @@ function getLineGeom(d::Dict)
end end
function getGadflyLineTheme(d::Dict) function getGadflyLineTheme(d::Dict)
lc = getColor(d[:color]) lc = getColor(d[:color])
α = d[:lineopacity]
if α != nothing
lc = RGBA(lc, α)
end
fc = getColor(d[:fillcolor]) fc = getColor(d[:fillcolor])
α = d[:fillopacity]
if α != nothing
fc = RGBA(fc, α)
end
Gadfly.Theme(; Gadfly.Theme(;
default_color = lc, default_color = lc,
line_width = (d[:linetype] == :sticks ? 1 : d[:linewidth]) * Gadfly.px, line_width = (d[:linetype] == :sticks ? 1 : d[:linewidth]) * Gadfly.px,
@ -199,8 +218,14 @@ end
function getGadflyMarkerTheme(d::Dict) function getGadflyMarkerTheme(d::Dict)
c = getColor(d[:markercolor])
α = d[:markeropacity]
if α != nothing
c = RGBA(RGB(c), α)
end
Gadfly.Theme( Gadfly.Theme(
default_color = getColor(d[:markercolor]), default_color = c,
default_point_size = d[:markersize] * Gadfly.px, default_point_size = d[:markersize] * Gadfly.px,
# highlight_color = getColor(initargs[:foreground_color]), # highlight_color = getColor(initargs[:foreground_color]),
highlight_width = d[:linewidth] * Gadfly.px, highlight_width = d[:linewidth] * Gadfly.px,

View File

@ -35,7 +35,7 @@ supportedArgs(::PyPlotPackage) = [
:nc, :nc,
:nr, :nr,
# :pos, # :pos,
# :reg, # :smooth,
# :ribbon, # :ribbon,
:show, :show,
:size, :size,
@ -55,12 +55,13 @@ supportedArgs(::PyPlotPackage) = [
:xflip, :xflip,
:yflip, :yflip,
:z, :z,
# :linkx, # :tickfont,
# :linky, # :guidefont,
# :linkfunc, # :legendfont,
# :grid,
] ]
supportedAxes(::PyPlotPackage) = _allAxes supportedAxes(::PyPlotPackage) = _allAxes
supportedTypes(::PyPlotPackage) = [:none, :line, :path, :step, :stepinverted, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline] supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot] supportedStyles(::PyPlotPackage) = [:auto, :solid, :dash, :dot, :dashdot]
supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon] supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon]
supportedScales(::PyPlotPackage) = [:identity, :log, :log2, :log10] supportedScales(::PyPlotPackage) = [:identity, :log, :log2, :log10]
@ -109,8 +110,8 @@ function getPyPlotMarker(marker::@compat(AbstractString))
end end
function getPyPlotDrawStyle(linetype::Symbol) function getPyPlotDrawStyle(linetype::Symbol)
linetype == :step && return "steps-post" linetype == :steppost && return "steps-post"
linetype == :stepinverted && return "steps-pre" linetype == :steppre && return "steps-pre"
return "default" return "default"
end end
@ -394,6 +395,20 @@ function createPyPlotAnnotationObject(plt::Plot{PyPlotPackage}, x, y, val::@comp
ax[:annotate](val, xy = (x,y)) ax[:annotate](val, xy = (x,y))
end end
function createPyPlotAnnotationObject(plt::Plot{PyPlotPackage}, x, y, val::PlotText)
ax = getLeftAxis(plt)
ax[:annotate](val.str,
xy = (x,y),
family = val.font.family,
color = getPyPlotColor(val.font.color),
horizontalalignment = val.font.halign == :hcenter ? "center" : string(val.font.halign),
verticalalignment = val.font.valign == :vcenter ? "center" : string(val.font.valign),
rotation = val.font.rotation * 180 / π,
size = val.font.pointsize
)
end
function addAnnotations{X,Y,V}(plt::Plot{PyPlotPackage}, anns::AVec{@compat(Tuple{X,Y,V})}) function addAnnotations{X,Y,V}(plt::Plot{PyPlotPackage}, anns::AVec{@compat(Tuple{X,Y,V})})
for ann in anns for ann in anns
createPyPlotAnnotationObject(plt, ann...) createPyPlotAnnotationObject(plt, ann...)
@ -447,7 +462,12 @@ function addPyPlotLegend(plt::Plot, ax)
# gotta do this to ensure both axes are included # gotta do this to ensure both axes are included
args = filter(x -> !(x[:linetype] in (:hist,:hexbin,:heatmap,:hline,:vline)), plt.seriesargs) args = filter(x -> !(x[:linetype] in (:hist,:hexbin,:heatmap,:hline,:vline)), plt.seriesargs)
if length(args) > 0 if length(args) > 0
ax[:legend]([d[:serieshandle] for d in args], [d[:label] for d in args], loc="best") ax[:legend]([d[:serieshandle] for d in args],
[d[:label] for d in args],
loc="best",
fontsize = plt.initargs[:legendfont].pointsize,
framealpha = 0.6
)
end end
end end
end end

View File

@ -62,7 +62,7 @@ function corrplot{T<:Real,S<:Real}(mat::AMat{T}, corrmat::AMat{S} = cor(mat);
colors = :redsblues, colors = :redsblues,
labels = nothing, kw...) labels = nothing, kw...)
m = size(mat,2) m = size(mat,2)
means = mean(mat, 1) centers = Float64[mean(extrema(mat[:,i])) for i in 1:m]
# might be a mistake? # might be a mistake?
@assert m <= 20 @assert m <= 20
@ -84,7 +84,10 @@ function corrplot{T<:Real,S<:Real}(mat::AMat{T}, corrmat::AMat{S} = cor(mat);
elseif i < j elseif i < j
# plot!(plt, mat[:,j], mat[:,i], l=:hexbin, leg=false) # plot!(plt, mat[:,j], mat[:,i], l=:hexbin, leg=false)
# plot!(plt, [0], [0], ann=(0, 0, "Corr:\n$(corrmat[i,j])"), leg=false) # plot!(plt, [0], [0], ann=(0, 0, "Corr:\n$(corrmat[i,j])"), leg=false)
plot!(plt, [means[j]], [means[i]], title = @sprintf("Corr:\n%0.3f", corrmat[i,j]), yticks=:none) mi, mj = centers[i], centers[j]
plot!(plt, [mj], [mi],
ann = (mj, mi, text(@sprintf("Corr:\n%0.3f", corrmat[i,j]), 15)),
yticks=:none, grid=false)
else else
# scatter plots off-diagonal, color determined by correlation # scatter plots off-diagonal, color determined by correlation
c = RGBA(RGB(getColorZ(cgrad, corrmat[i,j])), 0.3) c = RGBA(RGB(getColorZ(cgrad, corrmat[i,j])), 0.3)