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
|
||||
Plot,
|
||||
plotter,
|
||||
plotter!,
|
||||
plot,
|
||||
plot!,
|
||||
currentPlot,
|
||||
currentPlot!,
|
||||
plotDefault,
|
||||
plotDefault!,
|
||||
|
||||
scatter,
|
||||
bar,
|
||||
hist,
|
||||
heatmap,
|
||||
|
||||
plotter!,
|
||||
plot!,
|
||||
currentPlot!,
|
||||
plotDefault!,
|
||||
scatter!,
|
||||
bar!,
|
||||
hist!,
|
||||
heatmap!,
|
||||
|
||||
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_MARKERS = (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
const PLOT_DEFAULTS = Dict{Symbol, Any}()
|
||||
|
||||
@ -36,11 +37,18 @@ PLOT_DEFAULTS[:background_color] = :white
|
||||
PLOT_DEFAULTS[:xticks] = true
|
||||
PLOT_DEFAULTS[:yticks] = true
|
||||
|
||||
# TODO: x/y scales
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
plotDefault(sym::Symbol) = PLOT_DEFAULTS[sym]
|
||||
function plotDefault!(sym::Symbol, val)
|
||||
PLOT_DEFAULTS[sym] = val
|
||||
end
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
makeplural(s::Symbol) = Symbol(string(s,"s"))
|
||||
autocolor(idx::Integer) = COLORS[mod1(idx,NUMCOLORS)]
|
||||
|
||||
|
||||
@ -3,26 +3,49 @@
|
||||
|
||||
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
|
||||
function plot(pkg::GadflyPackage)
|
||||
function plot(pkg::GadflyPackage; kw...)
|
||||
@eval import DataFrames
|
||||
plt = Gadfly.Plot()
|
||||
plt.mapping = Dict()
|
||||
plt.data_source = DataFrame()
|
||||
plt.data_source = DataFrames.DataFrame()
|
||||
plt.layers = plt.layers[1:0]
|
||||
Plot(plt, pkg, AVec[], AVec[])
|
||||
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
|
||||
function plot!(::GadflyPackage, plt::Plot; 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
|
||||
end
|
||||
|
||||
@ -30,20 +53,7 @@ function Base.display(::GadflyPackage, plt::Plot)
|
||||
display(plt.o)
|
||||
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()))
|
||||
# 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)
|
||||
savepng(::GadflyPackage, plt::Plot, fn::String, args...) = Gadfly.draw(Gadfly.PNG(fn, args...), plt.o)
|
||||
|
||||
# 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
|
||||
|
||||
# show/update the plot
|
||||
function display(plt::Plot)
|
||||
function Base.display(plt::Plot)
|
||||
display(plt.plotter, plt)
|
||||
end
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
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")
|
||||
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!(::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.showwidget(plt.o)
|
||||
end
|
||||
|
||||
savepng(::QwtPackage, plt::Plot, fn::String, args...) = Qwt.savepng(plt.o, fn)
|
||||
|
||||
# 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