working on massive naming overhaul and fixes

This commit is contained in:
Thomas Breloff 2015-09-28 14:58:56 -04:00
parent 3334c4a87a
commit 3a7887d003
29 changed files with 256 additions and 157 deletions

View File

@ -43,7 +43,7 @@ Pkg.add("Winston")
## Use ## Use
Load it in. The underlying plotting backends are not imported until `plotter()` is called (which happens Load it in. The underlying plotting backends are not imported until `backend()` is called (which happens
on your first call to `plot` or `subplot`). This means that you don't need any backends to be installed when you call `using Plots`. on your first call to `plot` or `subplot`). This means that you don't need any backends to be installed when you call `using Plots`.
Plots will try to figure out a good default backend for you automatically based on what backends are installed. Plots will try to figure out a good default backend for you automatically based on what backends are installed.
@ -54,7 +54,7 @@ using Plots
Do a plot in Gadfly (inspired by [this example](http://gadflyjl.org/geom_point.html)), then save a png: Do a plot in Gadfly (inspired by [this example](http://gadflyjl.org/geom_point.html)), then save a png:
```julia ```julia
gadfly!() # switch to Gadfly as a backend gadfly() # switch to Gadfly as a backend
dataframes!() # turn on support for DataFrames inputs dataframes!() # turn on support for DataFrames inputs
# load some data # load some data
@ -72,21 +72,21 @@ Also check out the [IJulia notebooks](examples) and see how it works interactive
## API ## API
Call `plotter!(backend::Symbol)` or the shorthands (`gadfly!()`, `qwt!()`, `unicodeplots!()`, etc) to set the current plotting backend. Call `backend(backend::Symbol)` or the shorthands (`gadfly()`, `qwt()`, `unicodeplots()`, etc) to set the current plotting backend.
Subsequent commands are converted into the relevant plotting commands for that package: Subsequent commands are converted into the relevant plotting commands for that package:
```julia ```julia
gadfly!() gadfly()
plot(1:10) # this effectively calls `y = 1:10; Gadfly.plot(x=1:length(y), y=y)` plot(1:10) # this effectively calls `y = 1:10; Gadfly.plot(x=1:length(y), y=y)`
qwt!() qwt()
plot(1:10) # this effectively calls `Qwt.plot(1:10)` plot(1:10) # this effectively calls `Qwt.plot(1:10)`
``` ```
Use `plot` to create a new plot object, and `plot!` to add to an existing one: Use `plot` to create a new plot object, and `plot!` to add to an existing one:
```julia ```julia
plot(args...; kw...) # creates a new plot window, and sets it to be the `currentPlot` plot(args...; kw...) # creates a new plot window, and sets it to be the `current`
plot!(args...; kw...) # adds to the `currentPlot` plot!(args...; kw...) # adds to the `current`
plot!(plotobj, args...; kw...) # adds to the plot `plotobj` plot!(plotobj, args...; kw...) # adds to the plot `plotobj`
``` ```
@ -104,7 +104,7 @@ In general, you can pass in a `y` only, or an `x` and `y`, both of whatever type
For matrices, data is split by columns. For functions, data is mapped. For DataFrames, a Symbol/Symbols in place of x/y will map to For matrices, data is split by columns. For functions, data is mapped. For DataFrames, a Symbol/Symbols in place of x/y will map to
the relevant column(s). the relevant column(s).
Here are some example usages... remember you can always use `plot!` to update an existing plot, and that, unless specified, you will update the `currentPlot()`. Here are some example usages... remember you can always use `plot!` to update an existing plot, and that, unless specified, you will update the `current()`.
```julia ```julia
plot() # empty plot object plot() # empty plot object
@ -162,9 +162,9 @@ vline!(args...; kw...) = plot!(args...; kw..., linetype = :vline)
ohlc(args...; kw...) = plot(args...; kw..., linetype = :ohlc) ohlc(args...; kw...) = plot(args...; kw..., linetype = :ohlc)
ohlc!(args...; kw...) = plot!(args...; kw..., linetype = :ohlc) ohlc!(args...; kw...) = plot!(args...; kw..., linetype = :ohlc)
title!(s::AbstractString) = plot!(title = s) title(s::AbstractString) = plot!(title = s)
xlabel!(s::AbstractString) = plot!(xlabel = s) xlabel(s::AbstractString) = plot!(xlabel = s)
ylabel!(s::AbstractString) = plot!(ylabel = s) ylabel(s::AbstractString) = plot!(ylabel = s)
xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims) xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims)
ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims) ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims)
xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v) xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v)
@ -262,7 +262,7 @@ Type | Aliases
__Tip__: You can see the default value for a given argument with `plotDefault(arg::Symbol)`, and set the default value with `plotDefault!(arg::Symbol, value)` __Tip__: You can see the default value for a given argument with `default(arg::Symbol)`, and set the default value with `default(arg::Symbol, value)`
__Tip__: When plotting multiple lines, you can set all series to use the same value, or pass in an array to cycle through values. Example: __Tip__: When plotting multiple lines, you can set all series to use the same value, or pass in an array to cycle through values. Example:

View File

@ -105,9 +105,9 @@ createStringOfMarkDownSymbols(arr) = isempty(arr) ? "" : createStringOfMarkDownC
function generate_markdown(pkgname::Symbol) function generate_markdown(pkgname::Symbol)
# set up the plotter, and don't show the plots by default # set up the backend, and don't show the plots by default
pkg = plotter!(pkgname) pkg = backend(pkgname)
# plotDefault!(:show, false) # default(:show, false)
# mkdir if necessary # mkdir if necessary
try try
@ -166,10 +166,10 @@ end
# make and display one plot # make and display one plot
function test_example(pkgname::Symbol, idx::Int) function test_example(pkgname::Symbol, idx::Int)
println("Testing plot: $pkgname:$idx:$(examples[idx].header)") println("Testing plot: $pkgname:$idx:$(examples[idx].header)")
plotter!(pkgname) backend(pkgname)
plotter() backend()
map(eval, examples[idx].exprs) map(eval, examples[idx].exprs)
plt = currentPlot() plt = current()
gui(plt) gui(plt)
plt plt
end end

View File

@ -11,7 +11,7 @@
```julia ```julia
using Plots using Plots
gadfly!() gadfly()
``` ```
### Lines ### Lines

View File

@ -11,7 +11,7 @@
```julia ```julia
using Plots using Plots
immerse!() immerse()
``` ```
### Lines ### Lines

View File

@ -11,7 +11,7 @@
```julia ```julia
using Plots using Plots
pyplot!() pyplot()
``` ```
### Lines ### Lines

View File

@ -11,7 +11,7 @@
```julia ```julia
using Plots using Plots
qwt!() qwt()
``` ```
### Lines ### Lines

View File

@ -43,7 +43,7 @@ Pkg.add("Winston")
## Use ## Use
Load it in. The underlying plotting backends are not imported until `plotter()` is called (which happens Load it in. The underlying plotting backends are not imported until `backend()` is called (which happens
on your first call to `plot` or `subplot`). This means that you don't need any backends to be installed when you call `using Plots`. on your first call to `plot` or `subplot`). This means that you don't need any backends to be installed when you call `using Plots`.
Plots will try to figure out a good default backend for you automatically based on what backends are installed. Plots will try to figure out a good default backend for you automatically based on what backends are installed.
@ -54,8 +54,8 @@ using Plots
Do a plot in Gadfly (inspired by [this example](http://gadflyjl.org/geom_point.html)), then save a png: Do a plot in Gadfly (inspired by [this example](http://gadflyjl.org/geom_point.html)), then save a png:
```julia ```julia
gadfly!() # switch to Gadfly as a backend gadfly() # switch to Gadfly as a backend
dataframes!() # turn on support for DataFrames inputs dataframes() # turn on support for DataFrames inputs
# load some data # load some data
using RDatasets using RDatasets
@ -72,21 +72,21 @@ Also check out the [IJulia notebooks](examples) and see how it works interactive
## API ## API
Call `plotter!(backend::Symbol)` or the shorthands (`gadfly!()`, `qwt!()`, `unicodeplots!()`, etc) to set the current plotting backend. Call `backend(backend::Symbol)` or the shorthands (`gadfly()`, `qwt()`, `unicodeplots()`, etc) to set the current plotting backend.
Subsequent commands are converted into the relevant plotting commands for that package: Subsequent commands are converted into the relevant plotting commands for that package:
```julia ```julia
gadfly!() gadfly()
plot(1:10) # this effectively calls `y = 1:10; Gadfly.plot(x=1:length(y), y=y)` plot(1:10) # this effectively calls `y = 1:10; Gadfly.plot(x=1:length(y), y=y)`
qwt!() qwt()
plot(1:10) # this effectively calls `Qwt.plot(1:10)` plot(1:10) # this effectively calls `Qwt.plot(1:10)`
``` ```
Use `plot` to create a new plot object, and `plot!` to add to an existing one: Use `plot` to create a new plot object, and `plot!` to add to an existing one:
```julia ```julia
plot(args...; kw...) # creates a new plot window, and sets it to be the `currentPlot` plot(args...; kw...) # creates a new plot window, and sets it to be the `current`
plot!(args...; kw...) # adds to the `currentPlot` plot!(args...; kw...) # adds to the `current`
plot!(plotobj, args...; kw...) # adds to the plot `plotobj` plot!(plotobj, args...; kw...) # adds to the plot `plotobj`
``` ```
@ -98,13 +98,13 @@ There are many ways to pass in data to the plot functions... some examples:
- Vectors of Vectors - Vectors of Vectors
- Functions - Functions
- Vectors of Functions - Vectors of Functions
- DataFrames with column symbols (initialize with `dataframes!()`) - DataFrames with column symbols (initialize with `dataframes()`)
In general, you can pass in a `y` only, or an `x` and `y`, both of whatever type(s) you want, and Plots will slice up the data as needed. In general, you can pass in a `y` only, or an `x` and `y`, both of whatever type(s) you want, and Plots will slice up the data as needed.
For matrices, data is split by columns. For functions, data is mapped. For DataFrames, a Symbol/Symbols in place of x/y will map to For matrices, data is split by columns. For functions, data is mapped. For DataFrames, a Symbol/Symbols in place of x/y will map to
the relevant column(s). the relevant column(s).
Here are some example usages... remember you can always use `plot!` to update an existing plot, and that, unless specified, you will update the `currentPlot()`. Here are some example usages... remember you can always use `plot!` to update an existing plot, and that, unless specified, you will update the `current()`.
```julia ```julia
plot() # empty plot object plot() # empty plot object
@ -118,7 +118,7 @@ plot(rand(10), sin) # same... y = sin(x)
plot([sin,cos], 0:0.1:π) # plot 2 series, sin(x) and cos(x) plot([sin,cos], 0:0.1:π) # plot 2 series, sin(x) and cos(x)
plot([sin,cos], 0, π) # plot sin and cos on the range [0, π] plot([sin,cos], 0, π) # plot sin and cos on the range [0, π]
plot(1:10, Any[rand(10), sin]) # plot 2 series, y = rand(10) for the first, y = sin(x) for the second... x = 1:10 for both plot(1:10, Any[rand(10), sin]) # plot 2 series, y = rand(10) for the first, y = sin(x) for the second... x = 1:10 for both
plot(dataset("Ecdat", "Airline"), :Cost) # plot from a DataFrame (call `dataframes!()` first to import DataFrames and initialize) plot(dataset("Ecdat", "Airline"), :Cost) # plot from a DataFrame (call `dataframes()` first to import DataFrames and initialize)
``` ```
You can update certain plot settings after plot creation (not supported on all backends): You can update certain plot settings after plot creation (not supported on all backends):
@ -169,7 +169,7 @@ xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims)
ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims) ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims)
xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v) xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v)
yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = v) yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = v)
annotate!(annotations) = plot!(annotation = annotations) annotate!(anns) = plot!(annotation = anns)
``` ```
Some keyword arguments you can set: Some keyword arguments you can set:
@ -189,7 +189,7 @@ Markers:
[[MARKERS_TABLE]] [[MARKERS_TABLE]]
__Tip__: You can see the default value for a given argument with `plotDefault(arg::Symbol)`, and set the default value with `plotDefault!(arg::Symbol, value)` __Tip__: You can see the default value for a given argument with `default(arg::Symbol)`, and set the default value with `default(arg::Symbol, value)`
__Tip__: When plotting multiple lines, you can set all series to use the same value, or pass in an array to cycle through values. Example: __Tip__: When plotting multiple lines, you can set all series to use the same value, or pass in an array to cycle through values. Example:

View File

@ -11,7 +11,7 @@
```julia ```julia
using Plots using Plots
unicodeplots!() unicodeplots()
``` ```
### Lines ### Lines

View File

@ -11,7 +11,7 @@
```julia ```julia
using Plots using Plots
winston!() winston()
``` ```
### Lines ### Lines

View File

@ -35,8 +35,8 @@
} }
], ],
"source": [ "source": [
"using Plots; winston!()\n", "using Plots; winston()\n",
"plotDefault!(size=(600,400),leg=false)\n", "default(size=(600,400),leg=false)\n",
"y = rand(10)\n", "y = rand(10)\n",
"plot(y, ann=[(3,y[3],\"this is #3\"), (8,y[8],\"this is #8\")])" "plot(y, ann=[(3,y[3],\"this is #3\"), (8,y[8],\"this is #8\")])"
] ]

View File

@ -35,9 +35,9 @@
} }
], ],
"source": [ "source": [
"using RDatasets, Plots; dataframes!()\n", "using RDatasets, Plots; dataframes()\n",
"iris = dataset(\"datasets\", \"iris\");\n", "iris = dataset(\"datasets\", \"iris\");\n",
"plotDefault!(size=(600,400));" "default(size=(600,400));"
] ]
}, },
{ {
@ -49,7 +49,7 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"gadfly!();\n", "gadfly();\n",
"scatter(iris, :SepalLength, :SepalWidth, group=:Species, ms=12, m=[:+,:h,:s])" "scatter(iris, :SepalLength, :SepalWidth, group=:Species, ms=12, m=[:+,:h,:s])"
] ]
}, },
@ -65,7 +65,7 @@
"\n", "\n",
"plot!(u->6+2*sin(u), u->3+cos(u), 0, 2π, lab=\"an oval\", fill=3)\n", "plot!(u->6+2*sin(u), u->3+cos(u), 0, 2π, lab=\"an oval\", fill=3)\n",
"plot!(Any[[6],[3]], t=[:vline,:hline], w=4, c=RGB(1,0,0))\n", "plot!(Any[[6],[3]], t=[:vline,:hline], w=4, c=RGB(1,0,0))\n",
"title!(\"Playing around with series\")" "title(\"Playing around with series\")"
] ]
}, },
{ {

View File

@ -34,7 +34,7 @@
} }
], ],
"source": [ "source": [
"using Plots; gadfly!(); plotDefault!(size=(400,300),leg=false)\n", "using Plots; gadfly(); default(size=(400,300),leg=false)\n",
"n = 10\n", "n = 10\n",
"#cs = distinguishable_colors(n)\n", "#cs = distinguishable_colors(n)\n",
"cs = [colorant\"red\",colorant\"blue\",colorant\"yellow\",colorant\"blue\"]\n", "cs = [colorant\"red\",colorant\"blue\",colorant\"yellow\",colorant\"blue\"]\n",
@ -89,8 +89,8 @@
} }
], ],
"source": [ "source": [
"using Plots; qwt!()\n", "using Plots; qwt()\n",
"plotDefault!(:size, (500,300));" "default(:size, (500,300));"
] ]
}, },
{ {
@ -268,7 +268,7 @@
} }
], ],
"source": [ "source": [
"using Plots; gadfly!()\n", "using Plots; gadfly()\n",
"plot(cumsum(randn(100,5),1), w=8, style=:auto)\n", "plot(cumsum(randn(100,5),1), w=8, style=:auto)\n",
"plot!(rand(1,10)*10, style=:auto, t=[:hline,:vline])" "plot!(rand(1,10)*10, style=:auto, t=[:hline,:vline])"
] ]

View File

@ -8,7 +8,7 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"using Plots; pyplot!()" "using Plots; pyplot()"
] ]
}, },
{ {
@ -39,8 +39,8 @@
} }
], ],
"source": [ "source": [
"using Plots; immerse!()\n", "using Plots; immerse()\n",
"plotDefault!(:size, (500,300));" "default(:size, (500,300));"
] ]
}, },
{ {

View File

@ -1,5 +1,55 @@
{ {
"cells": [ "cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[Plots.jl] Switched to backend: gadfly"
]
},
{
"ename": "MethodError",
"evalue": "MethodError: `isless` has no method matching isless(::ASCIIString, ::Int64)\nClosest candidates are:\n isless(!Matched::AbstractFloat, ::Real)\n isless(!Matched::Real, ::Real)\n isless(!Matched::Char, ::Integer)\n ...",
"output_type": "error",
"traceback": [
"MethodError: `isless` has no method matching isless(::ASCIIString, ::Int64)\nClosest candidates are:\n isless(!Matched::AbstractFloat, ::Real)\n isless(!Matched::Real, ::Real)\n isless(!Matched::Char, ::Integer)\n ...",
"",
" in min at operators.jl:58",
" in apply_statistic at /home/tom/.julia/v0.4/Gadfly/src/statistics.jl:818",
" in apply_statistics at /home/tom/.julia/v0.4/Gadfly/src/statistics.jl:38",
" in render_prepare at /home/tom/.julia/v0.4/Gadfly/src/Gadfly.jl:676",
" in render at /home/tom/.julia/v0.4/Gadfly/src/Gadfly.jl:717",
" in draw at /home/tom/.julia/v0.4/Gadfly/src/Gadfly.jl:821",
" in writemime at /home/tom/.julia/v0.4/Plots/src/backends/gadfly.jl:352",
" in base64encode at base64.jl:160",
" in display_dict at /home/tom/.julia/v0.4/IJulia/src/execute_request.jl:32"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"ticks = Union{ASCIIString,UTF8String}[\"x01\",\"x02\",\"x03\",\"x04\",\"x05\",\"x06\",\"x07\",\"x08\",\"x09\",\"x10\"]\n"
]
}
],
"source": [
"using Plots, StatsBase\n",
"gadfly()\n",
"xstr = [@sprintf(\"x%02d\",i) for i in 1:10]\n",
"x = sort(sample(xstr, 100))\n",
"y = rand(length(x))\n",
"scatter(x,y)"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
@ -7,9 +57,7 @@
"collapsed": true "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": []
"using Plots; gadfly!()"
]
} }
], ],
"metadata": { "metadata": {

View File

@ -6,19 +6,16 @@ using Reexport
@reexport using Colors @reexport using Colors
export export
plotter,
plotter!,
plot, plot,
plot!, plot!,
plot_display, # plot_display,
plot_display!, # plot_display!,
subplot, subplot,
subplot!, subplot!,
currentPlot, current,
currentPlot!, default,
plotDefault,
plotDefault!,
scatter, scatter,
scatter!, scatter!,
bar, bar,
@ -48,9 +45,10 @@ export
savepng, savepng,
gui, gui,
backend,
backends, backends,
aliases, aliases,
dataframes!, dataframes,
OHLC, OHLC,
supportedArgs, supportedArgs,
@ -119,13 +117,13 @@ annotate!(plt::Plot, anns) = plot!(plt; annotation =
# --------------------------------------------------------- # ---------------------------------------------------------
savepng(args...; kw...) = savepng(currentPlot(), args...; kw...) savepng(args...; kw...) = savepng(current(), args...; kw...)
savepng(plt::PlottingObject, fn::AbstractString; kw...) = (io = open(fn, "w"); writemime(io, MIME("image/png"), plt); close(io)) savepng(plt::PlottingObject, fn::AbstractString; kw...) = (io = open(fn, "w"); writemime(io, MIME("image/png"), plt); close(io))
# savepng(plt::PlottingObject, args...; kw...) = savepng(plt.plotter, plt, args...; kw...) # savepng(plt::PlottingObject, args...; kw...) = savepng(plt.backend, plt, args...; kw...)
# savepng(::PlottingPackage, plt::PlottingObject, fn::AbstractString, args...) = error("unsupported") # fallback so multiple dispatch doesn't get confused if it's missing # savepng(::PlottingPackage, plt::PlottingObject, fn::AbstractString, args...) = error("unsupported") # fallback so multiple dispatch doesn't get confused if it's missing
gui(plt::PlottingObject = currentPlot()) = display(PlotsDisplay(), plt) gui(plt::PlottingObject = current()) = display(PlotsDisplay(), plt)
# override the REPL display to open a gui window # override the REPL display to open a gui window

View File

@ -79,11 +79,11 @@ supportedStyles(::PlottingPackage) = _allStyles
supportedMarkers(::PlottingPackage) = _allMarkers supportedMarkers(::PlottingPackage) = _allMarkers
subplotSupported(::PlottingPackage) = true subplotSupported(::PlottingPackage) = true
supportedAxes() = supportedAxes(plotter()) supportedAxes() = supportedAxes(backend())
supportedTypes() = supportedTypes(plotter()) supportedTypes() = supportedTypes(backend())
supportedStyles() = supportedStyles(plotter()) supportedStyles() = supportedStyles(backend())
supportedMarkers() = supportedMarkers(plotter()) supportedMarkers() = supportedMarkers(backend())
subplotSupported() = subplotSupported(plotter()) subplotSupported() = subplotSupported(backend())
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -126,8 +126,13 @@ _plotDefaults[:ylims] = :auto
_plotDefaults[:xticks] = :auto _plotDefaults[:xticks] = :auto
_plotDefaults[:yticks] = :auto _plotDefaults[:yticks] = :auto
_plotDefaults[:size] = (800,600) _plotDefaults[:size] = (800,600)
_plotDefaults[:pos] = (0,0)
_plotDefaults[:windowtitle] = "Plots.jl" _plotDefaults[:windowtitle] = "Plots.jl"
_plotDefaults[:show] = false _plotDefaults[:show] = false
_plotDefaults[:layout] = nothing
_plotDefaults[:n] = -1
_plotDefaults[:nr] = -1
_plotDefaults[:nc] = -1
@ -135,7 +140,7 @@ _plotDefaults[:show] = false
const _allArgs = sort(collect(union(keys(_seriesDefaults), keys(_plotDefaults)))) const _allArgs = sort(collect(union(keys(_seriesDefaults), keys(_plotDefaults))))
supportedArgs(::PlottingPackage) = _allArgs supportedArgs(::PlottingPackage) = _allArgs
supportedArgs() = supportedArgs(plotter()) supportedArgs() = supportedArgs(backend())
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -235,7 +240,13 @@ end
# update the defaults globally # update the defaults globally
function plotDefault(k::Symbol) """
`default(key)` returns the current default value for that key
`default(key, value)` sets the current default value for that key
`default(; kw...)` will set the current default value for each key/value pair
"""
function default(k::Symbol)
k = get(_keyAliases, k, k) k = get(_keyAliases, k, k)
if haskey(_seriesDefaults, k) if haskey(_seriesDefaults, k)
return _seriesDefaults[k] return _seriesDefaults[k]
@ -246,7 +257,7 @@ function plotDefault(k::Symbol)
end end
end end
function plotDefault!(k::Symbol, v) function default(k::Symbol, v)
k = get(_keyAliases, k, k) k = get(_keyAliases, k, k)
if haskey(_seriesDefaults, k) if haskey(_seriesDefaults, k)
_seriesDefaults[k] = v _seriesDefaults[k] = v
@ -257,9 +268,9 @@ function plotDefault!(k::Symbol, v)
end end
end end
function plotDefault!(; kw...) function default(; kw...)
for (k,v) in kw for (k,v) in kw
plotDefault!(k, v) default(k, v)
end end
end end
@ -297,7 +308,7 @@ end
function warnOnUnsupportedArgs(pkg::PlottingPackage, d::Dict) function warnOnUnsupportedArgs(pkg::PlottingPackage, d::Dict)
for k in sortedkeys(d) for k in sortedkeys(d)
if !(k in supportedArgs(pkg)) if !(k in supportedArgs(pkg)) && d[k] != default(k)
warn("Keyword argument $k not supported with $pkg. Choose from: $(supportedArgs(pkg))") warn("Keyword argument $k not supported with $pkg. Choose from: $(supportedArgs(pkg))")
end end
end end

View File

@ -3,11 +3,52 @@
immutable GadflyPackage <: PlottingPackage end immutable GadflyPackage <: PlottingPackage end
export gadfly! export gadfly
gadfly!() = plotter!(:gadfly) gadfly() = backend(:gadfly)
supportedArgs(::GadflyPackage) = setdiff(_allArgs, [:heatmap_c, :pos, :screen, :yrightlabel]) # supportedArgs(::GadflyPackage) = setdiff(_allArgs, [:heatmap_c, :pos, :screen, :yrightlabel])
supportedArgs(::GadflyPackage) = [
:annotation,
:args,
:axis,
:background_color,
:color,
:fillto,
:foreground_color,
:group,
# :heatmap_c,
:kwargs,
:label,
:layout,
:legend,
:linestyle,
:linetype,
:marker,
:markercolor,
:markersize,
:n,
:nbins,
:nc,
:nr,
# :pos,
:reg,
# :ribbon,
:show,
:size,
:title,
:width,
:windowtitle,
:x,
:xlabel,
:xlims,
:xticks,
:y,
:ylabel,
:ylims,
# :yrightlabel,
:yticks,
]
supportedAxes(::GadflyPackage) = [:auto, :left] supportedAxes(::GadflyPackage) = [:auto, :left]
supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc] supportedTypes(::GadflyPackage) = [:none, :line, :path, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] supportedStyles(::GadflyPackage) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
@ -336,7 +377,7 @@ function buildGadflySubplotContext(subplt::Subplot)
i = 0 i = 0
rows = [] rows = []
for rowcnt in subplt.layout.rowcounts for rowcnt in subplt.layout.rowcounts
push!(rows, Gadfly.hstack([getGadflyContext(plt.plotter, plt) for plt in subplt.plts[(1:rowcnt) + i]]...)) push!(rows, Gadfly.hstack([getGadflyContext(plt.backend, plt) for plt in subplt.plts[(1:rowcnt) + i]]...))
i += rowcnt i += rowcnt
end end
Gadfly.vstack(rows...) Gadfly.vstack(rows...)
@ -347,7 +388,7 @@ function setGadflyDisplaySize(w,h)
end end
function Base.writemime(io::IO, ::MIME"image/png", plt::Plot{GadflyPackage}) function Base.writemime(io::IO, ::MIME"image/png", plt::Plot{GadflyPackage})
gplt = getGadflyContext(plt.plotter, plt) gplt = getGadflyContext(plt.backend, plt)
setGadflyDisplaySize(plt.initargs[:size]...) setGadflyDisplaySize(plt.initargs[:size]...)
Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt) Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end end
@ -361,7 +402,7 @@ end
function Base.writemime(io::IO, ::MIME"image/png", plt::Subplot{GadflyPackage}) function Base.writemime(io::IO, ::MIME"image/png", plt::Subplot{GadflyPackage})
gplt = getGadflyContext(plt.plotter, plt) gplt = getGadflyContext(plt.backend, plt)
setGadflyDisplaySize(plt.initargs[1][:size]...) setGadflyDisplaySize(plt.initargs[1][:size]...)
Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt) Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end end

View File

@ -3,8 +3,8 @@
immutable ImmersePackage <: PlottingPackage end immutable ImmersePackage <: PlottingPackage end
export immerse! export immerse
immerse!() = plotter!(:immerse) immerse() = backend(:immerse)
supportedArgs(::ImmersePackage) = supportedArgs(GadflyPackage()) supportedArgs(::ImmersePackage) = supportedArgs(GadflyPackage())
@ -128,7 +128,7 @@ getGadflyContext(::ImmersePackage, plt::Plot) = plt.o[2]
getGadflyContext(::ImmersePackage, subplt::Subplot) = buildGadflySubplotContext(subplt) getGadflyContext(::ImmersePackage, subplt::Subplot) = buildGadflySubplotContext(subplt)
function Base.writemime(io::IO, ::MIME"image/png", plt::Plot{ImmersePackage}) function Base.writemime(io::IO, ::MIME"image/png", plt::Plot{ImmersePackage})
gplt = getGadflyContext(plt.plotter, plt) gplt = getGadflyContext(plt.backend, plt)
setGadflyDisplaySize(plt.initargs[:size]...) setGadflyDisplaySize(plt.initargs[:size]...)
Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt) Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end end
@ -148,7 +148,7 @@ end
function Base.writemime(io::IO, ::MIME"image/png", plt::Subplot{ImmersePackage}) function Base.writemime(io::IO, ::MIME"image/png", plt::Subplot{ImmersePackage})
gplt = getGadflyContext(plt.plotter, plt) gplt = getGadflyContext(plt.backend, plt)
setGadflyDisplaySize(plt.initargs[1][:size]...) setGadflyDisplaySize(plt.initargs[1][:size]...)
Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt) Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt)
end end

View File

@ -3,8 +3,8 @@
immutable PyPlotPackage <: PlottingPackage end immutable PyPlotPackage <: PlottingPackage end
export pyplot! export pyplot
pyplot!() = plotter!(:pyplot) pyplot() = backend(:pyplot)
# ------------------------------- # -------------------------------

View File

@ -3,8 +3,8 @@
immutable QwtPackage <: PlottingPackage end immutable QwtPackage <: PlottingPackage end
export qwt! export qwt
qwt!() = plotter!(:qwt) qwt() = backend(:qwt)
supportedArgs(::QwtPackage) = setdiff(_allArgs, [:xlims, :ylims, :xticks, :yticks]) supportedArgs(::QwtPackage) = setdiff(_allArgs, [:xlims, :ylims, :xticks, :yticks])
supportedTypes(::QwtPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar] supportedTypes(::QwtPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar]

View File

@ -5,8 +5,8 @@
immutable [PkgName]Package <: PlottingPackage end immutable [PkgName]Package <: PlottingPackage end
export [pkgname]! export [pkgname]
[pkgname]!() = plotter!(:[pkgname]) [pkgname]() = backend(:[pkgname])
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------

View File

@ -3,8 +3,8 @@
immutable UnicodePlotsPackage <: PlottingPackage end immutable UnicodePlotsPackage <: PlottingPackage end
export unicodeplots! export unicodeplots
unicodeplots!() = plotter!(:unicodeplots) unicodeplots() = backend(:unicodeplots)
# ------------------------------- # -------------------------------

View File

@ -5,8 +5,8 @@
immutable WinstonPackage <: PlottingPackage end immutable WinstonPackage <: PlottingPackage end
export winston! export winston
winston!() = plotter!(:winston) winston() = backend(:winston)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------

View File

@ -143,7 +143,7 @@ function handlePlotColors(::PlottingPackage, d::Dict)
else else
bgcolor = _plotDefaults[:background_color] bgcolor = _plotDefaults[:background_color]
if d[:background_color] != _plotDefaults[:background_color] if d[:background_color] != _plotDefaults[:background_color]
warn("Cannot set background_color with backend $(plotter())") warn("Cannot set background_color with backend $(backend())")
end end
end end
d[:background_color] = bgcolor d[:background_color] = bgcolor

View File

@ -6,18 +6,18 @@ const CURRENT_PLOT = CurrentPlot(Nullable{PlottingObject}())
isplotnull() = isnull(CURRENT_PLOT.nullableplot) isplotnull() = isnull(CURRENT_PLOT.nullableplot)
function currentPlot() function current()
if isplotnull() if isplotnull()
error("No current plot/subplot") error("No current plot/subplot")
end end
get(CURRENT_PLOT.nullableplot) get(CURRENT_PLOT.nullableplot)
end end
currentPlot!(plot::PlottingObject) = (CURRENT_PLOT.nullableplot = Nullable(plot)) current(plot::PlottingObject) = (CURRENT_PLOT.nullableplot = Nullable(plot))
# --------------------------------------------------------- # ---------------------------------------------------------
Base.string(plt::Plot) = "Plot{$(plt.plotter) n=$(plt.n)}" Base.string(plt::Plot) = "Plot{$(plt.backend) n=$(plt.n)}"
Base.print(io::IO, plt::Plot) = print(io, string(plt)) Base.print(io::IO, plt::Plot) = print(io, string(plt))
Base.show(io::IO, plt::Plot) = print(io, string(plt)) Base.show(io::IO, plt::Plot) = print(io, string(plt))
@ -32,8 +32,8 @@ doc"""
The main plot command. Use `plot` to create a new plot object, and `plot!` to add to an existing one: The main plot command. Use `plot` to create a new plot object, and `plot!` to add to an existing one:
``` ```
plot(args...; kw...) # creates a new plot window, and sets it to be the currentPlot plot(args...; kw...) # creates a new plot window, and sets it to be the current
plot!(args...; kw...) # adds to the `currentPlot` plot!(args...; kw...) # adds to the `current`
plot!(plotobj, args...; kw...) # adds to the plot `plotobj` plot!(plotobj, args...; kw...) # adds to the plot `plotobj`
``` ```
@ -43,7 +43,7 @@ When you pass in matrices, it splits by columns. See the documentation for more
# 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...)
pkg = plotter() pkg = backend()
d = Dict(kw) d = Dict(kw)
replaceAliases!(d, _keyAliases) replaceAliases!(d, _keyAliases)
@ -59,15 +59,15 @@ function plot(args...; kw...)
end end
function plot_display(args...; kw...) # function plot_display(args...; kw...)
plt = plot(args...; kw...) # plt = plot(args...; kw...)
display(plt) # display(plt)
plt # plt
end # 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!(current(), args...; kw...)
end end
# not allowed: # not allowed:
@ -81,14 +81,14 @@ function plot!(plt::Plot, args...; kw...)
d = Dict(kw) d = Dict(kw)
replaceAliases!(d, _keyAliases) replaceAliases!(d, _keyAliases)
warnOnUnsupportedArgs(plt.plotter, d) warnOnUnsupportedArgs(plt.backend, d)
# TODO: handle a "group by" mechanism. # TODO: handle a "group by" mechanism.
# will probably want to check for the :group kw param, and split into # will probably want to check for the :group kw param, and split into
# index partitions/filters to be passed through to the next step. # index partitions/filters to be passed through to the next step.
# Ideally we don't change the insides ot createKWargsList too much to # Ideally we don't change the insides ot createKWargsList too much to
# save from code repetition. We could consider adding a throw # save from code repetition. We could consider adding a throw
groupargs = haskey(d, :group) ? [extractGroupArgs(d[:group], args...)] : [] groupargs = get(d, :group, nothing) == nothing ? [] : [extractGroupArgs(d[:group], args...)]
# @show groupargs # @show groupargs
# just in case the backend needs to set up the plot (make it current or something) # just in case the backend needs to set up the plot (make it current or something)
@ -110,7 +110,7 @@ function plot!(plt::Plot, args...; kw...)
setTicksFromStringVector(d, di, :y, :yticks) setTicksFromStringVector(d, di, :y, :yticks)
# println("Plotting: ", di) # println("Plotting: ", di)
plot!(plt.plotter, plt; di...) plot!(plt.backend, plt; di...)
end end
@ -118,7 +118,7 @@ function plot!(plt::Plot, args...; kw...)
# add title, axis labels, ticks, etc # add title, axis labels, ticks, etc
updatePlotItems(plt, d) updatePlotItems(plt, d)
currentPlot!(plt) current(plt)
# NOTE: lets ignore the show param and effectively use the semicolon at the end of the REPL statement # NOTE: lets ignore the show param and effectively use the semicolon at the end of the REPL statement
# # do we want to show it? # # do we want to show it?
@ -153,7 +153,7 @@ preparePlotUpdate(plt::Plot) = nothing
# should we update the x/y label given the meta info during input slicing? # should we update the x/y label given the meta info during input slicing?
function updateDictWithMeta(d::Dict, initargs::Dict, meta::Symbol, isx::Bool) function updateDictWithMeta(d::Dict, initargs::Dict, meta::Symbol, isx::Bool)
lsym = isx ? :xlabel : :ylabel lsym = isx ? :xlabel : :ylabel
if initargs[lsym] == plotDefault(lsym) if initargs[lsym] == default(lsym)
d[lsym] = string(meta) d[lsym] = string(meta)
end end
end end
@ -254,7 +254,7 @@ function createKWargsList(plt::PlottingObject, x, y; kw...)
# build the series arg dict # build the series arg dict
numUncounted = get(d, :numUncounted, 0) numUncounted = get(d, :numUncounted, 0)
n = plt.n + i + numUncounted n = plt.n + i + numUncounted
d = getSeriesArgs(plt.plotter, getinitargs(plt, n), d, i + numUncounted, convertSeriesIndex(plt, n), n) d = getSeriesArgs(plt.backend, getinitargs(plt, n), d, i + numUncounted, convertSeriesIndex(plt, n), n)
d[:x], d[:y] = computeXandY(xs[mod1(i,mx)], ys[mod1(i,my)]) d[:x], d[:y] = computeXandY(xs[mod1(i,mx)], ys[mod1(i,my)])
if haskey(d, :idxfilter) if haskey(d, :idxfilter)
@ -343,7 +343,7 @@ end
# -------------------------------------------------------------------- # --------------------------------------------------------------------
"For DataFrame support. Imports DataFrames and defines the necessary methods which support them." "For DataFrame support. Imports DataFrames and defines the necessary methods which support them."
function dataframes!() function dataframes()
@eval import DataFrames @eval import DataFrames
@eval function createKWargsList(plt::PlottingObject, df::DataFrames.DataFrame, args...; kw...) @eval function createKWargsList(plt::PlottingObject, df::DataFrames.DataFrame, args...; kw...)

View File

@ -28,7 +28,7 @@ const INITIALIZED_BACKENDS = Set{Symbol}()
backends() = BACKENDS backends() = BACKENDS
function backend(sym::Symbol) function backendInstance(sym::Symbol)
sym == :qwt && return QwtPackage() sym == :qwt && return QwtPackage()
sym == :gadfly && return GadflyPackage() sym == :gadfly && return GadflyPackage()
sym == :unicodeplots && return UnicodePlotsPackage() sym == :unicodeplots && return UnicodePlotsPackage()
@ -43,7 +43,7 @@ type CurrentBackend
sym::Symbol sym::Symbol
pkg::PlottingPackage pkg::PlottingPackage
end end
CurrentBackend(sym::Symbol) = CurrentBackend(sym, backend(sym)) CurrentBackend(sym::Symbol) = CurrentBackend(sym, backendInstance(sym))
# --------------------------------------------------------- # ---------------------------------------------------------
@ -90,7 +90,7 @@ end
doc""" doc"""
Returns the current plotting package name. Initializes package on first call. Returns the current plotting package name. Initializes package on first call.
""" """
function plotter() function backend()
currentBackendSymbol = CURRENT_BACKEND.sym currentBackendSymbol = CURRENT_BACKEND.sym
if !(currentBackendSymbol in INITIALIZED_BACKENDS) if !(currentBackendSymbol in INITIALIZED_BACKENDS)
@ -149,7 +149,7 @@ function plotter()
end end
else else
error("Unknown plotter $currentBackendSymbol. Choose from: $BACKENDS") error("Unknown backend $currentBackendSymbol. Choose from: $BACKENDS")
end end
push!(INITIALIZED_BACKENDS, currentBackendSymbol) push!(INITIALIZED_BACKENDS, currentBackendSymbol)
# println("[Plots.jl] done.") # println("[Plots.jl] done.")
@ -161,7 +161,7 @@ end
doc""" doc"""
Set the plot backend. Choose from: :qwt, :gadfly, :unicodeplots Set the plot backend. Choose from: :qwt, :gadfly, :unicodeplots
""" """
function plotter!(modname) function backend(modname)
# set the PlottingPackage # set the PlottingPackage
if modname == :qwt if modname == :qwt
@ -177,7 +177,7 @@ function plotter!(modname)
elseif modname == :winston elseif modname == :winston
CURRENT_BACKEND.pkg = WinstonPackage() CURRENT_BACKEND.pkg = WinstonPackage()
else else
error("Unknown plotter $modname. Choose from: $BACKENDS") error("Unknown backend $modname. Choose from: $BACKENDS")
end end
# update the symbol # update the symbol

View File

@ -37,7 +37,7 @@ Base.length(layout::SubplotLayout) = layout.numplts
# ------------------------------------------------------------ # ------------------------------------------------------------
Base.string(subplt::Subplot) = "Subplot{$(subplt.plotter) p=$(subplt.p) n=$(subplt.n)}" Base.string(subplt::Subplot) = "Subplot{$(subplt.backend) p=$(subplt.p) n=$(subplt.n)}"
Base.print(io::IO, subplt::Subplot) = print(io, string(subplt)) Base.print(io::IO, subplt::Subplot) = print(io, string(subplt))
Base.show(io::IO, subplt::Subplot) = print(io, string(subplt)) Base.show(io::IO, subplt::Subplot) = print(io, string(subplt))
@ -63,17 +63,19 @@ function subplot(args...; kw...)
replaceAliases!(d, _keyAliases) replaceAliases!(d, _keyAliases)
# figure out the layout # figure out the layout
if haskey(d, :layout) layoutarg = get(d, :layout, nothing)
layout = SubplotLayout(d[:layout]) # if haskey(d, :layout)
if layoutarg != nothing
layout = SubplotLayout(layoutarg)
else else
if !haskey(d, :n) if !haskey(d, :n) || d[:n] < 0
error("You must specify either layout or n when creating a subplot: ", d) error("You must specify either layout or n when creating a subplot: ", d)
end end
layout = SubplotLayout(d[:n], get(d, :nr, -1), get(d, :nc, -1)) layout = SubplotLayout(d[:n], get(d, :nr, -1), get(d, :nc, -1))
end end
# initialize the individual plots # initialize the individual plots
pkg = plotter() pkg = backend()
plts = Plot[] plts = Plot[]
ds = Dict[] ds = Dict[]
for i in 1:length(layout) for i in 1:length(layout)
@ -100,7 +102,7 @@ Adds to a subplot.
# current subplot # current subplot
function subplot!(args...; kw...) function subplot!(args...; kw...)
subplot!(currentPlot(), args...; kw...) subplot!(current(), args...; kw...)
end end
@ -113,7 +115,7 @@ end
# # this adds to a specific subplot... most plot commands will flow through here # # this adds to a specific subplot... most plot commands will flow through here
function subplot!(subplt::Subplot, args...; kw...) function subplot!(subplt::Subplot, args...; kw...)
if !subplotSupported() if !subplotSupported()
error(CURRENT_BACKEND.sym, " does not support the subplot/subplot! commands at this time. Try one of: ", join(filter(pkg->subplotSupported(backend(pkg)), backends()),", ")) error(CURRENT_BACKEND.sym, " does not support the subplot/subplot! commands at this time. Try one of: ", join(filter(pkg->subplotSupported(backendInstance(pkg)), backends()),", "))
end end
d = Dict(kw) d = Dict(kw)
@ -122,12 +124,15 @@ function subplot!(subplt::Subplot, args...; kw...)
delete!(d, k) delete!(d, k)
end end
kwList = createKWargsList(subplt, args...; d...) kwList, xmeta, ymeta = createKWargsList(subplt, args...; d...)
for (i,d) in enumerate(kwList)
# TODO: something useful with meta info?
for (i,di) in enumerate(kwList)
subplt.n += 1 subplt.n += 1
plt = getplot(subplt) # get the Plot object where this series will be drawn plt = getplot(subplt) # get the Plot object where this series will be drawn
d[:show] = false di[:show] = false
plot!(plt; d...) plot!(plt; di...)
end end
# create the underlying object (each backend will do this differently) # create the underlying object (each backend will do this differently)
@ -137,16 +142,12 @@ function subplot!(subplt::Subplot, args...; kw...)
end end
# set this to be current # set this to be current
currentPlot!(subplt) current(subplt)
# NOTE: lets ignore the show param and effectively use the semicolon at the end of the REPL statement # show it automatically?
# # do we want to show it? if haskey(d, :show) && d[:show]
# d = Dict(kw) gui()
# @show d end
# if haskey(d, :show) && d[:show]
# println("here...why?")
# display(subplt)
# end
subplt subplt
end end

View File

@ -9,7 +9,7 @@ abstract PlottingObject{T<:PlottingPackage}
type Plot{T<:PlottingPackage} <: PlottingObject{T} type Plot{T<:PlottingPackage} <: PlottingObject{T}
o # the underlying object o # the underlying object
plotter::T backend::T
n::Int # number of series n::Int # number of series
# store these just in case # store these just in case
@ -27,7 +27,7 @@ end
type Subplot{T<:PlottingPackage} <: PlottingObject{T} type Subplot{T<:PlottingPackage} <: PlottingObject{T}
o # the underlying object o # the underlying object
plts::Vector{Plot} # the individual plots plts::Vector{Plot} # the individual plots
plotter::T backend::T
p::Int # number of plots p::Int # number of plots
n::Int # number of series n::Int # number of series
layout::SubplotLayout layout::SubplotLayout

View File

@ -4,15 +4,15 @@ using Plots
using FactCheck using FactCheck
# don't actually show the plots # don't actually show the plots
plotDefault!(:show, false) default(show=false)
srand(1234) srand(1234)
# note: we wrap in a try block so that the tests only run if we have the backend installed # note: we wrap in a try block so that the tests only run if we have the backend installed
try try
Pkg.installed("Gadfly") Pkg.installed("Gadfly")
facts("Gadfly") do facts("Gadfly") do
@fact plotter!(:gadfly) --> Plots.GadflyPackage() @fact backend(:gadfly) --> Plots.GadflyPackage()
@fact plotter() --> Plots.GadflyPackage() @fact backend() --> Plots.GadflyPackage()
@fact typeof(plot(1:10)) --> Plots.Plot{Plots.GadflyPackage} @fact typeof(plot(1:10)) --> Plots.Plot{Plots.GadflyPackage}
@ -41,35 +41,35 @@ end
try try
Pkg.installed("Qwt") Pkg.installed("Qwt")
facts("Qwt") do facts("Qwt") do
@fact plotter!(:qwt) --> Plots.QwtPackage() @fact backend(:qwt) --> Plots.QwtPackage()
@fact plotter() --> Plots.QwtPackage() @fact backend() --> Plots.QwtPackage()
@fact typeof(plot(1:10)) --> Plots.Plot{Plots.QwtPackage} @fact typeof(plot(1:10)) --> Plots.Plot{Plots.QwtPackage}
# plot(y::AVec; kw...) # one line... x = 1:length(y) # plot(y::AVec; kw...) # one line... x = 1:length(y)
@fact plot(1:10) --> not(nothing) @fact plot(1:10) --> not(nothing)
@fact length(currentPlot().o.lines) --> 1 @fact length(current().o.lines) --> 1
# plot(x::AVec, f::Function; kw...) # one line, y = f(x) # plot(x::AVec, f::Function; kw...) # one line, y = f(x)
@fact plot(1:10, sin) --> not(nothing) @fact plot(1:10, sin) --> not(nothing)
@fact currentPlot().o.lines[1].y --> sin(collect(1:10)) @fact current().o.lines[1].y --> sin(collect(1:10))
# plot(x::AMat, f::Function; kw...) # multiple lines, yᵢⱼ = f(xᵢⱼ) # plot(x::AMat, f::Function; kw...) # multiple lines, yᵢⱼ = f(xᵢⱼ)
@fact plot(rand(10,2), sin) --> not(nothing) @fact plot(rand(10,2), sin) --> not(nothing)
@fact length(currentPlot().o.lines) --> 2 @fact length(current().o.lines) --> 2
# 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)
@fact plot!(rand(10,2)) --> not(nothing) @fact plot!(rand(10,2)) --> not(nothing)
@fact length(currentPlot().o.lines) --> 4 @fact length(current().o.lines) --> 4
# plot(x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ) # plot(x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ)
@fact plot(1:10, Function[sin,cos]) --> not(nothing) @fact plot(1:10, Function[sin,cos]) --> not(nothing)
@fact currentPlot().o.lines[1].y --> sin(collect(1:10)) @fact current().o.lines[1].y --> sin(collect(1:10))
@fact currentPlot().o.lines[2].y --> cos(collect(1:10)) @fact current().o.lines[2].y --> cos(collect(1:10))
# plot(y::AVec{AVec}; kw...) # multiple lines, each with x = 1:length(y[i]) # plot(y::AVec{AVec}; kw...) # multiple lines, each with x = 1:length(y[i])
@fact plot([11:20 ; rand(10)]) --> not(nothing) @fact plot([11:20 ; rand(10)]) --> not(nothing)
@fact currentPlot().o.lines[1].x[4] --> 4 @fact current().o.lines[1].x[4] --> 4
@fact currentPlot().o.lines[1].y[4] --> 14 @fact current().o.lines[1].y[4] --> 14
end end
end end