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

View File

@ -16,6 +16,7 @@ supportedArgs(::GadflyPackage) = [
:color_palette,
:fillrange,
:fillcolor,
:fillopacity,
:foreground_color,
:group,
:label,
@ -24,9 +25,11 @@ supportedArgs(::GadflyPackage) = [
:linestyle,
:linetype,
:linewidth,
:lineopacity,
:markershape,
:markercolor,
:markersize,
:markeropacity,
:n,
:nbins,
:nc,
@ -54,6 +57,7 @@ supportedArgs(::GadflyPackage) = [
:tickfont,
:guidefont,
:legendfont,
:grid,
]
supportedAxes(::GadflyPackage) = [:auto, :left]
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
end
if !get(d, :grid, true)
kwargs[:grid_color] = getColor(d[:background_color])
end
# fonts
tfont, gfont, lfont = d[:tickfont], d[:guidefont], d[:legendfont]
@ -142,8 +150,19 @@ function getLineGeom(d::Dict)
end
function getGadflyLineTheme(d::Dict)
lc = getColor(d[:color])
α = d[:lineopacity]
if α != nothing
lc = RGBA(lc, α)
end
fc = getColor(d[:fillcolor])
α = d[:fillopacity]
if α != nothing
fc = RGBA(fc, α)
end
Gadfly.Theme(;
default_color = lc,
line_width = (d[:linetype] == :sticks ? 1 : d[:linewidth]) * Gadfly.px,
@ -199,8 +218,14 @@ end
function getGadflyMarkerTheme(d::Dict)
c = getColor(d[:markercolor])
α = d[:markeropacity]
if α != nothing
c = RGBA(RGB(c), α)
end
Gadfly.Theme(
default_color = getColor(d[:markercolor]),
default_color = c,
default_point_size = d[:markersize] * Gadfly.px,
# highlight_color = getColor(initargs[:foreground_color]),
highlight_width = d[:linewidth] * Gadfly.px,

View File

@ -35,7 +35,7 @@ supportedArgs(::PyPlotPackage) = [
:nc,
:nr,
# :pos,
# :reg,
# :smooth,
# :ribbon,
:show,
:size,
@ -55,12 +55,13 @@ supportedArgs(::PyPlotPackage) = [
:xflip,
:yflip,
:z,
# :linkx,
# :linky,
# :linkfunc,
# :tickfont,
# :guidefont,
# :legendfont,
# :grid,
]
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]
supportedMarkers(::PyPlotPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :hexagon]
supportedScales(::PyPlotPackage) = [:identity, :log, :log2, :log10]
@ -109,8 +110,8 @@ function getPyPlotMarker(marker::@compat(AbstractString))
end
function getPyPlotDrawStyle(linetype::Symbol)
linetype == :step && return "steps-post"
linetype == :stepinverted && return "steps-pre"
linetype == :steppost && return "steps-post"
linetype == :steppre && return "steps-pre"
return "default"
end
@ -394,6 +395,20 @@ function createPyPlotAnnotationObject(plt::Plot{PyPlotPackage}, x, y, val::@comp
ax[:annotate](val, xy = (x,y))
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})})
for ann in anns
createPyPlotAnnotationObject(plt, ann...)
@ -447,7 +462,12 @@ function addPyPlotLegend(plt::Plot, ax)
# gotta do this to ensure both axes are included
args = filter(x -> !(x[:linetype] in (:hist,:hexbin,:heatmap,:hline,:vline)), plt.seriesargs)
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

View File

@ -62,7 +62,7 @@ function corrplot{T<:Real,S<:Real}(mat::AMat{T}, corrmat::AMat{S} = cor(mat);
colors = :redsblues,
labels = nothing, kw...)
m = size(mat,2)
means = mean(mat, 1)
centers = Float64[mean(extrema(mat[:,i])) for i in 1:m]
# might be a mistake?
@assert m <= 20
@ -84,7 +84,10 @@ function corrplot{T<:Real,S<:Real}(mat::AMat{T}, corrmat::AMat{S} = cor(mat);
elseif i < j
# 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, [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
# scatter plots off-diagonal, color determined by correlation
c = RGBA(RGB(getColorZ(cgrad, corrmat[i,j])), 0.3)