From 610ddb09ff72df50e2b8b8b1e516659b4f9acf13 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Wed, 23 Sep 2015 13:33:12 -0400 Subject: [PATCH] readme and cleanup --- README.md | 59 ++++++++++++++++++++++++-------------- docs/example_generation.jl | 4 +-- docs/readme_template.md | 45 +++++++++++++++++++---------- src/Plots.jl | 16 +++++------ src/args.jl | 46 +++++++++++++++-------------- 5 files changed, 103 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 9d717cbc..5b15eb45 100644 --- a/README.md +++ b/README.md @@ -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()`. ```julia -plot() # empty plot object -plot(4) # initialize with 4 empty series -plot(rand(10)) # plot 1 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,5), rand(10)) # plot 5 series... y is the same for all -plot(sin, rand(10)) # 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, π) # 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(dataset("Ecdat", "Airline"), :Cost) # plot from a DataFrame +plot() # empty plot object +plot(4) # initialize with 4 empty series +plot(rand(10)) # plot 1 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,5), rand(10)) # plot 5 series... y is the same for all +plot(sin, rand(10)) # 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, π) # 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(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: @@ -154,6 +161,14 @@ 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) + +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: @@ -185,10 +200,12 @@ Keyword | Default | Type | Aliases `:title` | `` | Plot | `:windowtitle` | `Plots.jl` | Plot | `:wtitle` `:xlabel` | `` | Plot | `:xlab` -`:xticks` | `true` | Plot | +`:xlims` | `auto` | Plot | `:xlim`, `:xlimit`, `:xlimits` +`:xticks` | `auto` | Plot | `:xtick` `:ylabel` | `` | Plot | `:ylab` +`:ylims` | `auto` | Plot | `:ylim`, `:ylimit`, `:ylimits` `:yrightlabel` | `` | Plot | `:y2lab`, `:y2label`, `:ylab2`, `:ylabel2`, `:ylabelright`, `:ylabr`, `:yrlab` -`:yticks` | `true` | Plot | +`:yticks` | `auto` | Plot | `:ytick` Plot types: @@ -198,9 +215,9 @@ Type | Desc | Aliases `:none` | No line | `:n`, `:no` `:line` | Lines with sorted x-axis | `:l` `:path` | Lines | `:p` -`:steppre` | Step plot (vertical then horizontal) | `:stepinv`, `:stepinverted` -`:steppost` | Step plot (horizontal then vertical) | `:stair`, `:stairs`, `:step` -`:sticks` | Vertical lines | `:stem` +`:steppre` | Step plot (vertical then horizontal) | `:stepinv`, `:stepinverted`, `:stepsinv`, `:stepsinverted` +`:steppost` | Step plot (horizontal then vertical) | `:stair`, `:stairs`, `:step`, `:steps` +`:sticks` | Vertical lines | `:stem`, `:stems` `:scatter` | Points, no lines | `:dots` `:heatmap` | Colored regions by density | `:hexbin` | Similar to heatmap | @@ -208,7 +225,7 @@ Type | Desc | Aliases `:bar` | Bar plot (centered on x values) | `:hline` | Horizontal 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: @@ -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 ``` -__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: - [x] Plot vectors/matrices/functions -- [ ] Plot DataFrames +- [x] Plot DataFrames - [ ] Scales - [ ] Categorical Inputs (strings, etc... for hist, bar? or can split one series into multiple?) - [ ] Custom markers diff --git a/docs/example_generation.jl b/docs/example_generation.jl index 87a143c6..d47e7a68 100644 --- a/docs/example_generation.jl +++ b/docs/example_generation.jl @@ -227,7 +227,7 @@ const _ltdesc = Dict( :bar => "Bar plot (centered on x values)", :hline => "Horizontal 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() @@ -236,7 +236,7 @@ function buildReadme() # build keyword arg table table = "Keyword | Default | Type | Aliases \n---- | ---- | ---- | ----\n" for d in (Plots._seriesDefaults, Plots._plotDefaults) - for k in sortedkeys(d) + for k in Plots.sortedkeys(d) aliasstr = createStringOfMarkDownSymbols(aliases(Plots._keyAliases, k)) table = string(table, "`:$k` | `$(d[k])` | $(d==Plots._seriesDefaults ? "Series" : "Plot") | $aliasstr \n") end diff --git a/docs/readme_template.md b/docs/readme_template.md index 0d387774..84e8b680 100644 --- a/docs/readme_template.md +++ b/docs/readme_template.md @@ -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()`. ```julia -plot() # empty plot object -plot(4) # initialize with 4 empty series -plot(rand(10)) # plot 1 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,5), rand(10)) # plot 5 series... y is the same for all -plot(sin, rand(10)) # 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, π) # 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(dataset("Ecdat", "Airline"), :Cost) # plot from a DataFrame +plot() # empty plot object +plot(4) # initialize with 4 empty series +plot(rand(10)) # plot 1 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,5), rand(10)) # plot 5 series... y is the same for all +plot(sin, rand(10)) # 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, π) # 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(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: @@ -154,6 +161,14 @@ 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) + +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: @@ -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 ``` -__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: - [x] Plot vectors/matrices/functions -- [ ] Plot DataFrames +- [x] Plot DataFrames - [ ] Scales - [ ] Categorical Inputs (strings, etc... for hist, bar? or can split one series into multiple?) - [ ] Custom markers diff --git a/src/Plots.jl b/src/Plots.jl index 840be7d2..dfbeb2c7 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -99,18 +99,18 @@ 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}(s::Tuple{T,S}) = plot!(xlims = s) -ylims!{T<:Real,S<:Real}(s::Tuple{T,S}) = plot!(ylims = s) -xticks!{T<:Real}(s::AVec{T}) = plot!(xticks = s) -yticks!{T<:Real}(s::AVec{T}) = plot!(yticks = 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) title!(plt::Plot, s::AbstractString) = plot!(plt; title = s) xlabel!(plt::Plot, s::AbstractString) = plot!(plt; xlabel = 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) -ylims!{T<:Real,S<:Real}(plt::Plot, s::Tuple{T,S}) = plot!(plt; ylims = s) -xticks!{T<:Real}(plt::Plot, s::AVec{T}) = plot!(plt; xticks = s) -yticks!{T<:Real}(plt::Plot, s::AVec{T}) = plot!(plt; yticks = s) +xlims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}) = plot!(plt; xlims = lims) +ylims!{T<:Real,S<:Real}(plt::Plot, lims::Tuple{T,S}) = plot!(plt; ylims = lims) +xticks!{T<:Real}(plt::Plot, v::AVec{T}) = plot!(plt; xticks = v) +yticks!{T<:Real}(plt::Plot, v::AVec{T}) = plot!(plt; yticks = v) # --------------------------------------------------------- diff --git a/src/args.jl b/src/args.jl index 8dd9af1d..0a35e27b 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1,32 +1,35 @@ -const _allAxes = [:auto, :left, :right] -const _axesAliases = Dict( +const _allAxes = [:auto, :left, :right] +const _axesAliases = Dict( :a => :auto, :l => :left, :r => :right ) -const _allTypes = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, - :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc] -const _typeAliases = Dict( - :n => :none, - :no => :none, - :l => :line, - :p => :path, - :stepinv => :steppre, - :stepinverted => :steppre, - :step => :steppost, - :step => :steppost, - :stair => :steppost, - :stairs => :steppost, - :stem => :sticks, - :dots => :scatter, - :histogram => :hist, +const _allTypes = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, + :heatmap, :hexbin, :hist, :bar, :hline, :vline, :ohlc] +const _typeAliases = Dict( + :n => :none, + :no => :none, + :l => :line, + :p => :path, + :stepinv => :steppre, + :stepsinv => :steppre, + :stepinverted => :steppre, + :stepsinverted => :steppre, + :step => :steppost, + :steps => :steppost, + :stair => :steppost, + :stairs => :steppost, + :stem => :sticks, + :stems => :sticks, + :dots => :scatter, + :histogram => :hist, ) -const _allStyles = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] -const _styleAliases = Dict( +const _allStyles = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] +const _styleAliases = Dict( :a => :auto, :s => :solid, :d => :dash, @@ -34,7 +37,8 @@ const _styleAliases = Dict( :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( :n => :none, :no => :none,