diff --git a/REQUIRE b/REQUIRE index ac4e90d4..6ac85eea 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,3 @@ julia 0.4- -Requires +Colors \ No newline at end of file diff --git a/src/Plots.jl b/src/Plots.jl index 3ff5b043..1510beba 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -1,6 +1,6 @@ module Plots -using Requires +using Colors export Plot, @@ -39,8 +39,6 @@ const IMG_DIR = "$(ENV["HOME"])/.julia/v0.4/Plots/img/" type Plot o # the underlying object plotter::PlottingPackage - xdata::Vector{AVec} - ydata::Vector{AVec} end diff --git a/src/args.jl b/src/args.jl index aaec789a..aefe8858 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1,7 +1,8 @@ -const COLORS = [:black, :blue, :green, :red, :darkGray, :darkCyan, :darkYellow, :darkMagenta, - :darkBlue, :darkGreen, :darkRed, :gray, :cyan, :yellow, :magenta] +# const COLORS = [:black, :blue, :green, :red, :darkGray, :darkCyan, :darkYellow, :darkMagenta, +# :darkBlue, :darkGreen, :darkRed, :gray, :cyan, :yellow, :magenta] +const COLORS = distinguishable_colors(20) const NUMCOLORS = length(COLORS) # these are valid choices... first one is default value if unset diff --git a/src/gadfly.jl b/src/gadfly.jl index 212b690b..05b3fa46 100644 --- a/src/gadfly.jl +++ b/src/gadfly.jl @@ -11,22 +11,22 @@ function plot(pkg::GadflyPackage; kw...) plt.mapping = Dict() plt.data_source = DataFrames.DataFrame() plt.layers = plt.layers[1:0] - Plot(plt, pkg, AVec[], AVec[]) + Plot(plt, pkg) end # note: currently only accepts lines and dots function getGeomLine(linetype::Symbol) - linetype == :line && return [Gadfly.Geom.line()] - linetype == :dots && return [Gadfly.Geom.point()] + 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()] + [Gadfly.Geom.point] end # plot one data series @@ -38,14 +38,20 @@ function plot!(::GadflyPackage, plt::Plot; kw...) append!(gfargs, getGeomLine(d[:linetype])) append!(gfargs, getGeomPoint(d[:marker])) + # todo: # linestyle # label + # color + if d[:color] == :auto + color = convert(RGB{Float32}, autocolor(length(plt.o.layers)+1)) + end + # legend # guides (x/y labels, title, background, ticks) - append!(plt.o.layers, Gadfly.layer(unique(gfargs)...; x = d[:x], y = d[:y])) + append!(plt.o.layers, Gadfly.layer(unique(gfargs)...; x = d[:x], y = d[:y], color = [color])) plt end diff --git a/src/plot.jl b/src/plot.jl index b06caa1f..be812632 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -125,12 +125,16 @@ function plot!(args...; kw...) end # this adds to a specific plot... most plot commands will flow through here -function plot!(plt::Plot, args...; show=true, kw...) +function plot!(plt::Plot, args...; kw...) plot!(plt.plotter, plt, args...; kw...) currentPlot!(plt) - if show + + # do we want to show it? + d = Dict(kw) + if haskey(d, :show) && d[:show] display(plt) end + plt end diff --git a/src/plotter.jl b/src/plotter.jl index dad25d87..157178de 100644 --- a/src/plotter.jl +++ b/src/plotter.jl @@ -1,10 +1,5 @@ -# these are the plotting packages you can load. we use lazymod so that we -# don't "import" the module until we want it -@lazymod Qwt -@lazymod Gadfly - 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") Base.display(pkg::PlottingPackage, plt::Plot) = error("display($pkg, plt) is not implemented") @@ -38,19 +33,21 @@ function plotter!(modname) if modname == :qwt if !(modname in INITIALIZED_PACKAGES) - qwt() + # qwt() + @eval import Qwt push!(INITIALIZED_PACKAGES, modname) end - global Qwt = Main.Qwt + # global Qwt = Main.Qwt CURRENT_PACKAGE.pkg = Nullable(QwtPackage()) return elseif modname == :gadfly if !(modname in INITIALIZED_PACKAGES) - gadfly() + # gadfly() + @eval import Gadfly push!(INITIALIZED_PACKAGES, modname) end - global Gadfly = Main.Gadfly + # global Gadfly = Main.Gadfly CURRENT_PACKAGE.pkg = Nullable(GadflyPackage()) return diff --git a/src/qwt.jl b/src/qwt.jl index 3b4dbefd..c6e3c210 100644 --- a/src/qwt.jl +++ b/src/qwt.jl @@ -3,8 +3,12 @@ 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...) +plot(pkg::QwtPackage; kw...) = Plot(Qwt.plot(zeros(0,0); kw...), pkg) + +function plot!(::QwtPackage, plt::Plot; kw...) + Qwt.oplot(plt.o; kw...) +end + function Base.display(::QwtPackage, plt::Plot) Qwt.refresh(plt.o) Qwt.showwidget(plt.o)