working on gadfly, colors; removed Requires dep
This commit is contained in:
parent
853ce08a9f
commit
0dec779cf4
@ -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
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user