reg line; reorg of plotter commands
This commit is contained in:
parent
c2d7704d3f
commit
341f671c7c
@ -66,9 +66,9 @@ currentPlot!(plot) = (CURRENT_PLOT.nullableplot = Nullable(plot))
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
include("plotter.jl")
|
||||
include("qwt.jl")
|
||||
include("gadfly.jl")
|
||||
include("plotter.jl")
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
|
||||
@ -24,10 +24,11 @@ PLOT_DEFAULTS[:linetype] = :line
|
||||
PLOT_DEFAULTS[:linestyle] = :solid
|
||||
PLOT_DEFAULTS[:marker] = :none
|
||||
PLOT_DEFAULTS[:markercolor] = :match
|
||||
PLOT_DEFAULTS[:markersize] = 10
|
||||
PLOT_DEFAULTS[:heatmap_n] = 100
|
||||
PLOT_DEFAULTS[:markersize] = 3
|
||||
PLOT_DEFAULTS[:nbins] = 100 # number of bins for heatmaps and hists
|
||||
PLOT_DEFAULTS[:heatmap_c] = (0.15, 0.5)
|
||||
PLOT_DEFAULTS[:fillto] = nothing # fills in the area
|
||||
PLOT_DEFAULTS[:fillto] = nothing # fills in the area
|
||||
PLOT_DEFAULTS[:reg] = false # regression line?
|
||||
|
||||
# plot globals
|
||||
PLOT_DEFAULTS[:title] = ""
|
||||
|
||||
@ -22,57 +22,62 @@ function plot(pkg::GadflyPackage; kw...)
|
||||
Plot(plt, pkg, 0)
|
||||
end
|
||||
|
||||
function getGeoms(linetype::Symbol, marker::Symbol, heatmap_n::Int)
|
||||
geoms = []
|
||||
if linetype in (:heatmap,:hexbin)
|
||||
push!(geoms, Gadfly.Geom.hexbin(xbincount=heatmap_n, ybincount=heatmap_n))
|
||||
else
|
||||
if linetype == :line
|
||||
push!(geoms, Gadfly.Geom.line)
|
||||
elseif linetype == :dots
|
||||
push!(geoms, Gadfly.Geom.point)
|
||||
else
|
||||
error("linetype $linetype not currently supported with Gadfly")
|
||||
end
|
||||
function getGeomFromLineType(linetype::Symbol)
|
||||
linetype == :line && return Gadfly.Geom.line
|
||||
linetype == :dots && return Gadfly.Geom.point
|
||||
linetype == :bar && return Gadfly.Geom.bar
|
||||
linetype == :step && return Gadfly.Geom.step
|
||||
linetype == :hist && return Gadfly.Geom.hist
|
||||
error("linetype $linetype not currently supported with Gadfly")
|
||||
end
|
||||
|
||||
function getGeoms(linetype::Symbol, marker::Symbol, nbins::Int)
|
||||
geoms = []
|
||||
|
||||
# handle heatmaps (hexbins) specially
|
||||
if linetype in (:heatmap,:hexbin)
|
||||
push!(geoms, Gadfly.Geom.hexbin(xbincount=nbins, ybincount=nbins))
|
||||
else
|
||||
|
||||
# for other linetypes, get the correct Geom
|
||||
push!(geoms, getGeomFromLineType(linetype))
|
||||
|
||||
# for any marker, add Geom.point
|
||||
if marker != :none
|
||||
push!(geoms, Gadfly.Geom.point)
|
||||
end
|
||||
end
|
||||
|
||||
geoms
|
||||
end
|
||||
|
||||
# # note: currently only accepts lines and dots
|
||||
# function getGeomLine(linetype::Symbol, heatmap_n::Int)
|
||||
# linetype == :line && return [Gadfly.Geom.line]
|
||||
# linetype == :dots && return [Gadfly.Geom.point]
|
||||
# linetype in (:heatmap, :hexbin) && return [Gadfly.Geom.hexbin(xbincount=heatmap_n, ybincount=heatmap_n)]
|
||||
# error("linetype $linetype not currently supported with Gadfly")
|
||||
# end
|
||||
|
||||
# # note: currently map any marker to point
|
||||
# function getGeomPoint(linetype::Syombol, marker::Symbol)
|
||||
# if marker == :none || linetype in (:heatmap, :hexbin)
|
||||
# return []
|
||||
# end
|
||||
# [Gadfly.Geom.point]
|
||||
# end
|
||||
|
||||
# plot one data series
|
||||
function plot!(::GadflyPackage, plt::Plot; kw...)
|
||||
d = Dict(kw)
|
||||
|
||||
gfargs = []
|
||||
# append!(gfargs, getGeomLine(d[:linetype], d[:heatmap_n]))
|
||||
# append!(gfargs, getGeomPoint(d[:marker]))
|
||||
append!(gfargs, getGeoms(d[:linetype], d[:marker], d[:heatmap_n]))
|
||||
|
||||
# add the Geoms
|
||||
println(d)
|
||||
append!(gfargs, getGeoms(d[:linetype], d[:marker], d[:nbins]))
|
||||
|
||||
# set color, line width, and point size
|
||||
theme = Gadfly.Theme(default_color = d[:color],
|
||||
line_width = d[:width] * Gadfly.px,
|
||||
default_point_size = d[:markersize] * Gadfly.px)
|
||||
push!(gfargs, theme)
|
||||
|
||||
# add a regression line?
|
||||
if d[:reg]
|
||||
push!(gfargs, Gadfly.Geom.smooth(method=:lm))
|
||||
end
|
||||
|
||||
append!(plt.o.layers, Gadfly.layer(unique(gfargs)...; x = d[:x], y = d[:y]))
|
||||
# for histograms, set x=y
|
||||
x = d[d[:linetype] == :hist ? :y : :x]
|
||||
|
||||
# add the layer to the Gadfly.Plot
|
||||
append!(plt.o.layers, Gadfly.layer(unique(gfargs)...; x = x, y = d[:y]))
|
||||
plt
|
||||
end
|
||||
|
||||
|
||||
@ -11,46 +11,74 @@ const AVAILABLE_PACKAGES = [:qwt, :gadfly]
|
||||
const INITIALIZED_PACKAGES = Set{Symbol}()
|
||||
|
||||
type CurrentPackage
|
||||
pkg::Nullable{PlottingPackage}
|
||||
# pkg::Nullable{PlottingPackage}
|
||||
sym::Symbol
|
||||
pkg::PlottingPackage
|
||||
end
|
||||
const CURRENT_PACKAGE = CurrentPackage(Nullable{PlottingPackage}())
|
||||
# const CURRENT_PACKAGE = CurrentPackage(Nullable{PlottingPackage}())
|
||||
const CURRENT_PACKAGE = CurrentPackage(:qwt, QwtPackage())
|
||||
|
||||
|
||||
doc"""Returns the current plotting package name."""
|
||||
doc"""
|
||||
Returns the current plotting package name. Initializes package on first use.
|
||||
"""
|
||||
function plotter()
|
||||
if isnull(CURRENT_PACKAGE.pkg)
|
||||
error("Must choose a plotter. Example: `plotter!(:qwt)`")
|
||||
# if isnull(CURRENT_PACKAGE.pkg)
|
||||
# error("Must choose a plotter. Example: `plotter!(:qwt)`")
|
||||
# end
|
||||
currentPackageSymbol = CURRENT_PACKAGE.sym
|
||||
if !(currentPackageSymbol in INITIALIZED_PACKAGES)
|
||||
|
||||
# initialize
|
||||
if currentPackageSymbol == :qwt
|
||||
@eval import Qwt
|
||||
elseif currentPackageSymbol == :gadfly
|
||||
@eval import Gadfly
|
||||
else
|
||||
error("Unknown plotter $currentPackageSymbol. Choose from: $AVAILABLE_PACKAGES")
|
||||
end
|
||||
push!(INITIALIZED_PACKAGES, currentPackageSymbol)
|
||||
# plotter!(CURRENT_PACKAGE.sym)
|
||||
|
||||
end
|
||||
get(CURRENT_PACKAGE.pkg)
|
||||
# get(CURRENT_PACKAGE.pkg)
|
||||
println("Current package: $CURRENT_PACKAGE")
|
||||
CURRENT_PACKAGE.pkg
|
||||
end
|
||||
|
||||
doc"""
|
||||
Setup the plot environment.
|
||||
`plotter!(:qwt)` will load package Qwt.jl and map all subsequent plot commands to that package.
|
||||
Same for `plotter!(:gadfly)`, etc.
|
||||
Set the plot backend. Choose from: :qwt, :gadfly
|
||||
"""
|
||||
function plotter!(modname)
|
||||
|
||||
if modname == :qwt
|
||||
if !(modname in INITIALIZED_PACKAGES)
|
||||
# qwt()
|
||||
@eval import Qwt
|
||||
push!(INITIALIZED_PACKAGES, modname)
|
||||
end
|
||||
# if !(modname in INITIALIZED_PACKAGES)
|
||||
# # qwt()
|
||||
# @eval import Qwt
|
||||
# push!(INITIALIZED_PACKAGES, modname)
|
||||
# end
|
||||
# global Qwt = Main.Qwt
|
||||
CURRENT_PACKAGE.pkg = Nullable(QwtPackage())
|
||||
return
|
||||
# CURRENT_PACKAGE.sym = modname
|
||||
# CURRENT_PACKAGE.pkg = Nullable(QwtPackage())
|
||||
CURRENT_PACKAGE.pkg = QwtPackage()
|
||||
# return
|
||||
|
||||
elseif modname == :gadfly
|
||||
if !(modname in INITIALIZED_PACKAGES)
|
||||
# gadfly()
|
||||
@eval import Gadfly
|
||||
push!(INITIALIZED_PACKAGES, modname)
|
||||
end
|
||||
# if !(modname in INITIALIZED_PACKAGES)
|
||||
# # gadfly()
|
||||
# @eval import Gadfly
|
||||
# push!(INITIALIZED_PACKAGES, modname)
|
||||
# end
|
||||
# global Gadfly = Main.Gadfly
|
||||
CURRENT_PACKAGE.pkg = Nullable(GadflyPackage())
|
||||
return
|
||||
# CURRENT_PACKAGE.sym = modname
|
||||
# CURRENT_PACKAGE.pkg = Nullable(GadflyPackage())
|
||||
CURRENT_PACKAGE.pkg = GadflyPackage()
|
||||
# return
|
||||
|
||||
else
|
||||
error("Unknown plotter $modname. Choose from: $AVAILABLE_PACKAGES")
|
||||
end
|
||||
error("Unknown plotter $modname. Choose from: $AVAILABLE_PACKAGES")
|
||||
|
||||
CURRENT_PACKAGE.sym = modname
|
||||
CURRENT_PACKAGE.pkg
|
||||
end
|
||||
|
||||
@ -8,25 +8,18 @@ function adjustQwtKeywords(; kw...)
|
||||
if d[:linetype] == :hexbin
|
||||
d[:linetype] = :heatmap
|
||||
end
|
||||
d[:heatmap_n] = d[:nbins]
|
||||
d
|
||||
end
|
||||
|
||||
function plot(pkg::QwtPackage; kw...)
|
||||
kw = adjustQwtKeywords(;kw...)
|
||||
plt = Plot(Qwt.plot(zeros(0,0); kw..., show=false), pkg, 0)
|
||||
# d = Dict(kw)
|
||||
# if haskey(d, :background_color)
|
||||
# Qwt.background!(plt.o, Dict(kw)[:background_color])
|
||||
# end
|
||||
plt
|
||||
end
|
||||
|
||||
function plot!(::QwtPackage, plt::Plot; kw...)
|
||||
kw = adjustQwtKeywords(;kw...)
|
||||
# d = Dict(kw)
|
||||
# if haskey(d, :background_color)
|
||||
# Qwt.background!(plt.o, Dict(kw)[:background_color])
|
||||
# end
|
||||
Qwt.oplot(plt.o; kw...)
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user