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: Shorthands:
```julia ```julia
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 = :none, marker = :hexagon) scatter!(args...; kw...) = plot!(args...; kw..., linetype = :scatter)
bar(args...; kw...) = plot(args...; kw..., linetype = :bar) bar(args...; kw...) = plot(args...; kw..., linetype = :bar)
bar!(args...; kw...) = plot!(args...; kw..., linetype = :bar) bar!(args...; kw...) = plot!(args...; kw..., linetype = :bar)
histogram(args...; kw...) = plot(args...; kw..., linetype = :hist) 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) # 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 label # string or symbol, applies to that line, may go in a legend
width # width of a line 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 linestyle # :solid, :dash, :dot, :dashdot, :dashdotdot
marker # :none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, marker # :none, :ellipse, :rect, :diamond, :utriangle, :dtriangle,
# :cross, :xcross, :star1, :star2, :hexagon # :cross, :xcross, :star1, :star2, :hexagon

View File

@ -23,19 +23,19 @@ const examples = PlotExample[
"A simple line plot of the 3 columns.", "A simple line plot of the 3 columns.",
[:(plot(rand(100,3)))]), [:(plot(rand(100,3)))]),
PlotExample("Functions", PlotExample("Functions",
"Plot multiple functions.", "Plot multiple functions. You can also put the function first.",
[:(plot(0:0.01:4π, [sin,cos]))]), [:(plot(0:0.01:4π, [sin,cos]))]),
PlotExample("", PlotExample("",
"You can also call it with plot(f, xmin, xmax).", "You can also call it with plot(f, xmin, xmax).",
[:(plot([sin,cos], 0, 4π))]), [:(plot([sin,cos], 0, 4π))]),
PlotExample("", 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π))]), [:(plot(sin, x->sin(2x), 0, 2π))]),
PlotExample("Global", PlotExample("Global",
"Change the guides/background without a separate call.", "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)))]), [:(plot(rand(10); title="TITLE", xlabel="XLABEL", ylabel="YLABEL", background_color = RGB(0.5,0.5,0.5)))]),
PlotExample("Two-axis", 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"))]), [:(plot(Vector[randn(100), randn(100)*100]; axiss = [:left,:right], ylabel="LEFT", yrightlabel="RIGHT"))]),
PlotExample("Vectors w/ pluralized args", 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`).", "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", PlotExample("Heatmaps",
"", "",
[:(heatmap(randn(10000),randn(10000); nbins=100))]), [:(heatmap(randn(10000),randn(10000); nbins=100))]),
PlotExample("Lots of line types", PlotExample("Suported line types",
"Options: (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar) \nNote: some may not work with all backends", "All options: (:line, :orderedline, :step, :stepinverted, :sticks, :scatter, :none, :heatmap, :hexbin, :hist, :bar)",
[:(plot(rand(20,4); linetypes=[:line, :step, :sticks, :dots], labels=["line","step","sticks","dots"]))]), [:(types = intersect(supportedTypes(), [:line, :orderedline, :path, :step, :stepinverted, :sticks, :scatter])),
PlotExample("Lots of line styles", :(n = length(types)),
"Options: (:solid, :dash, :dot, :dashdot, :dashdotdot) \nNote: some may not work with all backends", :(x = Vector[sort(rand(20)) for i in 1:n]),
[:(plot(rand(20,5); linestyles=[:solid, :dash, :dot, :dashdot, :dashdotdot], labels=["solid", "dash", "dot", "dashdot", "dashdotdot"]))]), :(y = rand(20,n)),
# PlotExample("Lots of marker types", :(plot(x, y; linetype=:auto, labels=map(string,types)))]),
# "Options: (:none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon) \nNote: some may not work with all backends", PlotExample("Supported line styles",
# [:(plot(repmat(collect(1:10)',10,1); markers=[:ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon], "All options: (:solid, :dash, :dot, :dashdot, :dashdotdot)",
# labels=["ellipse", "rect", "diamond", "utriangle", "dtriangle", "cross", "xcross", "star1", "star2", "hexagon"], [:(styles = supportedStyles()), :(plot(rand(20,length(styles)); linestyle=:auto, labels=map(string,styles)))]),
# markersize=10))]), PlotExample("Supported marker types",
PlotExample("Lots of 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))]), [:(markers = supportedMarkers()), :(plot([fill(i,10) for i=1:length(markers)]; marker=:auto, labels=map(string,markers), markersize=10))]),
PlotExample("Bar", PlotExample("Bar",
"x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)", "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. 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", PlotExample("Adding to subplots",
"Note here the automatic grid layout, as well as the order in which new series are added to the plots.", "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))]), [:(subplot(randn(100,5); n=4))]),
@ -132,13 +131,40 @@ function generate_markdown(pkgname::Symbol)
end 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! # run it!
# note: generate separately so it's easy to comment out # note: generate separately so it's easy to comment out
# generate_markdown(:qwt) # generate_markdown(:qwt)
generate_markdown(:gadfly) # generate_markdown(:gadfly)
# @osx_only generate_markdown(:unicodeplots) # @osx_only generate_markdown(:unicodeplots)
# generate_markdown(:pyplot) # generate_markdown(:pyplot)
generate_markdown(:immerse) # generate_markdown(:immerse)
end # module end # module

View File

@ -104,11 +104,11 @@ heatmap(randn(10000),randn(10000); nbins=100)
### Lots of line types ### 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 Note: some may not work with all backends
```julia ```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) ![](../img/gadfly/gadfly_example_11.png)

View File

@ -104,11 +104,11 @@ heatmap(randn(10000),randn(10000); nbins=100)
### Lots of line types ### 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 Note: some may not work with all backends
```julia ```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) ![](../img/immerse/immerse_example_11.png)

View File

@ -104,11 +104,11 @@ heatmap(randn(10000),randn(10000); nbins=100)
### Lots of line types ### 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 Note: some may not work with all backends
```julia ```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) ![](../img/pyplot/pyplot_example_11.png)

View File

@ -104,11 +104,11 @@ heatmap(randn(10000),randn(10000); nbins=100)
### Lots of line types ### 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 Note: some may not work with all backends
```julia ```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) ![](../img/qwt/qwt_example_11.png)
@ -165,7 +165,7 @@ histogram(randn(1000); nbins=50,fillto=20)
```julia ```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) ![](../img/qwt/qwt_example_16.png)

View File

@ -94,11 +94,11 @@ scatter!(rand(100); markersize=6,color=:blue)
### Lots of line types ### 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 Note: some may not work with all backends
```julia ```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) ![](../img/unicodeplots/unicodeplots_example_11.png)
@ -155,7 +155,7 @@ histogram(randn(1000); nbins=50,fillto=20)
```julia ```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) ![](../img/unicodeplots/unicodeplots_example_16.png)

View File

@ -7,10 +7,12 @@ using Colors
export export
plotter, plotter,
plot, plot,
plot_display,
subplot, subplot,
plotter!, plotter!,
plot!, plot!,
plot_display!,
subplot!, subplot!,
currentPlot, currentPlot,
@ -38,10 +40,12 @@ export
pyplot!, pyplot!,
immerse!, immerse!,
supportedArgs,
supportedAxes, supportedAxes,
supportedTypes, supportedTypes,
supportedStyles, 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 = :scatter)
scatter!(args...; kw...) = plot!(args...; kw..., linetype = :none, marker = :hexagon) scatter!(args...; kw...) = plot!(args...; kw..., linetype = :scatter)
bar(args...; kw...) = plot(args...; kw..., linetype = :bar) bar(args...; kw...) = plot(args...; kw..., linetype = :bar)
bar!(args...; kw...) = plot!(args...; kw..., linetype = :bar) bar!(args...; kw...) = plot!(args...; kw..., linetype = :bar)
histogram(args...; kw...) = plot(args...; kw..., linetype = :hist) histogram(args...; kw...) = plot(args...; kw..., linetype = :hist)

View File

@ -5,7 +5,7 @@
const COLORS = distinguishable_colors(20) const COLORS = distinguishable_colors(20)
const AXES = [:left, :right] 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 STYLES = [:solid, :dash, :dot, :dashdot, :dashdotdot]
const MARKERS = [:ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon] const MARKERS = [:ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon]
@ -13,11 +13,13 @@ supportedAxes(::PlottingPackage) = AXES
supportedTypes(::PlottingPackage) = TYPES supportedTypes(::PlottingPackage) = TYPES
supportedStyles(::PlottingPackage) = STYLES supportedStyles(::PlottingPackage) = STYLES
supportedMarkers(::PlottingPackage) = MARKERS supportedMarkers(::PlottingPackage) = MARKERS
subplotSupported(::GadflyPackage) = true
supportedAxes() = supportedAxes(plotter()) supportedAxes() = supportedAxes(plotter())
supportedTypes() = supportedTypes(plotter()) supportedTypes() = supportedTypes(plotter())
supportedStyles() = supportedStyles(plotter()) supportedStyles() = supportedStyles(plotter())
supportedMarkers() = supportedMarkers(plotter()) supportedMarkers() = supportedMarkers(plotter())
subplotSupported() = subplotSupported(plotter())
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -45,8 +47,8 @@ PLOT_DEFAULTS[:ylabel] = ""
PLOT_DEFAULTS[:yrightlabel] = "" PLOT_DEFAULTS[:yrightlabel] = ""
PLOT_DEFAULTS[:legend] = true PLOT_DEFAULTS[:legend] = true
# PLOT_DEFAULTS[:background_color] = nothing # PLOT_DEFAULTS[:background_color] = nothing
PLOT_DEFAULTS[:xticks] = true # PLOT_DEFAULTS[:xticks] = true
PLOT_DEFAULTS[:yticks] = true # PLOT_DEFAULTS[:yticks] = true
PLOT_DEFAULTS[:size] = (600,400) PLOT_DEFAULTS[:size] = (600,400)
PLOT_DEFAULTS[:windowtitle] = "Plots.jl" PLOT_DEFAULTS[:windowtitle] = "Plots.jl"
# PLOT_DEFAULTS[:show] = true # PLOT_DEFAULTS[:show] = true
@ -57,6 +59,10 @@ PLOT_DEFAULTS[:kwargs] = [] # additional keyword args to pass to the backend
# TODO: x/y scales # 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")) makeplural(s::Symbol) = Symbol(string(s,"s"))
autopick(arr::AVec, idx::Integer) = arr[mod1(idx,length(arr))] 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 # 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 end
# const ALT_ARG_NAMES = Dict{Tuple{Symbol,Symbol}, Any}() # 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) function warnOnUnsupported(pkg::PlottingPackage, d::Dict)
d[:axis] in supportedAxes(pkg) || warn("axis $(d[:axis]) is unsupported with $pkg. Choose from: $(supportedAxes(pkg))") 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) plural = makeplural(k)
if !haskey(d, k) if !haskey(d, k)
if n == 0 || k != :size 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
end end
delete!(d, plural) delete!(d, plural)
@ -153,13 +160,13 @@ function getPlotKeywordArgs(pkg::PlottingPackage, kw, idx::Int, n::Int)
end end
# swap out dots for no line and a marker # # swap out dots for no line and a marker
if haskey(d, :linetype) && d[:linetype] == :dots # if haskey(d, :linetype) && d[:linetype] == :scatter
d[:linetype] = :none # d[:linetype] = :none
if d[:marker] == :none # if d[:marker] == :none
d[:marker] = :ellipse # d[:marker] = :ellipse
end # end
end # end

View File

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

View File

@ -6,6 +6,7 @@ immutable ImmersePackage <: PlottingPackage end
immerse!() = plotter!(:immerse) immerse!() = plotter!(:immerse)
suppportedArgs(::ImmersePackage) = setdiff(ARGS, [:heatmap_c, :fillto, :pos])
supportedAxes(::ImmersePackage) = supportedAxes(GadflyPackage()) supportedAxes(::ImmersePackage) = supportedAxes(GadflyPackage())
supportedTypes(::ImmersePackage) = supportedTypes(GadflyPackage()) supportedTypes(::ImmersePackage) = supportedTypes(GadflyPackage())
supportedStyles(::ImmersePackage) = supportedStyles(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] # supportedAxes(::PyPlotPackage) = [:left]
# supportedTypes(::PyPlotPackage) = setdiff(TYPES, [:stepinverted]) # supportedTypes(::PyPlotPackage) = setdiff(TYPES, [:stepinverted])
supportedStyles(::PyPlotPackage) = [:solid,:dash,:dot,:dashdot] 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>" # left axis is PyPlot.<func>, right axis is "f.axes[0].twinx().<func>"
function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol) function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
# in the 2-axis case we need to get: <rightaxis>[:<func>]
if axis == :right if axis == :right
ax = getRightAxis(plt.o) ax = getRightAxis(plt.o)
ax[:set_ylabel](plt.initargs[:yrightlabel]) 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 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 end
# ------------------------------------------------------------------ # ------------------------------------------------------------------
@ -99,6 +122,17 @@ end
function plot!(::PyPlotPackage, plt::Plot; kw...) function plot!(::PyPlotPackage, plt::Plot; kw...)
d = Dict(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] lt = d[:linetype]
extraargs = Dict() extraargs = Dict()
@ -122,13 +156,21 @@ function plot!(::PyPlotPackage, plt::Plot; kw...)
else else
# all but color/label
extraargs[:linestyle] = getPyPlotLineStyle(lt, d[:linestyle]) extraargs[:linestyle] = getPyPlotLineStyle(lt, d[:linestyle])
extraargs[:marker] = getPyPlotMarker(d[:marker]) 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 end
# set these for all types # set these for all types
@ -138,10 +180,16 @@ function plot!(::PyPlotPackage, plt::Plot; kw...)
extraargs[:label] = d[:label] extraargs[:label] = d[:label]
# do the plot # do the plot
@show lt
if lt == :hist if lt == :hist
d[:serieshandle] = plotfunc(d[:y]; extraargs...) d[:serieshandle] = plotfunc(d[:y]; extraargs...)[1]
else elseif lt in (:scatter, :heatmap, :hexbin)
d[:serieshandle] = plotfunc(d[:x], d[:y]; extraargs...) 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 end
# this sets the bg color inside the grid (plt.o.o == matplotlib.Figure) # 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 # gotta do this to ensure both axes are included
args = filter(x -> !(x[:linetype] in (:hist,:hexbin,:heatmap)), plt.seriesargs) args = filter(x -> !(x[:linetype] in (:hist,:hexbin,:heatmap)), plt.seriesargs)
if length(args) > 0 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
end end
# catch ex # catch ex

View File

@ -13,9 +13,9 @@ function adjustQwtKeywords(iscreating::Bool; kw...)
if d[:linetype] == :hexbin if d[:linetype] == :hexbin
d[:linetype] = :heatmap d[:linetype] = :heatmap
elseif d[:linetype] == :dots elseif d[:linetype] == :scatter
d[:linetype] = :none d[:linetype] = :none
d[:marker] = :hexagon d[:marker] = :ellipse
elseif !iscreating && d[:linetype] == :bar elseif !iscreating && d[:linetype] == :bar
return barHack(; kw...) return barHack(; kw...)
elseif !iscreating && d[:linetype] == :hist elseif !iscreating && d[:linetype] == :hist
@ -58,6 +58,8 @@ function buildSubplotObject!(::QwtPackage, subplt::Subplot)
i += rowcnt i += rowcnt
end end
subplt.o = Qwt.vsplitter(rows...) 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 end
@ -65,6 +67,7 @@ function Base.display(::QwtPackage, subplt::Subplot)
for plt in subplt.plts for plt in subplt.plts
Qwt.refresh(plt.o) Qwt.refresh(plt.o)
end end
Qwt.showwidget(subplt.o) Qwt.showwidget(subplt.o)
end end

View File

@ -9,7 +9,7 @@ immutable [PkgName]Package <: PlottingPackage end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
supportedArgs(::[PkgName]Package) = ARGS
supportedAxes(::[PkgName]Package) = AXES supportedAxes(::[PkgName]Package) = AXES
supportedTypes(::[PkgName]Package) = TYPES supportedTypes(::[PkgName]Package) = TYPES
supportedStyles(::[PkgName]Package) = STYLES 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) function expandLimits!(lims, x)
e1, e2 = extrema(x) e1, e2 = extrema(x)
lims[1] = min(lims[1], e1) lims[1] = min(lims[1], e1)
@ -61,7 +68,7 @@ function addUnicodeSeries!(o, d::Dict, addlegend::Bool)
stepstyle = :post stepstyle = :post
if lt == :line if lt == :line
func = UnicodePlots.lineplot! func = UnicodePlots.lineplot!
elseif lt == :dots || d[:marker] != :none elseif lt == :scatter || d[:marker] != :none
func = UnicodePlots.scatterplot! func = UnicodePlots.scatterplot!
elseif lt == :step elseif lt == :step
func = UnicodePlots.stairs! 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) 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 label # string or symbol, applies to that line, may go in a legend
width # width of a line 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 linestyle # :solid, :dash, :dot, :dashdot, :dashdotdot
marker # :none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon marker # :none, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon
markercolor # same choices as `color` markercolor # same choices as `color`
@ -92,6 +92,13 @@ function plot(args...; kw...)
plot!(plt, args...; kw...) # add to it plot!(plt, args...; kw...) # add to it
end end
function plot_display(args...; kw...)
plt = plot(args...; kw...)
display(plt)
plt
end
# this adds to the current plot # this adds to the current plot
function plot!(args...; kw...) function plot!(args...; kw...)
plot!(currentPlot(), args...; kw...) plot!(currentPlot(), args...; kw...)
@ -168,7 +175,7 @@ function createKWargsList{T<:Real,S<:Real}(plt::PlottingObject, x::AVec{T}, y::A
end end
# create m series, 1 for each column of y # 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) n,m = size(y)
ret = [] ret = []
for i in 1:m for i in 1:m
@ -181,7 +188,7 @@ function createKWargsList(plt::PlottingObject, y::AMat; kw...)
end end
# create m series, 1 for each column of y # 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) n,m = size(y)
@assert length(x) == n @assert length(x) == n
ret = [] ret = []
@ -195,7 +202,7 @@ function createKWargsList(plt::PlottingObject, x::AVec, y::AMat; kw...)
end end
# create m series, 1 for each column of y # 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) @assert size(x) == size(y)
n,m = size(y) n,m = size(y)
ret = [] ret = []
@ -248,16 +255,16 @@ function createKWargsList(plt::PlottingObject, fx::Function, fy::Function, umin:
end end
# create 1 series, y = f(x) # 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 = getPlotKeywordArgs(plt.plotter, kw, 1, plt.n + 1)
d[:x] = x d[:x] = x
d[:y] = map(f, x) d[:y] = map(f, x)
[d] [d]
end 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 # 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) n,m = size(x)
ret = [] ret = []
for i in 1:m for i in 1:m
@ -268,7 +275,7 @@ function createKWargsList(plt::PlottingObject, x::AMat, f::Function; kw...)
end end
ret ret
end 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 ret
end 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]) # same, but m series of (x[i],y[i])
function createKWargsList(plt::PlottingObject, x::AVec, y::AVec; kw...) function createKWargsList(plt::PlottingObject, x::AVec, y::AVec; kw...)
@assert length(x) == length(y) @assert length(x) == length(y)

View File

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