args
This commit is contained in:
parent
c11cacbb99
commit
55a85cdaaf
@ -8,6 +8,8 @@ export
|
|||||||
plot!,
|
plot!,
|
||||||
currentPlot,
|
currentPlot,
|
||||||
currentPlot!,
|
currentPlot!,
|
||||||
|
plotDefault,
|
||||||
|
plotDefault!,
|
||||||
savepng
|
savepng
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|||||||
75
src/args.jl
75
src/args.jl
@ -10,19 +10,64 @@ const LINE_TYPES = (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap
|
|||||||
const LINE_STYLES = (:solid, :dash, :dot, :dashdot, :dashdotdot)
|
const LINE_STYLES = (:solid, :dash, :dot, :dashdot, :dashdotdot)
|
||||||
const LINE_MARKERS = (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)
|
const LINE_MARKERS = (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)
|
||||||
|
|
||||||
const DEFAULT_axis = LINE_AXES[1]
|
|
||||||
const DEFAULT_color = :auto
|
|
||||||
const DEFAULT_label = "AUTO"
|
|
||||||
const DEFAULT_width = 2
|
|
||||||
const DEFAULT_linetype = LINE_TYPES[1]
|
|
||||||
const DEFAULT_linestyle = LINE_STYLES[1]
|
|
||||||
const DEFAULT_marker = LINE_MARKERS[1]
|
|
||||||
const DEFAULT_markercolor = :auto
|
|
||||||
const DEFAULT_markersize = 10
|
|
||||||
const DEFAULT_heatmap_n = 100
|
|
||||||
const DEFAULT_heatmap_c = (0.15, 0.5)
|
|
||||||
|
|
||||||
const DEFAULT_title = ""
|
const PLOT_DEFAULTS = Dict{Symbol, Any}()
|
||||||
const DEFAULT_xlabel = ""
|
PLOT_DEFAULTS[:axis] = :left
|
||||||
const DEFAULT_ylabel = ""
|
PLOT_DEFAULTS[:color] = :auto
|
||||||
const DEFAULT_yrightlabel = ""
|
PLOT_DEFAULTS[:label] = "AUTO"
|
||||||
|
PLOT_DEFAULTS[:width] = 1
|
||||||
|
PLOT_DEFAULTS[:linetype] = :line
|
||||||
|
PLOT_DEFAULTS[:linestyle] = :solid
|
||||||
|
PLOT_DEFAULTS[:marker] = :none
|
||||||
|
PLOT_DEFAULTS[:markercolor] = :auto
|
||||||
|
PLOT_DEFAULTS[:markersize] = 10
|
||||||
|
PLOT_DEFAULTS[:heatmap_n] = 100
|
||||||
|
PLOT_DEFAULTS[:heatmap_c] = (0.15, 0.5)
|
||||||
|
PLOT_DEFAULTS[:title] = ""
|
||||||
|
PLOT_DEFAULTS[:xlabel] = ""
|
||||||
|
PLOT_DEFAULTS[:ylabel] = ""
|
||||||
|
PLOT_DEFAULTS[:yrightlabel] = ""
|
||||||
|
|
||||||
|
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)]
|
||||||
|
|
||||||
|
|
||||||
|
function getPlotKeywordArgs(kw, i::Int)
|
||||||
|
d = Dict(kw)
|
||||||
|
kw = Dict()
|
||||||
|
|
||||||
|
for k in keys(PLOT_DEFAULTS)
|
||||||
|
plural = makeplural(k)
|
||||||
|
if haskey(d, plural)
|
||||||
|
kw[k] = d[plural][i]
|
||||||
|
elseif haskey(d, k)
|
||||||
|
kw[k] = d[k]
|
||||||
|
else
|
||||||
|
kw[k] = PLOT_DEFAULTS[k]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
kw
|
||||||
|
end
|
||||||
|
|
||||||
|
# const DEFAULT_axis = LINE_AXES[1]
|
||||||
|
# const DEFAULT_color = :auto
|
||||||
|
# const DEFAULT_label = "AUTO"
|
||||||
|
# const DEFAULT_width = 2
|
||||||
|
# const DEFAULT_linetype = LINE_TYPES[1]
|
||||||
|
# const DEFAULT_linestyle = LINE_STYLES[1]
|
||||||
|
# const DEFAULT_marker = LINE_MARKERS[1]
|
||||||
|
# const DEFAULT_markercolor = :auto
|
||||||
|
# const DEFAULT_markersize = 10
|
||||||
|
# const DEFAULT_heatmap_n = 100
|
||||||
|
# const DEFAULT_heatmap_c = (0.15, 0.5)
|
||||||
|
|
||||||
|
# const DEFAULT_title = ""
|
||||||
|
# const DEFAULT_xlabel = ""
|
||||||
|
# const DEFAULT_ylabel = ""
|
||||||
|
# const DEFAULT_yrightlabel = ""
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
immutable GadflyPackage <: PlottingPackage end
|
immutable GadflyPackage <: PlottingPackage end
|
||||||
|
|
||||||
# newplot(pkg::QwtPackage) = Plot(Qwt.plot(zeros(0,0)), pkg, AVec[], AVec[])
|
# plot(pkg::QwtPackage) = Plot(Qwt.plot(zeros(0,0)), pkg, AVec[], AVec[])
|
||||||
# plot!(::GadflyPackage, plt::Plot; kw...) = Qwt.oplot(plt.o; kw...)
|
# plot!(::GadflyPackage, plt::Plot; kw...) = Qwt.oplot(plt.o; kw...)
|
||||||
|
|
||||||
# plot(::GadflyPackage, y; kw...) = Gadfly.plot(; x = 1:length(y), y = y, kw...)
|
# plot(::GadflyPackage, y; kw...) = Gadfly.plot(; x = 1:length(y), y = y, kw...)
|
||||||
|
|||||||
20
src/plot.jl
20
src/plot.jl
@ -115,9 +115,9 @@ When plotting multiple lines, you can give every line the same trait by using th
|
|||||||
|
|
||||||
# this creates a new plot with args/kw and sets it to be the current plot
|
# this creates a new plot with args/kw and sets it to be the current plot
|
||||||
function plot(args...; kw...)
|
function plot(args...; kw...)
|
||||||
plt = newplot(plotter())
|
plt = plot(plotter(); getPlotKeywordArgs(kw, 1)...) # create a new, blank plot
|
||||||
plot!(plt, args...; kw...)
|
plot!(plt, args...; kw...) # add the series to that plot
|
||||||
currentPlot!(plt)
|
currentPlot!(plt) # set this as the current plot
|
||||||
plt
|
plt
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -133,17 +133,20 @@ end
|
|||||||
# These methods are various ways to add to an existing plot
|
# These methods are various ways to add to an existing plot
|
||||||
|
|
||||||
function plot!(plt::Plot, y::AVec; kw...)
|
function plot!(plt::Plot, y::AVec; kw...)
|
||||||
|
kw = getPlotKeywordArgs(kw, 1)
|
||||||
plot!(plt; x = 1:length(y), y = y, kw...)
|
plot!(plt; x = 1:length(y), y = y, kw...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function plot!(plt::Plot, x::AVec, y::AVec; kw...) # one line (will assert length(x) == length(y))
|
function plot!(plt::Plot, x::AVec, y::AVec; kw...) # one line (will assert length(x) == length(y))
|
||||||
@assert length(x) == length(y)
|
@assert length(x) == length(y)
|
||||||
|
kw = getPlotKeywordArgs(kw, 1)
|
||||||
plot!(plt; x=x, y=y, kw...)
|
plot!(plt; x=x, y=y, kw...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function plot!(plt::Plot, y::AMat; kw...) # multiple lines (one per column of x), all sharing x = 1:size(y,1)
|
function plot!(plt::Plot, y::AMat; kw...) # multiple lines (one per column of x), all sharing x = 1:size(y,1)
|
||||||
n,m = size(y)
|
n,m = size(y)
|
||||||
for i in 1:m
|
for i in 1:m
|
||||||
|
kw = getPlotKeywordArgs(kw, i)
|
||||||
plot!(plt; x = 1:n, y = y[:,i], kw...)
|
plot!(plt; x = 1:n, y = y[:,i], kw...)
|
||||||
end
|
end
|
||||||
plt
|
plt
|
||||||
@ -153,6 +156,7 @@ function plot!(plt::Plot, x::AVec, y::AMat; kw...) # multiple lines
|
|||||||
n,m = size(y)
|
n,m = size(y)
|
||||||
for i in 1:m
|
for i in 1:m
|
||||||
@assert length(x) == n
|
@assert length(x) == n
|
||||||
|
kw = getPlotKeywordArgs(kw, i)
|
||||||
plot!(plt; x = x, y = y[:,i], kw...)
|
plot!(plt; x = x, y = y[:,i], kw...)
|
||||||
end
|
end
|
||||||
plt
|
plt
|
||||||
@ -161,18 +165,21 @@ end
|
|||||||
function plot!(plt::Plot, x::AMat, y::AMat; kw...) # multiple lines (one per column of x/y... will assert size(x) == size(y))
|
function plot!(plt::Plot, x::AMat, y::AMat; kw...) # multiple lines (one per column of x/y... will assert size(x) == size(y))
|
||||||
@assert size(x) == size(y)
|
@assert size(x) == size(y)
|
||||||
for i in 1:size(x,2)
|
for i in 1:size(x,2)
|
||||||
|
kw = getPlotKeywordArgs(kw, i)
|
||||||
plot!(plt; x = x[:,i], y = y[:,i], kw...)
|
plot!(plt; x = x[:,i], y = y[:,i], kw...)
|
||||||
end
|
end
|
||||||
plt
|
plt
|
||||||
end
|
end
|
||||||
|
|
||||||
function plot!(plt::Plot, x::AVec, f::Function; kw...) # one line, y = f(x)
|
function plot!(plt::Plot, x::AVec, f::Function; kw...) # one line, y = f(x)
|
||||||
|
kw = getPlotKeywordArgs(kw, 1)
|
||||||
plot!(plt; x = x, y = map(f,x), kw...)
|
plot!(plt; x = x, y = map(f,x), kw...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function plot!(plt::Plot, x::AMat, f::Function; kw...) # multiple lines, yᵢⱼ = f(xᵢⱼ)
|
function plot!(plt::Plot, x::AMat, f::Function; kw...) # multiple lines, yᵢⱼ = f(xᵢⱼ)
|
||||||
for i in 1:size(x,2)
|
for i in 1:size(x,2)
|
||||||
xi = x[:,i]
|
xi = x[:,i]
|
||||||
|
kw = getPlotKeywordArgs(kw, i)
|
||||||
plot!(plt; x = xi, y = map(f, xi), kw...)
|
plot!(plt; x = xi, y = map(f, xi), kw...)
|
||||||
end
|
end
|
||||||
plt
|
plt
|
||||||
@ -180,6 +187,7 @@ end
|
|||||||
|
|
||||||
function plot!(plt::Plot, x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ)
|
function plot!(plt::Plot, x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ)
|
||||||
for i in 1:length(fs)
|
for i in 1:length(fs)
|
||||||
|
kw = getPlotKeywordArgs(kw, i)
|
||||||
plot!(plt; x = x, y = map(fs[i], x), kw...)
|
plot!(plt; x = x, y = map(fs[i], x), kw...)
|
||||||
end
|
end
|
||||||
plt
|
plt
|
||||||
@ -187,6 +195,7 @@ end
|
|||||||
|
|
||||||
function plot!(plt::Plot, y::AVec{AVec}; kw...) # multiple lines, each with x = 1:length(y[i])
|
function plot!(plt::Plot, y::AVec{AVec}; kw...) # multiple lines, each with x = 1:length(y[i])
|
||||||
for i in 1:length(y)
|
for i in 1:length(y)
|
||||||
|
kw = getPlotKeywordArgs(kw, i)
|
||||||
plot!(plt; x = 1:length(y[i]), y = y[i], kw...)
|
plot!(plt; x = 1:length(y[i]), y = y[i], kw...)
|
||||||
end
|
end
|
||||||
plt
|
plt
|
||||||
@ -195,6 +204,7 @@ end
|
|||||||
function plot!(plt::Plot, x::AVec, y::AVec{AVec}; kw...) # multiple lines, will assert length(x) == length(y[i])
|
function plot!(plt::Plot, x::AVec, y::AVec{AVec}; kw...) # multiple lines, will assert length(x) == length(y[i])
|
||||||
for i in 1:length(y)
|
for i in 1:length(y)
|
||||||
@assert length(x) == length(y[i])
|
@assert length(x) == length(y[i])
|
||||||
|
kw = getPlotKeywordArgs(kw, i)
|
||||||
plot!(plt; x = x, y = y[i], kw...)
|
plot!(plt; x = x, y = y[i], kw...)
|
||||||
end
|
end
|
||||||
plt
|
plt
|
||||||
@ -204,6 +214,7 @@ function plot!(plt::Plot, x::AVec{AVec}, y::AVec{AVec}; kw...) # multiple lines
|
|||||||
@assert length(x) == length(y)
|
@assert length(x) == length(y)
|
||||||
for i in 1:length(x)
|
for i in 1:length(x)
|
||||||
@assert length(x[i]) == length(y[i])
|
@assert length(x[i]) == length(y[i])
|
||||||
|
kw = getPlotKeywordArgs(kw, i)
|
||||||
plot!(plt; x = x[i], y = y[i], kw...)
|
plot!(plt; x = x[i], y = y[i], kw...)
|
||||||
end
|
end
|
||||||
plt
|
plt
|
||||||
@ -211,13 +222,14 @@ end
|
|||||||
|
|
||||||
function plot!(plt::Plot, n::Integer; kw...) # n lines, all empty (for updating plots)
|
function plot!(plt::Plot, n::Integer; kw...) # n lines, all empty (for updating plots)
|
||||||
for i in 1:n
|
for i in 1:n
|
||||||
|
kw = getPlotKeywordArgs(kw, i)
|
||||||
plot(plt, x = zeros(0), y = zeros(0), kw...)
|
plot(plt, x = zeros(0), y = zeros(0), kw...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# -------------------------
|
# -------------------------
|
||||||
|
|
||||||
# this is the core method... add to a plot object using kwargs
|
# this is the core method... add to a plot object using kwargs, with args already converted into kwargs
|
||||||
function plot!(plt::Plot; kw...)
|
function plot!(plt::Plot; kw...)
|
||||||
plot!(plotter(), plt; kw...)
|
plot!(plotter(), plt; kw...)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
immutable QwtPackage <: PlottingPackage end
|
immutable QwtPackage <: PlottingPackage end
|
||||||
|
|
||||||
newplot(pkg::QwtPackage) = Plot(Qwt.plot(zeros(0,0)), pkg, AVec[], AVec[])
|
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!(::QwtPackage, plt::Plot; kw...) = Qwt.oplot(plt.o; kw...)
|
||||||
# subplot(::QwtPackage, args...; kw...) = Qwt.subplot(args...; kw...)
|
# subplot(::QwtPackage, args...; kw...) = Qwt.subplot(args...; kw...)
|
||||||
# savepng(::QwtPackage, plt, fn::String, args...) = Qwt.savepng(plt, fn)
|
# savepng(::QwtPackage, plt, fn::String, args...) = Qwt.savepng(plt, fn)
|
||||||
|
|||||||
@ -5,16 +5,18 @@ using FactCheck
|
|||||||
|
|
||||||
|
|
||||||
facts("Qwt") do
|
facts("Qwt") do
|
||||||
|
plotDefault!(:show, false)
|
||||||
|
|
||||||
@fact plotter!(:qwt) --> nothing
|
@fact plotter!(:qwt) --> nothing
|
||||||
@fact plotter() --> Plots.QwtPackage()
|
@fact plotter() --> Plots.QwtPackage()
|
||||||
@fact typeof(plot(1:10, show=false)) --> Plot
|
@fact typeof(plot(1:10)) --> Plot
|
||||||
|
|
||||||
# plot(y::AVec; kw...) # one line... x = 1:length(y)
|
# plot(y::AVec; kw...) # one line... x = 1:length(y)
|
||||||
@fact plot(1:10, show=false) --> not(nothing)
|
@fact plot(1:10) --> not(nothing)
|
||||||
@fact length(currentPlot().o.lines) --> 1
|
@fact length(currentPlot().o.lines) --> 1
|
||||||
|
|
||||||
# plot(x::AVec, y::AVec; kw...) # one line (will assert length(x) == length(y))
|
# plot(x::AVec, y::AVec; kw...) # one line (will assert length(x) == length(y))
|
||||||
@fact plot(Int[1,2,3], rand(3); show=false) --> not(nothing)
|
@fact plot(Int[1,2,3], rand(3)) --> not(nothing)
|
||||||
@fact_throws plot(1:5, 1:4)
|
@fact_throws plot(1:5, 1:4)
|
||||||
|
|
||||||
# plot(y::AMat; kw...) # multiple lines (one per column of x), all sharing x = 1:size(y,1)
|
# plot(y::AMat; kw...) # multiple lines (one per column of x), all sharing x = 1:size(y,1)
|
||||||
@ -37,7 +39,7 @@ end
|
|||||||
facts("Gadfly") do
|
facts("Gadfly") do
|
||||||
@fact plotter!(:gadfly) --> nothing
|
@fact plotter!(:gadfly) --> nothing
|
||||||
@fact plotter() --> Plots.GadflyPackage()
|
@fact plotter() --> Plots.GadflyPackage()
|
||||||
@fact typeof(plot(1:10, show=false)) --> Plot
|
@fact typeof(plot(1:10)) --> Plot
|
||||||
end
|
end
|
||||||
|
|
||||||
FactCheck.exitstatus()
|
FactCheck.exitstatus()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user