working on gadfly, colors; removed Requires dep
This commit is contained in:
parent
853ce08a9f
commit
0dec779cf4
@ -1,6 +1,6 @@
|
|||||||
module Plots
|
module Plots
|
||||||
|
|
||||||
using Requires
|
using Colors
|
||||||
|
|
||||||
export
|
export
|
||||||
Plot,
|
Plot,
|
||||||
@ -39,8 +39,6 @@ const IMG_DIR = "$(ENV["HOME"])/.julia/v0.4/Plots/img/"
|
|||||||
type Plot
|
type Plot
|
||||||
o # the underlying object
|
o # the underlying object
|
||||||
plotter::PlottingPackage
|
plotter::PlottingPackage
|
||||||
xdata::Vector{AVec}
|
|
||||||
ydata::Vector{AVec}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
const COLORS = [:black, :blue, :green, :red, :darkGray, :darkCyan, :darkYellow, :darkMagenta,
|
# const COLORS = [:black, :blue, :green, :red, :darkGray, :darkCyan, :darkYellow, :darkMagenta,
|
||||||
:darkBlue, :darkGreen, :darkRed, :gray, :cyan, :yellow, :magenta]
|
# :darkBlue, :darkGreen, :darkRed, :gray, :cyan, :yellow, :magenta]
|
||||||
|
const COLORS = distinguishable_colors(20)
|
||||||
const NUMCOLORS = length(COLORS)
|
const NUMCOLORS = length(COLORS)
|
||||||
|
|
||||||
# these are valid choices... first one is default value if unset
|
# these are valid choices... first one is default value if unset
|
||||||
|
|||||||
@ -11,22 +11,22 @@ function plot(pkg::GadflyPackage; kw...)
|
|||||||
plt.mapping = Dict()
|
plt.mapping = Dict()
|
||||||
plt.data_source = DataFrames.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)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# note: currently only accepts lines and dots
|
# note: currently only accepts lines and dots
|
||||||
function getGeomLine(linetype::Symbol)
|
function getGeomLine(linetype::Symbol)
|
||||||
linetype == :line && return [Gadfly.Geom.line()]
|
linetype == :line && return [Gadfly.Geom.line]
|
||||||
linetype == :dots && return [Gadfly.Geom.point()]
|
linetype == :dots && return [Gadfly.Geom.point]
|
||||||
error("linetype $linetype not currently supported with Gadfly")
|
error("linetype $linetype not currently supported with Gadfly")
|
||||||
end
|
end
|
||||||
|
|
||||||
# note: currently map any marker to point
|
# note: currently map any marker to point
|
||||||
function getGeomPoint(marker::Symbol)
|
function getGeomPoint(marker::Symbol)
|
||||||
marker == :none && return []
|
marker == :none && return []
|
||||||
[Gadfly.Geom.point()]
|
[Gadfly.Geom.point]
|
||||||
end
|
end
|
||||||
|
|
||||||
# plot one data series
|
# plot one data series
|
||||||
@ -38,14 +38,20 @@ function plot!(::GadflyPackage, plt::Plot; kw...)
|
|||||||
append!(gfargs, getGeomLine(d[:linetype]))
|
append!(gfargs, getGeomLine(d[:linetype]))
|
||||||
append!(gfargs, getGeomPoint(d[:marker]))
|
append!(gfargs, getGeomPoint(d[:marker]))
|
||||||
|
|
||||||
|
|
||||||
# todo:
|
# todo:
|
||||||
# linestyle
|
# linestyle
|
||||||
# label
|
# label
|
||||||
|
|
||||||
# color
|
# color
|
||||||
|
if d[:color] == :auto
|
||||||
|
color = convert(RGB{Float32}, autocolor(length(plt.o.layers)+1))
|
||||||
|
end
|
||||||
|
|
||||||
# legend
|
# legend
|
||||||
# guides (x/y labels, title, background, ticks)
|
# 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
|
plt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -125,12 +125,16 @@ function plot!(args...; kw...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# this adds to a specific plot... most plot commands will flow through here
|
# 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...)
|
plot!(plt.plotter, plt, args...; kw...)
|
||||||
currentPlot!(plt)
|
currentPlot!(plt)
|
||||||
if show
|
|
||||||
|
# do we want to show it?
|
||||||
|
d = Dict(kw)
|
||||||
|
if haskey(d, :show) && d[:show]
|
||||||
display(plt)
|
display(plt)
|
||||||
end
|
end
|
||||||
|
|
||||||
plt
|
plt
|
||||||
end
|
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; 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")
|
||||||
Base.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")
|
||||||
@ -38,19 +33,21 @@ function plotter!(modname)
|
|||||||
|
|
||||||
if modname == :qwt
|
if modname == :qwt
|
||||||
if !(modname in INITIALIZED_PACKAGES)
|
if !(modname in INITIALIZED_PACKAGES)
|
||||||
qwt()
|
# qwt()
|
||||||
|
@eval import Qwt
|
||||||
push!(INITIALIZED_PACKAGES, modname)
|
push!(INITIALIZED_PACKAGES, modname)
|
||||||
end
|
end
|
||||||
global Qwt = Main.Qwt
|
# global Qwt = Main.Qwt
|
||||||
CURRENT_PACKAGE.pkg = Nullable(QwtPackage())
|
CURRENT_PACKAGE.pkg = Nullable(QwtPackage())
|
||||||
return
|
return
|
||||||
|
|
||||||
elseif modname == :gadfly
|
elseif modname == :gadfly
|
||||||
if !(modname in INITIALIZED_PACKAGES)
|
if !(modname in INITIALIZED_PACKAGES)
|
||||||
gadfly()
|
# gadfly()
|
||||||
|
@eval import Gadfly
|
||||||
push!(INITIALIZED_PACKAGES, modname)
|
push!(INITIALIZED_PACKAGES, modname)
|
||||||
end
|
end
|
||||||
global Gadfly = Main.Gadfly
|
# global Gadfly = Main.Gadfly
|
||||||
CURRENT_PACKAGE.pkg = Nullable(GadflyPackage())
|
CURRENT_PACKAGE.pkg = Nullable(GadflyPackage())
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@ -3,8 +3,12 @@
|
|||||||
|
|
||||||
immutable QwtPackage <: PlottingPackage end
|
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)
|
||||||
plot!(::QwtPackage, plt::Plot; kw...) = Qwt.oplot(plt.o; kw...)
|
|
||||||
|
function plot!(::QwtPackage, plt::Plot; kw...)
|
||||||
|
Qwt.oplot(plt.o; kw...)
|
||||||
|
end
|
||||||
|
|
||||||
function Base.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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user