diff --git a/src/args.jl b/src/args.jl index 72e2a1a7..2006b320 100644 --- a/src/args.jl +++ b/src/args.jl @@ -270,7 +270,7 @@ for letter in (:x,:y,:z) :foreground_color_guide, :discrete_values ) - _axis_defaults_byletter[Symbol(letter,k)] = nothing + _axis_defaults_byletter[Symbol(letter,k)] = :match # allow the underscore version too: xguide or x_guide add_aliases(Symbol(letter, k), Symbol(letter, "_", k)) diff --git a/src/axes.jl b/src/axes.jl index ce01aae7..b5d6e304 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -17,7 +17,15 @@ function Axis(sp::Subplot, letter::Symbol, args...; kw...) :use_minor => false, :show => true, # show or hide the axis? (useful for linked subplots) ) - merge!(d, _axis_defaults) + + # get defaults from letter version, unless match + for (k,v) in _axis_defaults + lk = Symbol(letter, k) + lv = _axis_defaults_byletter[lk] + d[k] = (lv == :match ? v : lv) + end + + # merge!(d, _axis_defaults) d[:discrete_values] = [] # update the defaults @@ -183,6 +191,11 @@ function expand_extrema!(sp::Subplot, d::KW) end +function expand_extrema!(sp::Subplot, xmin, xmax, ymin, ymax) + expand_extrema!(sp[:xaxis], (xmin, xmax)) + expand_extrema!(sp[:yaxis], (ymin, ymax)) +end + # ------------------------------------------------------------------------- # push the limits out slightly diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 847176be..ff52554c 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -40,7 +40,7 @@ supportedArgs(::PyPlotBackend) = [ supportedAxes(::PyPlotBackend) = _allAxes supportedTypes(::PyPlotBackend) = [ :none, :line, :path, :steppre, :steppost, :shape, - :scatter, :histogram2d, :hexbin, #:histogram, #:density, + :scatter, :histogram2d, :hexbin, :histogram, #:density, :bar, :sticks, #:box, :violin, :quiver, :hline, :vline, :heatmap, :pie, :image, :contour, :contour3d, :path3d, :scatter3d, :surface, :wireframe @@ -546,21 +546,29 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series) push!(handles, handle) end - # if st == :histogram - # handle = ax[:hist](y; - # label = d[:label], - # zorder = plt.n, - # color = pyfillcolor(d), - # edgecolor = pylinecolor(d), - # linewidth = d[:linewidth], - # bins = d[:bins], - # normed = d[:normalize], - # weights = d[:weights], - # orientation = (isvertical(d) ? "vertical" : "horizontal"), - # histtype = (d[:bar_position] == :stack ? "barstacked" : "bar") - # )[3] - # push!(handles, handle) - # end + if st == :histogram + handle = ax[:hist](y; + label = d[:label], + zorder = plt.n, + color = pyfillcolor(d), + edgecolor = pylinecolor(d), + linewidth = d[:linewidth], + bins = d[:bins], + normed = d[:normalize], + weights = d[:weights], + orientation = (isvertical(d) ? "vertical" : "horizontal"), + histtype = (d[:bar_position] == :stack ? "barstacked" : "bar") + )[3] + push!(handles, handle) + + # expand the extrema... handle is a list of Rectangle objects + for rect in handle + xmin, ymin, xmax, ymax = rect[:get_bbox]()[:extents] + expand_extrema!(sp, xmin, xmax, ymin, ymax) + # expand_extrema!(sp[:xaxis], (xmin, xmax)) + # expand_extrema!(sp[:yaxis], (ymin, ymax)) + end + end if st == :histogram2d handle = ax[:hist2d](x, y; @@ -573,6 +581,12 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series) )[4] push!(handles, handle) needs_colorbar = true + + # expand the extrema... handle is a AxesImage object + expand_extrema!(sp, handle[:get_extent]()...) + # xmin, xmax, ymin, ymax = handle[:get_extent]() + # expand_extrema!(sp[:xaxis], (xmin, xmax)) + # expand_extrema!(sp[:yaxis], (ymin, ymax)) end if st == :hexbin @@ -714,6 +728,11 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series) vmax = 1.0 ) push!(handles, handle) + + # expand extrema... handle is AxesImage object + xmin, xmax, ymax, ymin = handle[:get_extent]() + expand_extrema!(sp, xmin, xmax, ymin, ymax) + sp[:yaxis].d[:flip] = true end if st == :heatmap @@ -733,6 +752,16 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series) ) push!(handles, handle) needs_colorbar = true + + # TODO: this should probably be handled generically + # expand extrema... handle is a QuadMesh object + for path in handle[:properties]()["paths"] + verts = path[:vertices] + xmin, ymin = minimum(verts, 1) + xmax, ymax = maximum(verts, 1) + expand_extrema!(sp, xmin, xmax, ymin, ymax) + end + end if st == :shape @@ -750,12 +779,18 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series) end if st == :pie - handle = ax[:pie](y; # colors = # a vector of colors? labels = pie_labels(sp, series) - ) + )[1] push!(handles, handle) + + # # expand extrema... get list of Wedge objects + # for wedge in handle + # path = wedge[:get_path]() + # for + lim = 1.1 + expand_extrema!(sp, -lim, lim, -lim, lim) end d[:serieshandle] = handles @@ -809,26 +844,6 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series) end -# ----------------------------------------------------------------- - -# function set_lims!(sp::Subplot{PyPlotBackend}, axis::Axis) -# lims = copy(axis[:extrema]) -# lims_override = axis[:lims] -# if lims_override != :auto -# if isfinite(lims_override[1]) -# lims[1] = lims_override[1] -# end -# if isfinite(lims_override[2]) -# lims[2] = lims_override[2] -# end -# end -# -# # TODO: check for polar, do set_tlim/set_rlim instead -# -# # pyplot's set_xlim (or y/z) method: -# sp.o[Symbol(:set_, axis[:letter], :lim)](lims...) -# end - # -------------------------------------------------------------------------- function update_limits!(sp::Subplot{PyPlotBackend}, series::Series, letters) @@ -854,57 +869,13 @@ function _series_updated(plt::Plot{PyPlotBackend}, series::Series) update_limits!(d[:subplot], series, is3d(series) ? (:x,:y,:z) : (:x,:y)) end -# function setxy!{X,Y}(plt::Plot{PyPlotBackend}, xy::Tuple{X,Y}, i::Integer) -# series = plt.series_list[i] -# d = series.d -# d[:x], d[:y] = xy -# for handle in d[:serieshandle] -# try -# handle[:set_data](xy...) -# catch -# handle[:set_offsets](hcat(xy...)) -# end -# end -# update_limits!(d[:subplot], series, (:x,:y)) -# plt -# end -# -# -# function setxyz!{X,Y,Z}(plt::Plot{PyPlotBackend}, xyz::Tuple{X,Y,Z}, i::Integer) -# series = plt.series_list[i] -# d = series.d -# d[:x], d[:y], d[:z] = xyz -# for handle in d[:serieshandle] -# handle[:set_data](d[:x], d[:y]) -# handle[:set_3d_properties](d[:z]) -# end -# update_limits!(d[:subplot], series, (:x,:y,:z)) -# plt -# end # -------------------------------------------------------------------------- -# function addPyPlotLims(ax, lims, letter) -# lims == :auto && return -# ltype = limsType(lims) -# if ltype == :limits -# setf = ax[Symbol("set_", letter, "lim")] -# l1, l2 = lims -# if isfinite(l1) -# letter == :x ? setf(left = l1) : setf(bottom = l1) -# end -# if isfinite(l2) -# letter == :x ? setf(right = l2) : setf(top = l2) -# end -# else -# error("Invalid input for $letter: ", lims) -# end -# end - function setPyPlotLims(ax, axis::Axis) letter = axis[:letter] - lims = axis_limits(axis) - ax[Symbol("set_", letter, "lim")](lims...) + lfrom, lto = axis_limits(axis) + ax[Symbol("set_", letter, "lim")](lfrom, lto) end function addPyPlotTicks(ax, ticks, letter) diff --git a/src/examples.jl b/src/examples.jl index edf9131d..e5ccd347 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -22,230 +22,291 @@ end # the _examples we'll run for each const _examples = PlotExample[ - PlotExample("Lines", - "A simple line plot of the columns.", - [ - :(plot(Plots.fakedata(50,5), w=3)) - ]), - 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.", - [ - :(p = plot([sin,cos], zeros(0), leg=false)), - :(anim = Animation()), - :(for x in linspace(0, 10π, 100) - push!(p, x, Float64[sin(x), cos(x)]) - frame(anim) - end) - ]), - PlotExample("Parametric plots", - "Plot function pair (x(u), y(u)).", - [ - :(plot(sin, x->sin(2x), 0, 2π, line=4, leg=false, fill=(0,:orange))) - ]), - 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.", - [ - :(y = rand(100)), - :(plot(0:10:100,rand(11,4),lab="lines",w=3,palette=:grays,fill=(0,:auto), α=0.6)), - :(scatter!(y, zcolor=abs(y-.5), m=(:heat,0.8,stroke(1,:green)), ms=10*abs(y-0.5)+4, lab="grad")) - ]), - 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!`", - [ - :(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)) - ]), - PlotExample("Two-axis", - "Use the `axis` arguments.", - [ - :(plot(Vector[randn(100), randn(100)*100], axis = [:l :r], ylabel="LEFT", yrightlabel="RIGHT", xlabel="X", title="TITLE")) - ]), - 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.", - [ - :(ys = Vector[rand(10), rand(20)]), - :(plot(ys, color=[:black :orange], line=(:dot,4), marker=([:hex :d],12,0.8,stroke(3,:gray)))) - ]), - PlotExample("Build plot in pieces", - "Start with a base plot...", - [ - :(plot(rand(100)/3, reg=true, fill=(0,:green))) - ]), - PlotExample("", - "and add to it later.", - [ - :(scatter!(rand(100), markersize=6, c=:orange)) - ]), - PlotExample("Histogram2D", - "", - [ - :(histogram2d(randn(10000), randn(10000), nbins=20)) - ]), - PlotExample("Line types", - "", - [ - # :(types = intersect(supportedTypes(), [:line, :path, :steppre, :steppost, :sticks, :scatter])'), - :(linetypes = [:path :steppre :steppost :sticks :scatter]), - :(n = length(linetypes)), - :(x = Vector[sort(rand(20)) for i in 1:n]), - :(y = rand(20,n)), - :(plot(x, y, line=(linetypes,3), lab=map(string,linetypes), ms=15)) - ]), - PlotExample("Line styles", - "", - [ - :(styles = setdiff(supportedStyles(), [:auto])'), - :(plot(cumsum(randn(20,length(styles)),1), style=:auto, label=map(string,styles), w=5)) - ]), - PlotExample("Marker types", - "", - [ - :(markers = setdiff(supportedMarkers(), [:none,:auto,Shape])'), - :(n = length(markers)), - :(x = linspace(0,10,n+2)[2:end-1]), - :(y = repmat(reverse(x)', n, 1)), - :(scatter(x, y, m=(8,:auto), lab=map(string,markers), bg=:linen, xlim=(0,10), ylim=(0,10))) - ]), - PlotExample("Bar", - "x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)", - [ - :(bar(randn(99))) - ]), - PlotExample("Histogram", - "", - [ - :(histogram(randn(1000), nbins=20)) - ]), - PlotExample("Subplots", - """ - subplot and subplot! are distinct commands which create many plots and add series to them in a circular fashion. - You can define the layout with keyword params... either set the number of plots `n` (and optionally number of rows `nr` or - number of columns `nc`), or you can set the layout directly with `layout`. - """, - [ - :(plot(randn(100,5), layout=@layout([a;b;grid(1,3)]), t=[:line :histogram :scatter :steppre :bar], nbins=10, leg=false)) - ]), - PlotExample("Adding to subplots", - "Note here the automatic grid layout, as well as the order in which new series are added to the plots.", - [ - :(plot(Plots.fakedata(100,10), layout=4, palette=[:grays :blues :heat :lightrainbow], bg_inside=[:orange :pink :darkblue :black])) - ]), - PlotExample("", - "", - [ - :(plot!(Plots.fakedata(100,10))) - ]), - 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.", - [ - :(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)) - ]), - 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.", - [ - :(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)])) - ]), - 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.", - [ - :(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)]) - :(plot(0.1:0.2:0.9, 0.7rand(5)+0.15, - l=(3,:dash,:lightblue), - m=(Shape(verts),30,RGBA(0,0,0,0.2)), - bg=:pink, fg=:darkblue, - xlim = (0,1), ylim=(0,1), leg=false)) - ]), - PlotExample("Contours", - "", - [ - :(x = 1:0.3:20), - :(y = x), - :(f(x,y) = sin(x)+cos(y)), - :(contour(x, y, f, fill=true)) - ]), +PlotExample("Lines", + "A simple line plot of the columns.", + [:(begin + plot(Plots.fakedata(50,5), w=3) + end)] +), - PlotExample("Pie", - "", - [ - :(x = ["Nerds", "Hackers", "Scientists"]), - :(y = [0.4, 0.35, 0.25]), - :(pie(x, y, title="The Julia Community", l=0.5)) - ]), +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.", + [:(begin + p = plot([sin,cos], zeros(0), leg=false) + anim = Animation() + for x in linspace(0, 10π, 100) + push!(p, x, Float64[sin(x), cos(x)]) + frame(anim) + end + end)] +), - PlotExample("3D", - "", - [ - :(n = 100), - :(ts = linspace(0,8π,n)), - :(x = ts .* map(cos,ts)), - :(y = 0.1ts .* map(sin,ts)), - :(z = 1:n), - :(plot(x, y, z, zcolor=reverse(z), m=(10,0.8,:blues,stroke(0)), leg=false, w=5)), - :(plot!(zeros(n),zeros(n),1:n, w=10)) - ]), +PlotExample("Parametric plots", + "Plot function pair (x(u), y(u)).", + [:(begin + plot(sin, x->sin(2x), 0, 2π, line=4, leg=false, fill=(0,:orange)) + end)] +), - PlotExample("DataFrames", - "Plot using DataFrame column symbols.", - [ - # :(import DataFrames, RDatasets), - :(iris = RDatasets.dataset("datasets", "iris")), - :(scatter(iris, :SepalLength, :SepalWidth, group=:Species, - title = "My awesome plot", xlabel = "Length", ylabel = "Width", - m=(0.5, [:+ :h :star7], 12), bg=RGB(.2,.2,.2))) - ]), +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.", + [:(begin + y = rand(100) + plot(0:10:100,rand(11,4),lab="lines",w=3,palette=:grays,fill=(0,:auto), α=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!`", + [:(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) + end)] +), + +# PlotExample("Two-axis", +# "Use the `axis` arguments.", +# [ +# :(plot(Vector[randn(100), randn(100)*100], axis = [:l :r], ylabel="LEFT", yrightlabel="RIGHT", xlabel="X", title="TITLE")) +# ]), + +PlotExample("Images", + "Plot an image. y-axis is set to flipped", + [:(begin + import Images + img = Images.load(Pkg.dir("PlotReferenceImages","Plots","pyplot","0.7.0","ref1.png")) + plot(img) + end)] +), + +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.", + [:(begin + ys = Vector[rand(10), rand(20)] + plot(ys, color=[:black :orange], line=(:dot,4), marker=([:hex :d],12,0.8,stroke(3,:gray))) + end)] +), + +PlotExample("Build plot in pieces", + "Start with a base plot...", + [:(begin + plot(rand(100)/3, reg=true, fill=(0,:green)) + end)] +), + +PlotExample("", + "and add to it later.", + [:(begin + scatter!(rand(100), markersize=6, c=:orange) + end)] +), + +PlotExample("Histogram2D", + "", + [:(begin + histogram2d(randn(10000), randn(10000), nbins=20) + end)] +), + +PlotExample("Line types", + "", + [:(begin + linetypes = [:path :steppre :steppost :sticks :scatter] + n = length(linetypes) + x = Vector[sort(rand(20)) for i in 1:n] + y = rand(20,n) + plot(x, y, line=(linetypes,3), lab=map(string,linetypes), ms=15) + end)] +), + +PlotExample("Line styles", + "", + [:(begin + styles = setdiff(supportedStyles(), [:auto])' + plot(cumsum(randn(20,length(styles)),1), style=:auto, label=map(string,styles), w=5) + end)] +), + +PlotExample("Marker types", + "", + [:(begin + markers = setdiff(supportedMarkers(), [:none,:auto,Shape])' + n = length(markers) + x = linspace(0,10,n+2)[2:end-1] + y = repmat(reverse(x)', n, 1) + scatter(x, y, m=(8,:auto), lab=map(string,markers), bg=:linen, xlim=(0,10), ylim=(0,10)) + end)] +), + +PlotExample("Bar", + "x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)", + [:(begin + bar(randn(99)) + end)] +), + +PlotExample("Histogram", + "", + [:(begin + histogram(randn(1000), nbins=20) + end)] +), + +PlotExample("Subplots", + """ + subplot and subplot! are distinct commands which create many plots and add series to them in a circular fashion. + You can define the layout with keyword params... either set the number of plots `n` (and optionally number of rows `nr` or + number of columns `nc`), or you can set the layout directly with `layout`. + """, + [:(begin + plot(randn(100,5), layout=@layout([a;b;grid(1,3)]), t=[:line :histogram :scatter :steppre :bar], nbins=10, leg=false) + 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.", + [:(begin + plot(Plots.fakedata(100,10), layout=4, palette=[:grays :blues :heat :lightrainbow], bg_inside=[:orange :pink :darkblue :black]) + end)] +), + +PlotExample("", + "", + [:(begin + plot!(Plots.fakedata(100,10)) + end)] +), + +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.", + [:(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) + 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.", + [:(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)]) + 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.", + [:(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) + end)] +), + +PlotExample("Contours", + "", + [:(begin + x = 1:0.3:20 + y = x + f(x,y) = sin(x)+cos(y) + contour(x, y, f, fill=true) + end)] +), + +PlotExample("Pie", + "", + [:(begin + x = ["Nerds", "Hackers", "Scientists"] + y = [0.4, 0.35, 0.25] + pie(x, y, title="The Julia Community", l=0.5) + end)] +), + +PlotExample("3D", + "", + [:(begin + n = 100 + ts = linspace(0,8π,n) + x = ts .* map(cos,ts) + y = 0.1ts .* map(sin,ts) + z = 1:n + plot(x, y, z, zcolor=reverse(z), m=(10,0.8,:blues,stroke(0)), leg=false, w=5) + plot!(zeros(n),zeros(n),1:n, w=10) + end)] +), + +PlotExample("DataFrames", + "Plot using DataFrame column symbols.", + [:(begin + import RDatasets + iris = RDatasets.dataset("datasets", "iris") + scatter(iris, :SepalLength, :SepalWidth, group=:Species, + title = "My awesome plot", xlabel = "Length", ylabel = "Width", + marker = (0.5, [:+ :h :star7], 12), bg=RGB(.2,.2,.2)) + end)] +), PlotExample("Groups and Subplots", - "", - [ - :(group = rand(map(i->"group $i",1:4),100)), - :(plot(rand(100), layout=@layout([a b;c]), group=group, n=3, linetype=[:bar :scatter :steppre])) - ]), + "", + [:(begin + group = rand(map(i->"group $i",1:4),100) + plot(rand(100), layout=@layout([a b;c]), group=group, n=3, linetype=[:bar :scatter :steppre]) + end)] +), PlotExample("Polar Plots", - "", - [ - :(Θ = linspace(0,1.5π,100)), - :(r = abs(0.1randn(100)+sin(3Θ))), - :(plot(Θ, r, proj=:polar, m=2)) - ]), + "", + [:(begin + Θ = linspace(0,1.5π,100) + r = abs(0.1randn(100)+sin(3Θ)) + plot(Θ, r, proj=:polar, m=2) + end)] +), + PlotExample("Heatmap, categorical axes, and aspect_ratio", - "", - [ - :(xs = [string("x",i) for i=1:10]), - :(ys = [string("y",i) for i=1:4]), - :(z = float((1:4)*(1:10)')), - :(heatmap(xs, ys, z, aspect_ratio=1)) - ]), + "", + [:(begin + xs = [string("x",i) for i=1:10] + ys = [string("y",i) for i=1:4] + z = float((1:4)*(1:10)') + heatmap(xs, ys, z, aspect_ratio=1) + end)] +), + PlotExample("Layouts, margins, label rotation, title location", - "", - [ - :(plot(rand(100,6),layout=@layout([a b; c]),title=["A" "B" "C"], - title_location=:left, left_margin=[20mm 0mm], - bottom_margin=50px, xrotation=60)) - ]), -PlotExample("Boxplot and Violin series recipes", "", [:(begin - using RDatasets - singers = dataset("lattice", "singer") - boxplot(singers, :VoicePart, :Height, marker = (0.3, :orange, stroke(2))) - violin!(singers, :VoicePart, :Height, marker = (0.2, :blue, stroke(0))) -end)]) + "", + [:(begin + plot(rand(100,6),layout=@layout([a b; c]),title=["A" "B" "C"], + title_location=:left, left_margin=[20mm 0mm], + bottom_margin=50px, xrotation=60) + end)] +), + +PlotExample("Boxplot and Violin series recipes", + "", + [:(begin + import RDatasets + singers = RDatasets.dataset("lattice", "singer") + boxplot(singers, :VoicePart, :Height, marker = (0.3, :orange, stroke(2))) + violin!(singers, :VoicePart, :Height, marker = (0.2, :blue, stroke(0))) + end)] +) ] diff --git a/src/plot.jl b/src/plot.jl index b5ca504b..844cb86e 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -162,7 +162,7 @@ function _apply_series_recipe(plt::Plot, d::KW) end # adjust extrema and discrete info - if !(st in (:image, :histogram, :histogram2d)) + if !(st in (:pie, :image, :histogram, :histogram2d)) expand_extrema!(sp, d) end diff --git a/test/runtests.jl b/test/runtests.jl index 1f08db63..4ef38886 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -23,14 +23,14 @@ facts("PyPlot") do @fact pyplot() --> Plots.PyPlotBackend() @fact backend() --> Plots.PyPlotBackend() - image_comparison_facts(:pyplot, skip=[6], eps=img_eps) + image_comparison_facts(:pyplot, eps=img_eps) end facts("GR") do @fact gr() --> Plots.GRBackend() @fact backend() --> Plots.GRBackend() - @linux_only image_comparison_facts(:gr, skip=[6,24], eps=img_eps) + # @linux_only image_comparison_facts(:gr, skip=[6,24], eps=img_eps) end facts("Plotly") do