working on gadfly
This commit is contained in:
parent
2d4cd06090
commit
853ce08a9f
14
src/Plots.jl
14
src/Plots.jl
@ -5,19 +5,23 @@ using Requires
|
|||||||
export
|
export
|
||||||
Plot,
|
Plot,
|
||||||
plotter,
|
plotter,
|
||||||
plotter!,
|
|
||||||
plot,
|
plot,
|
||||||
plot!,
|
|
||||||
currentPlot,
|
currentPlot,
|
||||||
currentPlot!,
|
|
||||||
plotDefault,
|
plotDefault,
|
||||||
plotDefault!,
|
|
||||||
|
|
||||||
scatter,
|
scatter,
|
||||||
bar,
|
bar,
|
||||||
hist,
|
hist,
|
||||||
heatmap,
|
heatmap,
|
||||||
|
|
||||||
|
plotter!,
|
||||||
|
plot!,
|
||||||
|
currentPlot!,
|
||||||
|
plotDefault!,
|
||||||
|
scatter!,
|
||||||
|
bar!,
|
||||||
|
hist!,
|
||||||
|
heatmap!,
|
||||||
|
|
||||||
savepng
|
savepng
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|||||||
@ -10,6 +10,7 @@ const LINE_TYPES = (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap
|
|||||||
const LINE_STYLES = (:solid, :dash, :dot, :dashdot, :dashdotdot)
|
const LINE_STYLES = (:solid, :dash, :dot, :dashdot, :dashdotdot)
|
||||||
const LINE_MARKERS = (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)
|
const LINE_MARKERS = (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
const PLOT_DEFAULTS = Dict{Symbol, Any}()
|
const PLOT_DEFAULTS = Dict{Symbol, Any}()
|
||||||
|
|
||||||
@ -36,11 +37,18 @@ PLOT_DEFAULTS[:background_color] = :white
|
|||||||
PLOT_DEFAULTS[:xticks] = true
|
PLOT_DEFAULTS[:xticks] = true
|
||||||
PLOT_DEFAULTS[:yticks] = true
|
PLOT_DEFAULTS[:yticks] = true
|
||||||
|
|
||||||
|
# TODO: x/y scales
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
plotDefault(sym::Symbol) = PLOT_DEFAULTS[sym]
|
plotDefault(sym::Symbol) = PLOT_DEFAULTS[sym]
|
||||||
function plotDefault!(sym::Symbol, val)
|
function plotDefault!(sym::Symbol, val)
|
||||||
PLOT_DEFAULTS[sym] = val
|
PLOT_DEFAULTS[sym] = val
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
makeplural(s::Symbol) = Symbol(string(s,"s"))
|
makeplural(s::Symbol) = Symbol(string(s,"s"))
|
||||||
autocolor(idx::Integer) = COLORS[mod1(idx,NUMCOLORS)]
|
autocolor(idx::Integer) = COLORS[mod1(idx,NUMCOLORS)]
|
||||||
|
|
||||||
|
|||||||
@ -3,26 +3,49 @@
|
|||||||
|
|
||||||
immutable GadflyPackage <: PlottingPackage end
|
immutable GadflyPackage <: PlottingPackage end
|
||||||
|
|
||||||
plot(pkg::GadflyPackage) = Plot(Qwt.plot(zeros(0,0)), pkg, AVec[], AVec[])
|
|
||||||
plot!(::GadflyPackage, plt::Plot; kw...) = Qwt.oplot(plt.o; kw...)
|
|
||||||
|
|
||||||
|
|
||||||
# create a blank Gadfly.Plot object
|
# create a blank Gadfly.Plot object
|
||||||
function plot(pkg::GadflyPackage)
|
function plot(pkg::GadflyPackage; kw...)
|
||||||
|
@eval import DataFrames
|
||||||
plt = Gadfly.Plot()
|
plt = Gadfly.Plot()
|
||||||
plt.mapping = Dict()
|
plt.mapping = Dict()
|
||||||
plt.data_source = DataFrame()
|
plt.data_source = DataFrames.DataFrame()
|
||||||
plt.layers = plt.layers[1:0]
|
plt.layers = plt.layers[1:0]
|
||||||
Plot(plt, pkg, AVec[], AVec[])
|
Plot(plt, pkg, AVec[], AVec[])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# note: currently only accepts lines and dots
|
||||||
|
function getGeomLine(linetype::Symbol)
|
||||||
|
linetype == :line && return [Gadfly.Geom.line()]
|
||||||
|
linetype == :dots && return [Gadfly.Geom.point()]
|
||||||
|
error("linetype $linetype not currently supported with Gadfly")
|
||||||
|
end
|
||||||
|
|
||||||
|
# note: currently map any marker to point
|
||||||
|
function getGeomPoint(marker::Symbol)
|
||||||
|
marker == :none && return []
|
||||||
|
[Gadfly.Geom.point()]
|
||||||
|
end
|
||||||
|
|
||||||
# plot one data series
|
# plot one data series
|
||||||
function plot!(::GadflyPackage, plt::Plot; kw...)
|
function plot!(::GadflyPackage, plt::Plot; kw...)
|
||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
gd = Dict() # the kwargs for the call to Gadfly.layer
|
|
||||||
|
|
||||||
|
gfargs = []
|
||||||
|
|
||||||
append!(plt.o.layers, layer(; gd...))
|
append!(gfargs, getGeomLine(d[:linetype]))
|
||||||
|
append!(gfargs, getGeomPoint(d[:marker]))
|
||||||
|
|
||||||
|
# todo:
|
||||||
|
# linestyle
|
||||||
|
# label
|
||||||
|
# color
|
||||||
|
# legend
|
||||||
|
# guides (x/y labels, title, background, ticks)
|
||||||
|
|
||||||
|
append!(plt.o.layers, Gadfly.layer(unique(gfargs)...; x = d[:x], y = d[:y]))
|
||||||
plt
|
plt
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -30,20 +53,7 @@ function Base.display(::GadflyPackage, plt::Plot)
|
|||||||
display(plt.o)
|
display(plt.o)
|
||||||
end
|
end
|
||||||
|
|
||||||
# julia> append!(plt.layers, layer(x=collect(1:10), y=collect(1:10), Geom.line(), Geom.point()))
|
|
||||||
# 2-element Array{Gadfly.Layer,1}:
|
|
||||||
# Gadfly.Layer(nothing,Dict{Symbol,Union{AbstractArray{T,N},AbstractString,Distributions.Distribution{F<:Distributions.VariateForm,S<:Distributions.ValueSupport},Expr,Function,Integer,Symbol,Void}}(:y=>[1,2,3,4,5,6,7,8,9,10],:x=>[1,2,3,4,5,6,7,8,9,10]),Gadfly.Stat.Nil(),Gadfly.Geom.LineGeometry(Gadfly.Stat.Identity(),false,2),nothing,0)
|
|
||||||
# Gadfly.Layer(nothing,Dict{Symbol,Union{AbstractArray{T,N},AbstractString,Distributions.Distribution{F<:Distributions.VariateForm,S<:Distributions.ValueSupport},Expr,Function,Integer,Symbol,Void}}(:y=>[1,2,3,4,5,6,7,8,9,10],:x=>[1,2,3,4,5,6,7,8,9,10]),Gadfly.Stat.Nil(),Gadfly.Geom.PointGeometry(),nothing,0)
|
|
||||||
|
|
||||||
# julia> append!(plt.layers, layer(x=collect(1:10), y=rand(10), Geom.point()))
|
savepng(::GadflyPackage, plt::Plot, fn::String, args...) = Gadfly.draw(Gadfly.PNG(fn, args...), plt.o)
|
||||||
# 3-element Array{Gadfly.Layer,1}:
|
|
||||||
# Gadfly.Layer(nothing,Dict{Symbol,Union{AbstractArray{T,N},AbstractString,Distributions.Distribution{F<:Distributions.VariateForm,S<:Distributions.ValueSupport},Expr,Function,Integer,Symbol,Void}}(:y=>[1,2,3,4,5,6,7,8,9,10],:x=>[1,2,3,4,5,6,7,8,9,10]),Gadfly.Stat.Nil(),Gadfly.Geom.LineGeometry(Gadfly.Stat.Identity(),false,2),nothing,0)
|
|
||||||
# Gadfly.Layer(nothing,Dict{Symbol,Union{AbstractArray{T,N},AbstractString,Distributions.Distribution{F<:Distributions.VariateForm,S<:Distributions.ValueSupport},Expr,Function,Integer,Symbol,Void}}(:y=>[1,2,3,4,5,6,7,8,9,10],:x=>[1,2,3,4,5,6,7,8,9,10]),Gadfly.Stat.Nil(),Gadfly.Geom.PointGeometry(),nothing,0)
|
|
||||||
# Gadfly.Layer(nothing,Dict{Symbol,Union{AbstractArray{T,N},AbstractString,Distributions.Distribution{F<:Distributions.VariateForm,S<:Distributions.ValueSupport},Expr,Function,Integer,Symbol,Void}}(:y=>[0.6084907709968024,0.05206084912131548,0.14212960794916185,0.10981085500127885,0.9921993333039756,0.9552243188578231,0.3255950301920405,0.1328008877835145,0.8717471404048149,0.18183756751204538],:x=>[1,2,3,4,5,6,7,8,9,10]),Gadfly.Stat.Nil(),Gadfly.Geom.PointGeometry(),nothing,0)
|
|
||||||
|
|
||||||
# julia> display(plt)
|
|
||||||
|
|
||||||
# # plot(::GadflyPackage, y; kw...) = Gadfly.plot(; x = 1:length(y), y = y, kw...)
|
|
||||||
# # plot(::GadflyPackage, x, y; kw...) = Gadfly.plot(; x = x, y = y, kw...)
|
|
||||||
# # plot(::GadflyPackage; kw...) = Gadfly.plot(; kw...)
|
|
||||||
# # savepng(::GadflyPackage, plt, fn::String, args...) = Gadfly.draw(Gadfly.PNG(fn, args...), plt)
|
|
||||||
|
|||||||
@ -135,7 +135,7 @@ function plot!(plt::Plot, args...; show=true, kw...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# show/update the plot
|
# show/update the plot
|
||||||
function display(plt::Plot)
|
function Base.display(plt::Plot)
|
||||||
display(plt.plotter, plt)
|
display(plt.plotter, plt)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
plot(pkg::PlottingPackage; kw...) = error("plot($pkg; kw...) is not implemented")
|
plot(pkg::PlottingPackage; kw...) = error("plot($pkg; kw...) is not implemented")
|
||||||
plot!(pkg::PlottingPackage, plt::Plot; kw...) = error("plot!($pkg, plt; kw...) is not implemented")
|
plot!(pkg::PlottingPackage, plt::Plot; kw...) = error("plot!($pkg, plt; kw...) is not implemented")
|
||||||
display(pkg::PlottingPackage, plt::Plot) = error("display($pkg, plt) is not implemented")
|
Base.display(pkg::PlottingPackage, plt::Plot) = error("display($pkg, plt) is not implemented")
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -5,10 +5,11 @@ immutable QwtPackage <: PlottingPackage end
|
|||||||
|
|
||||||
plot(pkg::QwtPackage; kw...) = Plot(Qwt.plot(zeros(0,0); kw...), pkg, AVec[], AVec[])
|
plot(pkg::QwtPackage; kw...) = Plot(Qwt.plot(zeros(0,0); kw...), pkg, AVec[], AVec[])
|
||||||
plot!(::QwtPackage, plt::Plot; kw...) = Qwt.oplot(plt.o; kw...)
|
plot!(::QwtPackage, plt::Plot; kw...) = Qwt.oplot(plt.o; kw...)
|
||||||
function display(::QwtPackage, plt::Plot)
|
function Base.display(::QwtPackage, plt::Plot)
|
||||||
Qwt.refresh(plt.o)
|
Qwt.refresh(plt.o)
|
||||||
Qwt.showwidget(plt.o)
|
Qwt.showwidget(plt.o)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
savepng(::QwtPackage, plt::Plot, fn::String, args...) = Qwt.savepng(plt.o, fn)
|
||||||
|
|
||||||
# subplot(::QwtPackage, args...; kw...) = Qwt.subplot(args...; kw...)
|
# subplot(::QwtPackage, args...; kw...) = Qwt.subplot(args...; kw...)
|
||||||
# savepng(::QwtPackage, plt, fn::String, args...) = Qwt.savepng(plt, fn)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user