From e02a70249eba3763fcd924651cd7a45d0f761b2a Mon Sep 17 00:00:00 2001 From: JackDevine Date: Mon, 4 Dec 2017 22:34:45 +1300 Subject: [PATCH 1/2] Examples are limited to 90 columns. Thanks @daschw for pointing out the correct place to make these changes. I have also changed the explanation texts, which may be a little overkill, but I do think that the style guides apply to Markdown string too (could be wrong though). --- src/examples.jl | 182 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 124 insertions(+), 58 deletions(-) diff --git a/src/examples.jl b/src/examples.jl index fabb368d..386d45d9 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -18,7 +18,14 @@ PlotExample("Lines", ), PlotExample("Functions, adding data, and animations", - "Plot multiple functions. You can also put the function first, or use the form `plot(f, xmin, xmax)` where f is a Function or AbstractVector{Function}.\n\nGet series data: `x, y = plt[i]`. Set series data: `plt[i] = (x,y)`. Add to the series with `push!`/`append!`.\n\nEasily build animations. (`convert` or `ffmpeg` must be available to generate the animation.) Use command `gif(anim, filename, fps=15)` to save the animation.", +""" +Plot multiple functions. You can also put the function first, or use the form `plot(f, +xmin, xmax)` where f is a Function or AbstractVector{Function}.\n\nGet series data: +`x, y = plt[i]`. Set series data: `plt[i] = (x,y)`. Add to the series with +`push!`/`append!`.\n\nEasily build animations. (`convert` or `ffmpeg` must be available +to generate the animation.) Use command `gif(anim, filename, fps=15)` to save the +animation. +""", [:(begin p = plot([sin,cos], zeros(0), leg=false) anim = Animation() @@ -37,23 +44,35 @@ PlotExample("Parametric plots", ), PlotExample("Colors", - "Access predefined palettes (or build your own with the `colorscheme` method). Line/marker colors are auto-generated from the plot's palette, unless overridden. Set the `z` argument to turn on series gradients.", +""" +Access predefined palettes (or build your own with the `colorscheme` method). +Line/marker colors are auto-generated from the plot's palette, unless overridden. Set +the `z` argument to turn on series gradients. +""", [:(begin - y = rand(100) - plot(0:10:100,rand(11,4),lab="lines",w=3,palette=:grays,fill=0, α=0.6) - scatter!(y, zcolor=abs.(y-.5), m=(:heat,0.8,stroke(1,:green)), ms=10*abs.(y-0.5)+4, lab="grad") +y = rand(100) +plot(0:10:100,rand(11,4),lab="lines",w=3,palette=:grays,fill=0, α=0.6) +scatter!(y, zcolor=abs.(y-.5), m=(:heat,0.8,stroke(1,:green)), ms=10*abs.(y-0.5)+4, + lab="grad") end)] ), PlotExample("Global", - "Change the guides/background/limits/ticks. Convenience args `xaxis` and `yaxis` allow you to pass a tuple or value which will be mapped to the relevant args automatically. The `xaxis` below will be replaced with `xlabel` and `xlims` args automatically during the preprocessing step. You can also use shorthand functions: `title!`, `xaxis!`, `yaxis!`, `xlabel!`, `ylabel!`, `xlims!`, `ylims!`, `xticks!`, `yticks!`", +""" +Change the guides/background/limits/ticks. Convenience args `xaxis` and `yaxis` allow +you to pass a tuple or value which will be mapped to the relevant args automatically. +The `xaxis` below will be replaced with `xlabel` and `xlims` args automatically during +the preprocessing step. You can also use shorthand functions: `title!`, `xaxis!`, +`yaxis!`, `xlabel!`, `ylabel!`, `xlims!`, `ylims!`, `xticks!`, `yticks!` +""", [:(begin - y = rand(20,3) - plot(y, xaxis=("XLABEL",(-5,30),0:2:20,:flip), background_color = RGB(0.2,0.2,0.2), leg=false) - hline!(mean(y,1)+rand(1,3), line=(4,:dash,0.6,[:lightgreen :green :darkgreen])) - vline!([5,10]) - title!("TITLE") - yaxis!("YLABEL", :log10) +y = rand(20,3) +plot(y, xaxis=("XLABEL",(-5,30),0:2:20,:flip), background_color = RGB(0.2,0.2,0.2), + leg=false) +hline!(mean(y,1)+rand(1,3), line=(4,:dash,0.6,[:lightgreen :green :darkgreen])) +vline!([5,10]) +title!("TITLE") +yaxis!("YLABEL", :log10) end)] ), @@ -73,7 +92,14 @@ PlotExample("Images", ), PlotExample("Arguments", - "Plot multiple series with different numbers of points. Mix arguments that apply to all series (marker/markersize) with arguments unique to each series (colors). Special arguments `line`, `marker`, and `fill` will automatically figure out what arguments to set (for example, we are setting the `linestyle`, `linewidth`, and `color` arguments with `line`.) Note that we pass a matrix of colors, and this applies the colors to each series.", +""" +Plot multiple series with different numbers of points. Mix arguments that apply to all +series (marker/markersize) with arguments unique to each series (colors). Special +arguments `line`, `marker`, and `fill` will automatically figure out what arguments to +set (for example, we are setting the `linestyle`, `linewidth`, and `color` arguments with +`line`.) Note that we pass a matrix of colors, and this applies the colors to each +series. +""", [:(begin ys = Vector[rand(10), rand(20)] plot(ys, color=[:black :orange], line=(:dot,4), marker=([:hex :d],12,0.8,stroke(3,:gray))) @@ -115,12 +141,13 @@ PlotExample("Line types", PlotExample("Line styles", "", [:(begin - styles = filter(s -> s in Plots.supported_styles(), [:solid, :dash, :dot, :dashdot, :dashdotdot]) - styles = reshape(styles, 1, length(styles)) # Julia 0.6 unfortunately gives an error when transposing symbol vectors - n = length(styles) - y = cumsum(randn(20,n),1) - plot(y, line = (5, styles), label = map(string,styles), legendtitle = "linestyle") - end)] +styles = filter(s -> s in Plots.supported_styles(), + [:solid, :dash, :dot, :dashdot, :dashdotdot]) +styles = reshape(styles, 1, length(styles)) # Julia 0.6 unfortunately gives an error when transposing symbol vectors +n = length(styles) +y = cumsum(randn(20,n),1) +plot(y, line = (5, styles), label = map(string,styles), legendtitle = "linestyle") + end)] ), PlotExample("Marker types", @@ -150,19 +177,25 @@ PlotExample("Histogram", ), PlotExample("Subplots", - """ - Use the `layout` keyword, and optionally the convenient `@layout` macro to generate arbitrarily complex subplot layouts. - """, +""" +Use the `layout` keyword, and optionally the convenient `@layout` macro to generate +arbitrarily complex subplot layouts. +""", [:(begin - l = @layout([a{0.1h}; b [c;d e]]) - plot(randn(100,5), layout=l, t=[:line :histogram :scatter :steppre :bar], leg=false, ticks=nothing, border=:none) +l = @layout([a{0.1h}; b [c;d e]]) +plot(randn(100,5), layout=l, t=[:line :histogram :scatter :steppre :bar], leg=false, + ticks=nothing, border=:none) end)] ), 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. +""", [:(begin - plot(Plots.fakedata(100,10), layout=4, palette=[:grays :blues :heat :lightrainbow], bg_inside=[:orange :pink :darkblue :black]) +plot(Plots.fakedata(100,10), layout=4, palette=[:grays :blues :heat :lightrainbow], + bg_inside=[:orange :pink :darkblue :black]) end)] ), @@ -175,43 +208,63 @@ PlotExample("", ), PlotExample("Open/High/Low/Close", - "Create an OHLC chart. Pass in a list of (open,high,low,close) tuples as your `y` argument. This uses recipes to first convert the tuples to OHLC objects, and subsequently create a :path series with the appropriate line segments.", +""" +Create an OHLC chart. Pass in a list of (open,high,low,close) tuples as your `y` +argument. This uses recipes to first convert the tuples to OHLC objects, and +subsequently create a :path series with the appropriate line segments. +""", [:(begin - n=20 - hgt=rand(n)+1 - bot=randn(n) - openpct=rand(n) - closepct=rand(n) - y = OHLC[(openpct[i]*hgt[i]+bot[i], bot[i]+hgt[i], bot[i], closepct[i]*hgt[i]+bot[i]) for i in 1:n] - ohlc(y) +n=20 +hgt=rand(n)+1 +bot=randn(n) +openpct=rand(n) +closepct=rand(n) +y = OHLC[(openpct[i]*hgt[i]+bot[i], bot[i]+hgt[i], bot[i], + closepct[i]*hgt[i]+bot[i]) for i in 1:n] +ohlc(y) end)] ), PlotExample("Annotations", - "The `annotations` keyword is used for text annotations in data-coordinates. Pass in a tuple (x,y,text) or a vector of annotations. `annotate!(ann)` is shorthand for `plot!(; annotation=ann)`. Series annotations are used for annotating individual data points. They require only the annotation... x/y values are computed. A `PlotText` object can be build with the method `text(string, attr...)`, which wraps font and color attributes.", +""" +The `annotations` keyword is used for text annotations in data-coordinates. Pass in a +tuple (x,y,text) or a vector of annotations. `annotate!(ann)` is shorthand for `plot!(; +annotation=ann)`. Series annotations are used for annotating individual data points. +They require only the annotation... x/y values are computed. A `PlotText` object can be +build with the method `text(string, attr...)`, which wraps font and color attributes. +""", [:(begin - y = rand(10) - plot(y, annotations = (3,y[3],text("this is #3",:left)), leg=false) - annotate!([(5, y[5], text("this is #5",16,:red,:center)), (10, y[10], text("this is #10",:right,20,"courier"))]) - scatter!(linspace(2,8,6), rand(6), marker=(50,0.2,:orange), series_annotations = ["series","annotations","map","to","series",text("data",:green)]) +y = rand(10) +plot(y, annotations = (3,y[3],text("this is #3",:left)), leg=false) +annotate!([(5, y[5], text("this is #5",16,:red,:center)), + (10, y[10], text("this is #10",:right,20,"courier"))]) +scatter!(linspace(2,8,6), rand(6), marker=(50,0.2,:orange), + series_annotations = ["series","annotations","map","to","series", + text("data",:green)]) end)] ), PlotExample("Custom Markers", - "A `Plots.Shape` is a light wrapper around vertices of a polygon. For supported backends, pass arbitrary polygons as the marker shapes. Note: The center is (0,0) and the size is expected to be rougly the area of the unit circle.", +"""A `Plots.Shape` is a light wrapper around vertices of a polygon. For supported +backends, pass arbitrary polygons as the marker shapes. Note: The center is (0,0) and +the size is expected to be rougly the area of the unit circle. +""", [:(begin - verts = [(-1.0,1.0),(-1.28,0.6),(-0.2,-1.4),(0.2,-1.4),(1.28,0.6),(1.0,1.0), - (-1.0,1.0),(-0.2,-0.6),(0.0,-0.2),(-0.4,0.6),(1.28,0.6),(0.2,-1.4), - (-0.2,-1.4),(0.6,0.2),(-0.2,0.2),(0.0,-0.2),(0.2,0.2),(-0.2,-0.6)] - x = 0.1:0.2:0.9 - y = 0.7rand(5)+0.15 - plot(x, y, line = (3,:dash,:lightblue), marker = (Shape(verts),30,RGBA(0,0,0,0.2)), - bg=:pink, fg=:darkblue, xlim = (0,1), ylim=(0,1), leg=false) +verts = [(-1.0,1.0),(-1.28,0.6),(-0.2,-1.4),(0.2,-1.4),(1.28,0.6),(1.0,1.0), + (-1.0,1.0),(-0.2,-0.6),(0.0,-0.2),(-0.4,0.6),(1.28,0.6),(0.2,-1.4), + (-0.2,-1.4),(0.6,0.2),(-0.2,0.2),(0.0,-0.2),(0.2,0.2),(-0.2,-0.6)] +x = 0.1:0.2:0.9 +y = 0.7rand(5)+0.15 +plot(x, y, line = (3,:dash,:lightblue), marker = (Shape(verts),30,RGBA(0,0,0,0.2)), + bg=:pink, fg=:darkblue, xlim = (0,1), ylim=(0,1), leg=false) end)] ), PlotExample("Contours", - "Any value for fill works here. We first build a filled contour from a function, then an unfilled contour from a matrix.", +""" +Any value for fill works here. We first build a filled contour from a function, then an +unfilled contour from a matrix. +""", [:(begin x = 1:0.5:20 y = 1:0.5:10 @@ -261,8 +314,9 @@ PlotExample("DataFrames", PlotExample("Groups and Subplots", "", [:(begin - group = rand(map(i->"group $i",1:4),100) - plot(rand(100), layout=@layout([a b;c]), group=group, linetype=[:bar :scatter :steppre]) +group = rand(map(i->"group $i",1:4),100) +plot(rand(100), layout=@layout([a b;c]), group=group, + linetype=[:bar :scatter :steppre]) end)] ), @@ -322,16 +376,24 @@ PlotExample("Animation with subplots", ), PlotExample("Spy", - "For a matrix `mat` with unique nonzeros `spy(mat)` returns a colorless plot. If `mat` has various different nonzero values, a colorbar is added. The colorbar can be disabled with `legend = nothing`. As always, the marker shape and size can be changed with `spy(mat, markersize = 3, markershape = :star)`.", +""" +For a matrix `mat` with unique nonzeros `spy(mat)` returns a colorless plot. If `mat` +has various different nonzero values, a colorbar is added. The colorbar can be disabled +with `legend = nothing`. As always, the marker shape and size can be changed with +`spy(mat, markersize = 3, markershape = :star)`. +""", [:(begin - a = spdiagm((ones(50), ones(49), ones(49), ones(40), ones(40)),(0, 1, -1, 10, -10)) - b = spdiagm((1:50, 1:49, 1:49, 1:40, 1:40),(0, 1, -1, 10, -10)) - plot(spy(a, markershape = :dtriangle), spy(b), markersize = 3, title = ["Unique nonzeros" "Different nonzeros"]) +a = spdiagm((ones(50), ones(49), ones(49), ones(40), ones(40)),(0, 1, -1, 10, -10)) +b = spdiagm((1:50, 1:49, 1:49, 1:40, 1:40),(0, 1, -1, 10, -10)) +plot(spy(a, markershape = :dtriangle), spy(b), markersize = 3, + title = ["Unique nonzeros" "Different nonzeros"]) end)] ), PlotExample("Magic grid argument", - "The grid lines can be modified individually for each axis with the magic `grid` argument.", +""" +The grid lines can be modified individually for each axis with the magic `grid` argument. +""", [:(begin x = rand(10) p1 = plot(x, title = "Default looks") @@ -343,10 +405,14 @@ PlotExample("Magic grid argument", ), PlotExample("Framestyle", - "The style of the frame/axes of a (sub)plot can be changed with the `framestyle` attribute. The default framestyle is `:axes`.", +""" +The style of the frame/axes of a (sub)plot can be changed with the `framestyle` +attribute. The default framestyle is `:axes`. +""", [:(begin - histogram(fill(randn(1000), 5), framestyle = [:box :semi :axes :grid :none], - title = [":box" ":semi" ":axes" ":grid" ":none"], color = RowVector(1:5), layout = 5, label = "") +histogram(fill(randn(1000), 5), framestyle = [:box :semi :axes :grid :none], + title = [":box" ":semi" ":axes" ":grid" ":none"], + color = RowVector(1:5), layout = 5, label = "") end)] ), From 5d0adb178387f8e199713be469fdc702c7639c4f Mon Sep 17 00:00:00 2001 From: JackDevine Date: Tue, 5 Dec 2017 08:36:04 +1300 Subject: [PATCH 2/2] Add comma --- src/examples.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples.jl b/src/examples.jl index 27bf7d32..e43fa6fe 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -380,7 +380,7 @@ PlotExample("Spy", For a matrix `mat` with unique nonzeros `spy(mat)` returns a colorless plot. If `mat` has various different nonzero values, a colorbar is added. The colorbar can be disabled with `legend = nothing`. -""" +""", [:(begin a = spdiagm((ones(50), ones(49), ones(49), ones(40), ones(40)),(0, 1, -1, 10, -10)) b = spdiagm((1:50, 1:49, 1:49, 1:40, 1:40),(0, 1, -1, 10, -10))