diff --git a/src/Plots.jl b/src/Plots.jl index 2ba417e0..3ff5b043 100644 --- a/src/Plots.jl +++ b/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 # --------------------------------------------------------- diff --git a/src/args.jl b/src/args.jl index 52e2db0e..aaec789a 100644 --- a/src/args.jl +++ b/src/args.jl @@ -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)] diff --git a/src/gadfly.jl b/src/gadfly.jl index 25e3ec83..212b690b 100644 --- a/src/gadfly.jl +++ b/src/gadfly.jl @@ -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) diff --git a/src/plot.jl b/src/plot.jl index ca98c500..b06caa1f 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -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 diff --git a/src/plotter.jl b/src/plotter.jl index ff7194bd..dad25d87 100644 --- a/src/plotter.jl +++ b/src/plotter.jl @@ -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") # --------------------------------------------------------- diff --git a/src/qwt.jl b/src/qwt.jl index 571cf9ad..3b4dbefd 100644 --- a/src/qwt.jl +++ b/src/qwt.jl @@ -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)