readme and cleanup

This commit is contained in:
Thomas Breloff 2015-09-23 13:33:12 -04:00
parent 33602aca11
commit 610ddb09ff
5 changed files with 103 additions and 67 deletions

View File

@ -107,18 +107,25 @@ the relevant column(s) and also automatically set the associated legend label.
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 `currentPlot()`.
```julia ```julia
plot() # empty plot object plot() # empty plot object
plot(4) # initialize with 4 empty series plot(4) # initialize with 4 empty series
plot(rand(10)) # plot 1 series... x = 1:10 plot(rand(10)) # plot 1 series... x = 1:10
plot(rand(10,5)) # plot 5 series... x = 1:10 plot(rand(10,5)) # plot 5 series... x = 1:10
plot(rand(10), rand(10)) # plot 1 series plot(rand(10), rand(10)) # plot 1 series
plot(rand(10,5), rand(10)) # plot 5 series... y is the same for all plot(rand(10,5), rand(10)) # plot 5 series... y is the same for all
plot(sin, rand(10)) # y = sin(x) plot(sin, rand(10)) # y = sin(x)
plot(rand(10), sin) # same... y = sin(x) 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 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):
```julia
plot!(title = "New Title", xlabel = "New xlabel", ylabel = "New ylabel")
plot!(xlims = (0, 5.5), ylims = (-2.2, 6), xticks = 0:0.5:10, yticks = [0,1,5,10])
``` ```
With `subplot`, create multiple plots at once, with flexible layout options: With `subplot`, create multiple plots at once, with flexible layout options:
@ -154,6 +161,14 @@ vline(args...; kw...) = plot(args...; kw..., linetype = :vline)
vline!(args...; kw...) = plot!(args...; kw..., linetype = :vline) 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)
xlabel!(s::AbstractString) = plot!(xlabel = s)
ylabel!(s::AbstractString) = plot!(ylabel = s)
xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims)
ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims)
xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v)
yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = v)
``` ```
Some keyword arguments you can set: Some keyword arguments you can set:
@ -185,10 +200,12 @@ Keyword | Default | Type | Aliases
`:title` | `` | Plot | `:title` | `` | Plot |
`:windowtitle` | `Plots.jl` | Plot | `:wtitle` `:windowtitle` | `Plots.jl` | Plot | `:wtitle`
`:xlabel` | `` | Plot | `:xlab` `:xlabel` | `` | Plot | `:xlab`
`:xticks` | `true` | Plot | `:xlims` | `auto` | Plot | `:xlim`, `:xlimit`, `:xlimits`
`:xticks` | `auto` | Plot | `:xtick`
`:ylabel` | `` | Plot | `:ylab` `:ylabel` | `` | Plot | `:ylab`
`:ylims` | `auto` | Plot | `:ylim`, `:ylimit`, `:ylimits`
`:yrightlabel` | `` | Plot | `:y2lab`, `:y2label`, `:ylab2`, `:ylabel2`, `:ylabelright`, `:ylabr`, `:yrlab` `:yrightlabel` | `` | Plot | `:y2lab`, `:y2label`, `:ylab2`, `:ylabel2`, `:ylabelright`, `:ylabr`, `:yrlab`
`:yticks` | `true` | Plot | `:yticks` | `auto` | Plot | `:ytick`
Plot types: Plot types:
@ -198,9 +215,9 @@ Type | Desc | Aliases
`:none` | No line | `:n`, `:no` `:none` | No line | `:n`, `:no`
`:line` | Lines with sorted x-axis | `:l` `:line` | Lines with sorted x-axis | `:l`
`:path` | Lines | `:p` `:path` | Lines | `:p`
`:steppre` | Step plot (vertical then horizontal) | `:stepinv`, `:stepinverted` `:steppre` | Step plot (vertical then horizontal) | `:stepinv`, `:stepinverted`, `:stepsinv`, `:stepsinverted`
`:steppost` | Step plot (horizontal then vertical) | `:stair`, `:stairs`, `:step` `:steppost` | Step plot (horizontal then vertical) | `:stair`, `:stairs`, `:step`, `:steps`
`:sticks` | Vertical lines | `:stem` `:sticks` | Vertical lines | `:stem`, `:stems`
`:scatter` | Points, no lines | `:dots` `:scatter` | Points, no lines | `:dots`
`:heatmap` | Colored regions by density | `:heatmap` | Colored regions by density |
`:hexbin` | Similar to heatmap | `:hexbin` | Similar to heatmap |
@ -208,7 +225,7 @@ Type | Desc | Aliases
`:bar` | Bar plot (centered on x values) | `:bar` | Bar plot (centered on x values) |
`:hline` | Horizontal line (doesn't use x) | `:hline` | Horizontal line (doesn't use x) |
`:vline` | Vertical line (doesn't use x) | `:vline` | Vertical line (doesn't use x) |
`:ohlc` | Open/High/Low/Close chart (expects y is vector of 4-tuples) | `:ohlc` | Open/High/Low/Close chart (expects y is AbstractVector{Plots.OHLC}) |
Line styles: Line styles:
@ -253,14 +270,14 @@ plot(rand(100,4); color = [:red, RGB(0,0,1)], # lines 1 and 3 are red, lines
width = 5) # all lines have a width of 5 width = 5) # all lines have a width of 5
``` ```
__Tip__: Not all features are supported for each backend, but you can see what's supported by calling the functions: `supportedAxes()`, `supportedTypes()`, `supportedStyles()`, `supportedMarkers()`, `subplotSupported()` __Tip__: Not all features are supported for each backend, but you can see what's supported by calling the functions: `supportedArgs()`, `supportedAxes()`, `supportedTypes()`, `supportedStyles()`, `supportedMarkers()`, `subplotSupported()`
__Tip__: Call `gui()` to display the plot in a window. Interactivity depends on backend. Showing at the REPL implicitly calls this. __Tip__: Call `gui()` to display the plot in a window. Interactivity depends on backend. Plotting at the REPL (without semicolon) implicitly calls `gui()`.
## TODO features: ## TODO features:
- [x] Plot vectors/matrices/functions - [x] Plot vectors/matrices/functions
- [ ] Plot DataFrames - [x] Plot DataFrames
- [ ] Scales - [ ] Scales
- [ ] Categorical Inputs (strings, etc... for hist, bar? or can split one series into multiple?) - [ ] Categorical Inputs (strings, etc... for hist, bar? or can split one series into multiple?)
- [ ] Custom markers - [ ] Custom markers

View File

@ -227,7 +227,7 @@ const _ltdesc = Dict(
:bar => "Bar plot (centered on x values)", :bar => "Bar plot (centered on x values)",
:hline => "Horizontal line (doesn't use x)", :hline => "Horizontal line (doesn't use x)",
:vline => "Vertical line (doesn't use x)", :vline => "Vertical line (doesn't use x)",
:ohlc => "Open/High/Low/Close chart (expects y is vector of 4-tuples)", :ohlc => "Open/High/Low/Close chart (expects y is AbstractVector{Plots.OHLC})",
) )
function buildReadme() function buildReadme()
@ -236,7 +236,7 @@ function buildReadme()
# build keyword arg table # build keyword arg table
table = "Keyword | Default | Type | Aliases \n---- | ---- | ---- | ----\n" table = "Keyword | Default | Type | Aliases \n---- | ---- | ---- | ----\n"
for d in (Plots._seriesDefaults, Plots._plotDefaults) for d in (Plots._seriesDefaults, Plots._plotDefaults)
for k in sortedkeys(d) for k in Plots.sortedkeys(d)
aliasstr = createStringOfMarkDownSymbols(aliases(Plots._keyAliases, k)) aliasstr = createStringOfMarkDownSymbols(aliases(Plots._keyAliases, k))
table = string(table, "`:$k` | `$(d[k])` | $(d==Plots._seriesDefaults ? "Series" : "Plot") | $aliasstr \n") table = string(table, "`:$k` | `$(d[k])` | $(d==Plots._seriesDefaults ? "Series" : "Plot") | $aliasstr \n")
end end

View File

@ -107,18 +107,25 @@ the relevant column(s) and also automatically set the associated legend label.
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 `currentPlot()`.
```julia ```julia
plot() # empty plot object plot() # empty plot object
plot(4) # initialize with 4 empty series plot(4) # initialize with 4 empty series
plot(rand(10)) # plot 1 series... x = 1:10 plot(rand(10)) # plot 1 series... x = 1:10
plot(rand(10,5)) # plot 5 series... x = 1:10 plot(rand(10,5)) # plot 5 series... x = 1:10
plot(rand(10), rand(10)) # plot 1 series plot(rand(10), rand(10)) # plot 1 series
plot(rand(10,5), rand(10)) # plot 5 series... y is the same for all plot(rand(10,5), rand(10)) # plot 5 series... y is the same for all
plot(sin, rand(10)) # y = sin(x) plot(sin, rand(10)) # y = sin(x)
plot(rand(10), sin) # same... y = sin(x) 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 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):
```julia
plot!(title = "New Title", xlabel = "New xlabel", ylabel = "New ylabel")
plot!(xlims = (0, 5.5), ylims = (-2.2, 6), xticks = 0:0.5:10, yticks = [0,1,5,10])
``` ```
With `subplot`, create multiple plots at once, with flexible layout options: With `subplot`, create multiple plots at once, with flexible layout options:
@ -154,6 +161,14 @@ vline(args...; kw...) = plot(args...; kw..., linetype = :vline)
vline!(args...; kw...) = plot!(args...; kw..., linetype = :vline) 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)
xlabel!(s::AbstractString) = plot!(xlabel = s)
ylabel!(s::AbstractString) = plot!(ylabel = s)
xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims)
ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims)
xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v)
yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = v)
``` ```
Some keyword arguments you can set: Some keyword arguments you can set:
@ -183,14 +198,14 @@ plot(rand(100,4); color = [:red, RGB(0,0,1)], # lines 1 and 3 are red, lines
width = 5) # all lines have a width of 5 width = 5) # all lines have a width of 5
``` ```
__Tip__: Not all features are supported for each backend, but you can see what's supported by calling the functions: `supportedAxes()`, `supportedTypes()`, `supportedStyles()`, `supportedMarkers()`, `subplotSupported()` __Tip__: Not all features are supported for each backend, but you can see what's supported by calling the functions: `supportedArgs()`, `supportedAxes()`, `supportedTypes()`, `supportedStyles()`, `supportedMarkers()`, `subplotSupported()`
__Tip__: Call `gui()` to display the plot in a window. Interactivity depends on backend. Showing at the REPL implicitly calls this. __Tip__: Call `gui()` to display the plot in a window. Interactivity depends on backend. Plotting at the REPL (without semicolon) implicitly calls `gui()`.
## TODO features: ## TODO features:
- [x] Plot vectors/matrices/functions - [x] Plot vectors/matrices/functions
- [ ] Plot DataFrames - [x] Plot DataFrames
- [ ] Scales - [ ] Scales
- [ ] Categorical Inputs (strings, etc... for hist, bar? or can split one series into multiple?) - [ ] Categorical Inputs (strings, etc... for hist, bar? or can split one series into multiple?)
- [ ] Custom markers - [ ] Custom markers

View File

@ -99,18 +99,18 @@ 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}(s::Tuple{T,S}) = plot!(xlims = s) xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims)
ylims!{T<:Real,S<:Real}(s::Tuple{T,S}) = plot!(ylims = s) ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims)
xticks!{T<:Real}(s::AVec{T}) = plot!(xticks = s) xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v)
yticks!{T<:Real}(s::AVec{T}) = plot!(yticks = s) yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = v)
title!(plt::Plot, s::AbstractString) = plot!(plt; title = s) title!(plt::Plot, s::AbstractString) = plot!(plt; title = s)
xlabel!(plt::Plot, s::AbstractString) = plot!(plt; xlabel = s) xlabel!(plt::Plot, s::AbstractString) = plot!(plt; xlabel = s)
ylabel!(plt::Plot, s::AbstractString) = plot!(plt; ylabel = s) ylabel!(plt::Plot, s::AbstractString) = plot!(plt; ylabel = s)
xlims!{T<:Real,S<:Real}(plt::Plot, s::Tuple{T,S}) = plot!(plt; xlims = s) xlims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}) = plot!(plt; xlims = lims)
ylims!{T<:Real,S<:Real}(plt::Plot, s::Tuple{T,S}) = plot!(plt; ylims = s) ylims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}) = plot!(plt; ylims = lims)
xticks!{T<:Real}(plt::Plot, s::AVec{T}) = plot!(plt; xticks = s) xticks!{T<:Real}(plt::Plot, v::AVec{T}) = plot!(plt; xticks = v)
yticks!{T<:Real}(plt::Plot, s::AVec{T}) = plot!(plt; yticks = s) yticks!{T<:Real}(plt::Plot, v::AVec{T}) = plot!(plt; yticks = v)
# --------------------------------------------------------- # ---------------------------------------------------------

View File

@ -1,32 +1,35 @@
const _allAxes = [:auto, :left, :right] const _allAxes = [:auto, :left, :right]
const _axesAliases = Dict( const _axesAliases = Dict(
:a => :auto, :a => :auto,
:l => :left, :l => :left,
:r => :right :r => :right
) )
const _allTypes = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, const _allTypes = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter,
:heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc] :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc]
const _typeAliases = Dict( const _typeAliases = Dict(
:n => :none, :n => :none,
:no => :none, :no => :none,
:l => :line, :l => :line,
:p => :path, :p => :path,
:stepinv => :steppre, :stepinv => :steppre,
:stepinverted => :steppre, :stepsinv => :steppre,
:step => :steppost, :stepinverted => :steppre,
:step => :steppost, :stepsinverted => :steppre,
:stair => :steppost, :step => :steppost,
:stairs => :steppost, :steps => :steppost,
:stem => :sticks, :stair => :steppost,
:dots => :scatter, :stairs => :steppost,
:histogram => :hist, :stem => :sticks,
:stems => :sticks,
:dots => :scatter,
:histogram => :hist,
) )
const _allStyles = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] const _allStyles = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
const _styleAliases = Dict( const _styleAliases = Dict(
:a => :auto, :a => :auto,
:s => :solid, :s => :solid,
:d => :dash, :d => :dash,
@ -34,7 +37,8 @@ const _styleAliases = Dict(
:ddd => :dashdotdot, :ddd => :dashdotdot,
) )
const _allMarkers = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon, :octagon] const _allMarkers = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle,
:cross, :xcross, :star1, :star2, :hexagon, :octagon]
const _markerAliases = Dict( const _markerAliases = Dict(
:n => :none, :n => :none,
:no => :none, :no => :none,