working on big set of fixes/reorg; better example code, supportedArgs and subplotSupported, change dots to scatter and handle better

This commit is contained in:
Thomas Breloff 2015-09-16 12:07:08 -04:00
parent d27fe2fbad
commit ae48bd1abb
17 changed files with 190 additions and 72 deletions

View File

@ -152,8 +152,8 @@ __Tip__: Calling `subplot!` on a `Plot` object, or `plot!` on a `Subplot` object
Shorthands:
```julia
scatter(args...; kw...) = plot(args...; kw..., linetype = :none, marker = :hexagon)
scatter!(args...; kw...) = plot!(args...; kw..., linetype = :none, marker = :hexagon)
scatter(args...; kw...) = plot(args...; kw..., linetype = :scatter)
scatter!(args...; kw...) = plot!(args...; kw..., linetype = :scatter)
bar(args...; kw...) = plot(args...; kw..., linetype = :bar)
bar!(args...; kw...) = plot!(args...; kw..., linetype = :bar)
histogram(args...; kw...) = plot(args...; kw..., linetype = :hist)
@ -172,7 +172,7 @@ color # can be a string ("red") or a symbol (:red) or a ColorsTypes.jl
# Colorant (RGB(1,0,0)) or :auto (which lets the package pick)
label # string or symbol, applies to that line, may go in a legend
width # width of a line
linetype # :line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar
linetype # :line, :step, :stepinverted, :sticks, :scatter, :none, :heatmap, :hexbin, :hist, :bar
linestyle # :solid, :dash, :dot, :dashdot, :dashdotdot
marker # :none, :ellipse, :rect, :diamond, :utriangle, :dtriangle,
# :cross, :xcross, :star1, :star2, :hexagon

View File

@ -23,19 +23,19 @@ const examples = PlotExample[
"A simple line plot of the 3 columns.",
[:(plot(rand(100,3)))]),
PlotExample("Functions",
"Plot multiple functions.",
"Plot multiple functions. You can also put the function first.",
[:(plot(0:0.01:4π, [sin,cos]))]),
PlotExample("",
"You can also call it with plot(f, xmin, xmax).",
[:(plot([sin,cos], 0, 4π))]),
PlotExample("",
"Or make a parametric plot with plot(fx, fy, umin, umax).",
"Or make a parametric plot (i.e. plot: (fx(u), fy(u))) with plot(fx, fy, umin, umax).",
[:(plot(sin, x->sin(2x), 0, 2π))]),
PlotExample("Global",
"Change the guides/background without a separate call.",
[:(plot(rand(10); title="TITLE", xlabel="XLABEL", ylabel="YLABEL", background_color = RGB(0.5,0.5,0.5)))]),
PlotExample("Two-axis",
"Use the `axis` or `axiss` arguments.\n\nNote: This is only supported with Qwt right now",
"Use the `axis` or `axiss` arguments.\n\nNote: Currently only supported with Qwt and PyPlot",
[:(plot(Vector[randn(100), randn(100)*100]; axiss = [:left,:right], ylabel="LEFT", yrightlabel="RIGHT"))]),
PlotExample("Vectors w/ pluralized args",
"Plot multiple series with different numbers of points. Mix arguments that apply to all series (singular... see `marker`) with arguments unique to each series (pluralized... see `colors`).",
@ -49,19 +49,18 @@ const examples = PlotExample[
PlotExample("Heatmaps",
"",
[:(heatmap(randn(10000),randn(10000); nbins=100))]),
PlotExample("Lots of line types",
"Options: (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar) \nNote: some may not work with all backends",
[:(plot(rand(20,4); linetypes=[:line, :step, :sticks, :dots], labels=["line","step","sticks","dots"]))]),
PlotExample("Lots of line styles",
"Options: (:solid, :dash, :dot, :dashdot, :dashdotdot) \nNote: some may not work with all backends",
[:(plot(rand(20,5); linestyles=[:solid, :dash, :dot, :dashdot, :dashdotdot], labels=["solid", "dash", "dot", "dashdot", "dashdotdot"]))]),
# PlotExample("Lots of marker types",
# "Options: (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon) \nNote: some may not work with all backends",
# [:(plot(repmat(collect(1:10)',10,1); markers=[:ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon],
# labels=["ellipse", "rect", "diamond", "utriangle", "dtriangle", "cross", "xcross", "star1", "star2", "hexagon"],
# markersize=10))]),
PlotExample("Lots of marker types",
"",
PlotExample("Suported line types",
"All options: (:line, :orderedline, :step, :stepinverted, :sticks, :scatter, :none, :heatmap, :hexbin, :hist, :bar)",
[:(types = intersect(supportedTypes(), [:line, :orderedline, :path, :step, :stepinverted, :sticks, :scatter])),
:(n = length(types)),
:(x = Vector[sort(rand(20)) for i in 1:n]),
:(y = rand(20,n)),
:(plot(x, y; linetype=:auto, labels=map(string,types)))]),
PlotExample("Supported line styles",
"All options: (:solid, :dash, :dot, :dashdot, :dashdotdot)",
[:(styles = supportedStyles()), :(plot(rand(20,length(styles)); linestyle=:auto, labels=map(string,styles)))]),
PlotExample("Supported marker types",
"All options: (:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon)",
[:(markers = supportedMarkers()), :(plot([fill(i,10) for i=1:length(markers)]; marker=:auto, labels=map(string,markers), markersize=10))]),
PlotExample("Bar",
"x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)",
@ -77,7 +76,7 @@ const examples = PlotExample[
Note: Gadfly is not very friendly here, and although you can create a plot and save a PNG, I haven't been able to actually display it.
""",
[:(subplot(randn(100,5); layout=[1,1,3], linetypes=[:line,:hist,:dots,:step,:bar], nbins=10, legend=false))]),
[:(subplot(randn(100,5); layout=[1,1,3], linetypes=[:line,:hist,:scatter,:step,:bar], nbins=10, legend=false))]),
PlotExample("Adding to subplots",
"Note here the automatic grid layout, as well as the order in which new series are added to the plots.",
[:(subplot(randn(100,5); n=4))]),
@ -132,13 +131,40 @@ function generate_markdown(pkgname::Symbol)
end
# make and display one plot
function test_example(pkgname::Symbol, idx::Int)
println("Testing plot: $pkgname:$idx:$(examples[idx].header)")
plotter!(pkgname)
plotter()
map(eval, examples[idx].exprs)
plt = currentPlot()
display(plt)
plt
end
# generate all plots and create a dict mapping idx --> plt
function test_all_examples(pkgname::Symbol)
plts = Dict()
for i in 1:length(examples)
try
plt = test_example(pkgname, i)
plts[i] = plt
catch ex
# TODO: put error info into markdown?
warn("Example $pkgname:$i:$(examples[i].header) failed with: $ex")
end
end
plts
end
# run it!
# note: generate separately so it's easy to comment out
# generate_markdown(:qwt)
generate_markdown(:gadfly)
# generate_markdown(:gadfly)
# @osx_only generate_markdown(:unicodeplots)
# generate_markdown(:pyplot)
generate_markdown(:immerse)
# generate_markdown(:immerse)
end # module

View File

@ -104,11 +104,11 @@ heatmap(randn(10000),randn(10000); nbins=100)
### Lots of line types
Options: (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar)
Options: (:line, :step, :stepinverted, :sticks, :scatter, :none, :heatmap, :hexbin, :hist, :bar)
Note: some may not work with all backends
```julia
plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","sticks","dots"])
plot(rand(20,4); linetypes=[:line,:step,:sticks,:scatter],labels=["line","step","sticks","dots"])
```
![](../img/gadfly/gadfly_example_11.png)

View File

@ -104,11 +104,11 @@ heatmap(randn(10000),randn(10000); nbins=100)
### Lots of line types
Options: (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar)
Options: (:line, :step, :stepinverted, :sticks, :scatter, :none, :heatmap, :hexbin, :hist, :bar)
Note: some may not work with all backends
```julia
plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","sticks","dots"])
plot(rand(20,4); linetypes=[:line,:step,:sticks,:scatter],labels=["line","step","sticks","dots"])
```
![](../img/immerse/immerse_example_11.png)

View File

@ -104,11 +104,11 @@ heatmap(randn(10000),randn(10000); nbins=100)
### Lots of line types
Options: (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar)
Options: (:line, :step, :stepinverted, :sticks, :scatter, :none, :heatmap, :hexbin, :hist, :bar)
Note: some may not work with all backends
```julia
plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","sticks","dots"])
plot(rand(20,4); linetypes=[:line,:step,:sticks,:scatter],labels=["line","step","sticks","dots"])
```
![](../img/pyplot/pyplot_example_11.png)

View File

@ -104,11 +104,11 @@ heatmap(randn(10000),randn(10000); nbins=100)
### Lots of line types
Options: (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar)
Options: (:line, :step, :stepinverted, :sticks, :scatter, :none, :heatmap, :hexbin, :hist, :bar)
Note: some may not work with all backends
```julia
plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","sticks","dots"])
plot(rand(20,4); linetypes=[:line,:step,:sticks,:scatter],labels=["line","step","sticks","dots"])
```
![](../img/qwt/qwt_example_11.png)
@ -165,7 +165,7 @@ histogram(randn(1000); nbins=50,fillto=20)
```julia
subplot(randn(100,5); layout=[1,1,3],linetypes=[:line,:hist,:dots,:step,:bar],nbins=10,legend=false)
subplot(randn(100,5); layout=[1,1,3],linetypes=[:line,:hist,:scatter,:step,:bar],nbins=10,legend=false)
```
![](../img/qwt/qwt_example_16.png)

View File

@ -94,11 +94,11 @@ scatter!(rand(100); markersize=6,color=:blue)
### Lots of line types
Options: (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar)
Options: (:line, :step, :stepinverted, :sticks, :scatter, :none, :heatmap, :hexbin, :hist, :bar)
Note: some may not work with all backends
```julia
plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","sticks","dots"])
plot(rand(20,4); linetypes=[:line,:step,:sticks,:scatter],labels=["line","step","sticks","dots"])
```
![](../img/unicodeplots/unicodeplots_example_11.png)
@ -155,7 +155,7 @@ histogram(randn(1000); nbins=50,fillto=20)
```julia
subplot(randn(100,5); layout=[1,1,3],linetypes=[:line,:hist,:dots,:step,:bar],nbins=10,legend=false)
subplot(randn(100,5); layout=[1,1,3],linetypes=[:line,:hist,:scatter,:step,:bar],nbins=10,legend=false)
```
![](../img/unicodeplots/unicodeplots_example_16.png)

View File

@ -7,10 +7,12 @@ using Colors
export
plotter,
plot,
plot_display,
subplot,
plotter!,
plot!,
plot_display!,
subplot!,
currentPlot,
@ -38,10 +40,12 @@ export
pyplot!,
immerse!,
supportedArgs,
supportedAxes,
supportedTypes,
supportedStyles,
supportedMarkers
supportedMarkers,
subplotSupported
# ---------------------------------------------------------
@ -61,8 +65,8 @@ include("subplot.jl")
# ---------------------------------------------------------
scatter(args...; kw...) = plot(args...; kw..., linetype = :none, marker = :hexagon)
scatter!(args...; kw...) = plot!(args...; kw..., linetype = :none, marker = :hexagon)
scatter(args...; kw...) = plot(args...; kw..., linetype = :scatter)
scatter!(args...; kw...) = plot!(args...; kw..., linetype = :scatter)
bar(args...; kw...) = plot(args...; kw..., linetype = :bar)
bar!(args...; kw...) = plot!(args...; kw..., linetype = :bar)
histogram(args...; kw...) = plot(args...; kw..., linetype = :hist)

View File

@ -5,7 +5,7 @@
const COLORS = distinguishable_colors(20)
const AXES = [:left, :right]
const TYPES = [:line, :step, :stepinverted, :sticks, :dots, :heatmap, :hexbin, :hist, :bar]
const TYPES = [:line, :step, :stepinverted, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar]
const STYLES = [:solid, :dash, :dot, :dashdot, :dashdotdot]
const MARKERS = [:ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon]
@ -13,11 +13,13 @@ supportedAxes(::PlottingPackage) = AXES
supportedTypes(::PlottingPackage) = TYPES
supportedStyles(::PlottingPackage) = STYLES
supportedMarkers(::PlottingPackage) = MARKERS
subplotSupported(::GadflyPackage) = true
supportedAxes() = supportedAxes(plotter())
supportedTypes() = supportedTypes(plotter())
supportedStyles() = supportedStyles(plotter())
supportedMarkers() = supportedMarkers(plotter())
subplotSupported() = subplotSupported(plotter())
# -----------------------------------------------------------------------------
@ -45,8 +47,8 @@ PLOT_DEFAULTS[:ylabel] = ""
PLOT_DEFAULTS[:yrightlabel] = ""
PLOT_DEFAULTS[:legend] = true
# PLOT_DEFAULTS[:background_color] = nothing
PLOT_DEFAULTS[:xticks] = true
PLOT_DEFAULTS[:yticks] = true
# PLOT_DEFAULTS[:xticks] = true
# PLOT_DEFAULTS[:yticks] = true
PLOT_DEFAULTS[:size] = (600,400)
PLOT_DEFAULTS[:windowtitle] = "Plots.jl"
# PLOT_DEFAULTS[:show] = true
@ -57,6 +59,10 @@ PLOT_DEFAULTS[:kwargs] = [] # additional keyword args to pass to the backend
# TODO: x/y scales
const ARGS = sort(collect(keys(PLOT_DEFAULTS)))
supportedArgs(::PlottingPackage) = ARGS
supportedArgs() = supportedArgs(plotter())
# -----------------------------------------------------------------------------
@ -70,6 +76,7 @@ end
makeplural(s::Symbol) = Symbol(string(s,"s"))
autopick(arr::AVec, idx::Integer) = arr[mod1(idx,length(arr))]
autopick(notarr, idx::Integer) = notarr
# converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically
@ -97,7 +104,7 @@ function getRGBColor(c, n::Int = 0)
end
# const ALT_ARG_NAMES = Dict{Tuple{Symbol,Symbol}, Any}()
# ALT_ARG_NAMES[(:linetype, :scatter)] = :dots
# ALT_ARG_NAMES[(:linetype, :scatter)] = :scatter
function warnOnUnsupported(pkg::PlottingPackage, d::Dict)
d[:axis] in supportedAxes(pkg) || warn("axis $(d[:axis]) is unsupported with $pkg. Choose from: $(supportedAxes(pkg))")
@ -130,7 +137,7 @@ function getPlotKeywordArgs(pkg::PlottingPackage, kw, idx::Int, n::Int)
plural = makeplural(k)
if !haskey(d, k)
if n == 0 || k != :size
d[k] = haskey(d, plural) ? d[plural][idx] : PLOT_DEFAULTS[k]
d[k] = haskey(d, plural) ? autopick(d[plural], idx) : PLOT_DEFAULTS[k]
end
end
delete!(d, plural)
@ -153,13 +160,13 @@ function getPlotKeywordArgs(pkg::PlottingPackage, kw, idx::Int, n::Int)
end
# swap out dots for no line and a marker
if haskey(d, :linetype) && d[:linetype] == :dots
d[:linetype] = :none
if d[:marker] == :none
d[:marker] = :ellipse
end
end
# # swap out dots for no line and a marker
# if haskey(d, :linetype) && d[:linetype] == :scatter
# d[:linetype] = :none
# if d[:marker] == :none
# d[:marker] = :ellipse
# end
# end

View File

@ -6,6 +6,7 @@ immutable GadflyPackage <: PlottingPackage end
gadfly!() = plotter!(:gadfly)
suppportedArgs(::GadflyPackage) = setdiff(ARGS, [:heatmap_c, :fillto, :pos])
supportedAxes(::GadflyPackage) = [:left]
supportedTypes(::GadflyPackage) = setdiff(TYPES, [:stepinverted])
supportedStyles(::GadflyPackage) = [:solid]
@ -45,7 +46,7 @@ function getLineGeoms(d::Dict)
lt == :hist && return [Gadfly.Geom.histogram(bincount = d[:nbins])]
lt == :none && return [Gadfly.Geom.path]
lt == :line && return [Gadfly.Geom.path]
# lt == :dots && return [Gadfly.Geom.point]
lt == :scatter && return [Gadfly.Geom.point]
lt == :bar && return [Gadfly.Geom.bar]
lt == :step && return [Gadfly.Geom.step]
# lt == :sticks && return [Gadfly.Geom.bar]

View File

@ -6,6 +6,7 @@ immutable ImmersePackage <: PlottingPackage end
immerse!() = plotter!(:immerse)
suppportedArgs(::ImmersePackage) = setdiff(ARGS, [:heatmap_c, :fillto, :pos])
supportedAxes(::ImmersePackage) = supportedAxes(GadflyPackage())
supportedTypes(::ImmersePackage) = supportedTypes(GadflyPackage())
supportedStyles(::ImmersePackage) = supportedStyles(GadflyPackage())

View File

@ -7,6 +7,7 @@ pyplot!() = plotter!(:pyplot)
# -------------------------------
suppportedArgs(::PyPlotPackage) = setdiff(ARGS, [:reg, :heatmap_c, :fillto, :pos])
# supportedAxes(::PyPlotPackage) = [:left]
# supportedTypes(::PyPlotPackage) = setdiff(TYPES, [:stepinverted])
supportedStyles(::PyPlotPackage) = [:solid,:dash,:dot,:dashdot]
@ -61,12 +62,34 @@ getRightAxis(o) = getLeftAxis(o)[:twinx]()
# left axis is PyPlot.<func>, right axis is "f.axes[0].twinx().<func>"
function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
# in the 2-axis case we need to get: <rightaxis>[:<func>]
if axis == :right
ax = getRightAxis(plt.o)
ax[:set_ylabel](plt.initargs[:yrightlabel])
return ax[linetype == :hist ? :hist : (linetype in (:sticks,:bar) ? :bar : (linetype in (:heatmap,:hexbin) ? :hexbin : :plot))]
fmap = Dict(
:hist => :hist,
:sticks => :bar,
:bar => :bar,
:heatmap => :hexbin,
:hexbin => :hexbin,
# :scatter => :scatter
)
return ax[get(fmap, linetype, :plot)]
# return ax[linetype == :hist ? :hist : (linetype in (:sticks,:bar) ? :bar : (linetype in (:heatmap,:hexbin) ? :hexbin : :plot))]
end
return linetype == :hist ? PyPlot.plt[:hist] : (linetype in (:sticks,:bar) ? PyPlot.bar : (linetype in (:heatmap,:hexbin) ? PyPlot.hexbin : PyPlot.plot))
# get the function
fmap = Dict(
:hist => PyPlot.plt[:hist],
:sticks => PyPlot.bar,
:bar => PyPlot.bar,
:heatmap => PyPlot.hexbin,
:hexbin => PyPlot.hexbin,
# :scatter => PyPlot.scatter
)
return get(fmap, linetype, PyPlot.plot)
# return linetype == :hist ? PyPlot.plt[:hist] : (linetype in (:sticks,:bar) ? PyPlot.bar : (linetype in (:heatmap,:hexbin) ? PyPlot.hexbin : PyPlot.plot))
end
# ------------------------------------------------------------------
@ -99,6 +122,17 @@ end
function plot!(::PyPlotPackage, plt::Plot; kw...)
d = Dict(kw)
if d[:linetype] == :sticks
d,_ = sticksHack(;d...)
elseif d[:linetype] == :scatter
d[:linetype] = :none
if d[:marker] == :none
d[:marker] = :ellipse
end
end
lt = d[:linetype]
extraargs = Dict()
@ -122,13 +156,21 @@ function plot!(::PyPlotPackage, plt::Plot; kw...)
else
# all but color/label
extraargs[:linestyle] = getPyPlotLineStyle(lt, d[:linestyle])
extraargs[:marker] = getPyPlotMarker(d[:marker])
extraargs[:markersize] = d[:markersize]
extraargs[:markerfacecolor] = getPyPlotColor(d[:markercolor])
extraargs[:drawstyle] = getPyPlotDrawStyle(lt)
if lt == :scatter
extraargs[:s] = d[:markersize]
extraargs[:c] = getPyPlotColor(d[:markercolor])
extraargs[:linewidths] = d[:width]
if haskey(d, :colorscheme)
extraargs[:cmap] = d[:colorscheme]
end
else
extraargs[:markersize] = d[:markersize]
extraargs[:markerfacecolor] = getPyPlotColor(d[:markercolor])
extraargs[:drawstyle] = getPyPlotDrawStyle(lt)
end
end
# set these for all types
@ -138,10 +180,16 @@ function plot!(::PyPlotPackage, plt::Plot; kw...)
extraargs[:label] = d[:label]
# do the plot
@show lt
if lt == :hist
d[:serieshandle] = plotfunc(d[:y]; extraargs...)
else
d[:serieshandle] = plotfunc(d[:y]; extraargs...)[1]
elseif lt in (:scatter, :heatmap, :hexbin)
d[:serieshandle] = plotfunc(d[:x], d[:y]; extraargs...)
else
d[:serieshandle] = plotfunc(d[:x], d[:y]; extraargs...)[1]
# retval = plotfunc(d[:x], d[:y]; extraargs...)
# @show retval
# d[:serieshandle] = retval
end
# this sets the bg color inside the grid (plt.o.o == matplotlib.Figure)
@ -158,7 +206,7 @@ function addPyPlotLegend(plt::Plot)
# gotta do this to ensure both axes are included
args = filter(x -> !(x[:linetype] in (:hist,:hexbin,:heatmap)), plt.seriesargs)
if length(args) > 0
PyPlot.legend([d[:serieshandle][1] for d in args], [d[:label] for d in args], loc="best")
PyPlot.legend([d[:serieshandle] for d in args], [d[:label] for d in args], loc="best")
end
end
# catch ex

View File

@ -13,9 +13,9 @@ function adjustQwtKeywords(iscreating::Bool; kw...)
if d[:linetype] == :hexbin
d[:linetype] = :heatmap
elseif d[:linetype] == :dots
elseif d[:linetype] == :scatter
d[:linetype] = :none
d[:marker] = :hexagon
d[:marker] = :ellipse
elseif !iscreating && d[:linetype] == :bar
return barHack(; kw...)
elseif !iscreating && d[:linetype] == :hist
@ -58,6 +58,8 @@ function buildSubplotObject!(::QwtPackage, subplt::Subplot)
i += rowcnt
end
subplt.o = Qwt.vsplitter(rows...)
Qwt.resizewidget(subplt.o, subplt.initargs[:size]...)
Qwt.moveToLastScreen(subplt.o) # hack so it goes to my center monitor... sorry
end
@ -65,6 +67,7 @@ function Base.display(::QwtPackage, subplt::Subplot)
for plt in subplt.plts
Qwt.refresh(plt.o)
end
Qwt.showwidget(subplt.o)
end

View File

@ -9,7 +9,7 @@ immutable [PkgName]Package <: PlottingPackage end
# ---------------------------------------------------------------------------
supportedArgs(::[PkgName]Package) = ARGS
supportedAxes(::[PkgName]Package) = AXES
supportedTypes(::[PkgName]Package) = TYPES
supportedStyles(::[PkgName]Package) = STYLES

View File

@ -7,6 +7,13 @@ unicodeplots!() = plotter!(:unicodeplots)
# -------------------------------
suppportedArgs(::GadflyPackage) = setdiff(ARGS, [:reg, :heatmap_c, :fillto, :pos])
supportedAxes(::GadflyPackage) = [:left]
supportedTypes(::GadflyPackage) = setdiff(TYPES, [:stepinverted])
supportedStyles(::GadflyPackage) = [:solid]
supportedMarkers(::GadflyPackage) = [:ellipse]
function expandLimits!(lims, x)
e1, e2 = extrema(x)
lims[1] = min(lims[1], e1)
@ -61,7 +68,7 @@ function addUnicodeSeries!(o, d::Dict, addlegend::Bool)
stepstyle = :post
if lt == :line
func = UnicodePlots.lineplot!
elseif lt == :dots || d[:marker] != :none
elseif lt == :scatter || d[:marker] != :none
func = UnicodePlots.scatterplot!
elseif lt == :step
func = UnicodePlots.stairs!

View File

@ -53,7 +53,7 @@ Some keyword arguments you can set:
color # can be a string ("red") or a symbol (:red) or a ColorsTypes.jl Colorant (RGB(1,0,0)) or :auto (which lets the package pick)
label # string or symbol, applies to that line, may go in a legend
width # width of a line
linetype # :line, :step, :stepinverted, :sticks, :dots, :none, :heatmap
linetype # :line, :step, :stepinverted, :sticks, :scatter, :none, :heatmap
linestyle # :solid, :dash, :dot, :dashdot, :dashdotdot
marker # :none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon
markercolor # same choices as `color`
@ -92,6 +92,13 @@ function plot(args...; kw...)
plot!(plt, args...; kw...) # add to it
end
function plot_display(args...; kw...)
plt = plot(args...; kw...)
display(plt)
plt
end
# this adds to the current plot
function plot!(args...; kw...)
plot!(currentPlot(), args...; kw...)
@ -168,7 +175,7 @@ function createKWargsList{T<:Real,S<:Real}(plt::PlottingObject, x::AVec{T}, y::A
end
# create m series, 1 for each column of y
function createKWargsList(plt::PlottingObject, y::AMat; kw...)
function createKWargsList{T<:Real}(plt::PlottingObject, y::AMat{T}; kw...)
n,m = size(y)
ret = []
for i in 1:m
@ -181,7 +188,7 @@ function createKWargsList(plt::PlottingObject, y::AMat; kw...)
end
# create m series, 1 for each column of y
function createKWargsList(plt::PlottingObject, x::AVec, y::AMat; kw...)
function createKWargsList{T<:Real,S<:Real}(plt::PlottingObject, x::AVec{T}, y::AMat{S}; kw...)
n,m = size(y)
@assert length(x) == n
ret = []
@ -195,7 +202,7 @@ function createKWargsList(plt::PlottingObject, x::AVec, y::AMat; kw...)
end
# create m series, 1 for each column of y
function createKWargsList(plt::PlottingObject, x::AMat, y::AMat; kw...)
function createKWargsList{T<:Real,S<:Real}(plt::PlottingObject, x::AMat{T}, y::AMat{S}; kw...)
@assert size(x) == size(y)
n,m = size(y)
ret = []
@ -248,16 +255,16 @@ function createKWargsList(plt::PlottingObject, fx::Function, fy::Function, umin:
end
# create 1 series, y = f(x)
function createKWargsList(plt::PlottingObject, x::AVec, f::Function; kw...)
function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec{T}, f::Function; kw...)
d = getPlotKeywordArgs(plt.plotter, kw, 1, plt.n + 1)
d[:x] = x
d[:y] = map(f, x)
[d]
end
createKWargsList(plt::PlottingObject, f::Function, x::AVec; kw...) = createKWargsList(plt, x, f; kw...)
createKWargsList{T<:Real}(plt::PlottingObject, f::Function, x::AVec{T}; kw...) = createKWargsList(plt, x, f; kw...)
# create m series, y = f(x), 1 for each column of x
function createKWargsList(plt::PlottingObject, x::AMat, f::Function; kw...)
function createKWargsList{T<:Real}(plt::PlottingObject, x::AMat{T}, f::Function; kw...)
n,m = size(x)
ret = []
for i in 1:m
@ -268,7 +275,7 @@ function createKWargsList(plt::PlottingObject, x::AMat, f::Function; kw...)
end
ret
end
createKWargsList(plt::PlottingObject, f::Function, x::AMat; kw...) = createKWargsList(plt, x, f; kw...)
createKWargsList{T<:Real}(plt::PlottingObject, f::Function, x::AMat{T}; kw...) = createKWargsList(plt, x, f; kw...)
# ----------------------------------------------------------------------------
@ -309,6 +316,20 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec{T}, y::AVec; kw.
ret
end
# x is vec of vec, but y is a matrix
function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AMat{T}; kw...)
n,m = size(y)
@assert length(x) == m
ret = []
for i in 1:m
d = getPlotKeywordArgs(plt.plotter, kw, i, plt.n + i)
d[:x] = x[i]
d[:y] = getyvec(x[i], y[:,i])
push!(ret, d)
end
ret
end
# same, but m series of (x[i],y[i])
function createKWargsList(plt::PlottingObject, x::AVec, y::AVec; kw...)
@assert length(x) == length(y)

View File

@ -71,7 +71,7 @@ function subplot(args...; kw...)
# initialize the individual plots
pkg = plotter()
tmpd = getPlotKeywordArgs(kw, 1, 0)
tmpd = getPlotKeywordArgs(pkg, kw, 1, 0)
# shouldShow = tmpd[:show]
# tmpd[:show] = false
plts = Plot[plot(pkg; tmpd...) for i in 1:length(layout)]