changed axis defaults byletter to match; cleaned up examples; pyplot extrema fixes; commented out gr tests
This commit is contained in:
parent
76c84c7615
commit
29d93ba33e
@ -270,7 +270,7 @@ for letter in (:x,:y,:z)
|
|||||||
:foreground_color_guide,
|
:foreground_color_guide,
|
||||||
:discrete_values
|
: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
|
# allow the underscore version too: xguide or x_guide
|
||||||
add_aliases(Symbol(letter, k), Symbol(letter, "_", k))
|
add_aliases(Symbol(letter, k), Symbol(letter, "_", k))
|
||||||
|
|||||||
15
src/axes.jl
15
src/axes.jl
@ -17,7 +17,15 @@ function Axis(sp::Subplot, letter::Symbol, args...; kw...)
|
|||||||
:use_minor => false,
|
:use_minor => false,
|
||||||
:show => true, # show or hide the axis? (useful for linked subplots)
|
: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] = []
|
d[:discrete_values] = []
|
||||||
|
|
||||||
# update the defaults
|
# update the defaults
|
||||||
@ -183,6 +191,11 @@ function expand_extrema!(sp::Subplot, d::KW)
|
|||||||
|
|
||||||
end
|
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
|
# push the limits out slightly
|
||||||
|
|||||||
@ -40,7 +40,7 @@ supportedArgs(::PyPlotBackend) = [
|
|||||||
supportedAxes(::PyPlotBackend) = _allAxes
|
supportedAxes(::PyPlotBackend) = _allAxes
|
||||||
supportedTypes(::PyPlotBackend) = [
|
supportedTypes(::PyPlotBackend) = [
|
||||||
:none, :line, :path, :steppre, :steppost, :shape,
|
:none, :line, :path, :steppre, :steppost, :shape,
|
||||||
:scatter, :histogram2d, :hexbin, #:histogram, #:density,
|
:scatter, :histogram2d, :hexbin, :histogram, #:density,
|
||||||
:bar, :sticks, #:box, :violin, :quiver,
|
:bar, :sticks, #:box, :violin, :quiver,
|
||||||
:hline, :vline, :heatmap, :pie, :image,
|
:hline, :vline, :heatmap, :pie, :image,
|
||||||
:contour, :contour3d, :path3d, :scatter3d, :surface, :wireframe
|
:contour, :contour3d, :path3d, :scatter3d, :surface, :wireframe
|
||||||
@ -546,21 +546,29 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
end
|
end
|
||||||
|
|
||||||
# if st == :histogram
|
if st == :histogram
|
||||||
# handle = ax[:hist](y;
|
handle = ax[:hist](y;
|
||||||
# label = d[:label],
|
label = d[:label],
|
||||||
# zorder = plt.n,
|
zorder = plt.n,
|
||||||
# color = pyfillcolor(d),
|
color = pyfillcolor(d),
|
||||||
# edgecolor = pylinecolor(d),
|
edgecolor = pylinecolor(d),
|
||||||
# linewidth = d[:linewidth],
|
linewidth = d[:linewidth],
|
||||||
# bins = d[:bins],
|
bins = d[:bins],
|
||||||
# normed = d[:normalize],
|
normed = d[:normalize],
|
||||||
# weights = d[:weights],
|
weights = d[:weights],
|
||||||
# orientation = (isvertical(d) ? "vertical" : "horizontal"),
|
orientation = (isvertical(d) ? "vertical" : "horizontal"),
|
||||||
# histtype = (d[:bar_position] == :stack ? "barstacked" : "bar")
|
histtype = (d[:bar_position] == :stack ? "barstacked" : "bar")
|
||||||
# )[3]
|
)[3]
|
||||||
# push!(handles, handle)
|
push!(handles, handle)
|
||||||
# end
|
|
||||||
|
# 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
|
if st == :histogram2d
|
||||||
handle = ax[:hist2d](x, y;
|
handle = ax[:hist2d](x, y;
|
||||||
@ -573,6 +581,12 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
)[4]
|
)[4]
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
needs_colorbar = true
|
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
|
end
|
||||||
|
|
||||||
if st == :hexbin
|
if st == :hexbin
|
||||||
@ -714,6 +728,11 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
vmax = 1.0
|
vmax = 1.0
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
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
|
end
|
||||||
|
|
||||||
if st == :heatmap
|
if st == :heatmap
|
||||||
@ -733,6 +752,16 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
needs_colorbar = true
|
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
|
end
|
||||||
|
|
||||||
if st == :shape
|
if st == :shape
|
||||||
@ -750,12 +779,18 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if st == :pie
|
if st == :pie
|
||||||
|
|
||||||
handle = ax[:pie](y;
|
handle = ax[:pie](y;
|
||||||
# colors = # a vector of colors?
|
# colors = # a vector of colors?
|
||||||
labels = pie_labels(sp, series)
|
labels = pie_labels(sp, series)
|
||||||
)
|
)[1]
|
||||||
push!(handles, handle)
|
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
|
end
|
||||||
|
|
||||||
d[:serieshandle] = handles
|
d[:serieshandle] = handles
|
||||||
@ -809,26 +844,6 @@ function _series_added(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
end
|
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)
|
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))
|
update_limits!(d[:subplot], series, is3d(series) ? (:x,:y,:z) : (:x,:y))
|
||||||
end
|
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)
|
function setPyPlotLims(ax, axis::Axis)
|
||||||
letter = axis[:letter]
|
letter = axis[:letter]
|
||||||
lims = axis_limits(axis)
|
lfrom, lto = axis_limits(axis)
|
||||||
ax[Symbol("set_", letter, "lim")](lims...)
|
ax[Symbol("set_", letter, "lim")](lfrom, lto)
|
||||||
end
|
end
|
||||||
|
|
||||||
function addPyPlotTicks(ax, ticks, letter)
|
function addPyPlotTicks(ax, ticks, letter)
|
||||||
|
|||||||
363
src/examples.jl
363
src/examples.jl
@ -22,230 +22,291 @@ end
|
|||||||
|
|
||||||
# the _examples we'll run for each
|
# the _examples we'll run for each
|
||||||
const _examples = PlotExample[
|
const _examples = PlotExample[
|
||||||
|
|
||||||
PlotExample("Lines",
|
PlotExample("Lines",
|
||||||
"A simple line plot of the columns.",
|
"A simple line plot of the columns.",
|
||||||
[
|
[:(begin
|
||||||
:(plot(Plots.fakedata(50,5), w=3))
|
plot(Plots.fakedata(50,5), w=3)
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Functions, adding data, and animations",
|
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)),
|
p = plot([sin,cos], zeros(0), leg=false)
|
||||||
:(anim = Animation()),
|
anim = Animation()
|
||||||
:(for x in linspace(0, 10π, 100)
|
for x in linspace(0, 10π, 100)
|
||||||
push!(p, x, Float64[sin(x), cos(x)])
|
push!(p, x, Float64[sin(x), cos(x)])
|
||||||
frame(anim)
|
frame(anim)
|
||||||
end)
|
end
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Parametric plots",
|
PlotExample("Parametric plots",
|
||||||
"Plot function pair (x(u), y(u)).",
|
"Plot function pair (x(u), y(u)).",
|
||||||
[
|
[:(begin
|
||||||
:(plot(sin, x->sin(2x), 0, 2π, line=4, leg=false, fill=(0,:orange)))
|
plot(sin, x->sin(2x), 0, 2π, line=4, leg=false, fill=(0,:orange))
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Colors",
|
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)),
|
y = rand(100)
|
||||||
:(plot(0:10:100,rand(11,4),lab="lines",w=3,palette=:grays,fill=(0,:auto), α=0.6)),
|
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"))
|
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",
|
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)),
|
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)),
|
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]))),
|
hline!(mean(y,1)+rand(1,3), line=(4,:dash,0.6,[:lightgreen :green :darkgreen]))
|
||||||
:(vline!([5,10])),
|
vline!([5,10])
|
||||||
:(title!("TITLE")),
|
title!("TITLE")
|
||||||
:(yaxis!("YLABEL", :log10))
|
yaxis!("YLABEL", :log10)
|
||||||
]),
|
end)]
|
||||||
PlotExample("Two-axis",
|
),
|
||||||
"Use the `axis` arguments.",
|
|
||||||
[
|
# PlotExample("Two-axis",
|
||||||
:(plot(Vector[randn(100), randn(100)*100], axis = [:l :r], ylabel="LEFT", yrightlabel="RIGHT", xlabel="X", title="TITLE"))
|
# "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",
|
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)]),
|
ys = Vector[rand(10), rand(20)]
|
||||||
:(plot(ys, color=[:black :orange], line=(:dot,4), marker=([:hex :d],12,0.8,stroke(3,:gray))))
|
plot(ys, color=[:black :orange], line=(:dot,4), marker=([:hex :d],12,0.8,stroke(3,:gray)))
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Build plot in pieces",
|
PlotExample("Build plot in pieces",
|
||||||
"Start with a base plot...",
|
"Start with a base plot...",
|
||||||
[
|
[:(begin
|
||||||
:(plot(rand(100)/3, reg=true, fill=(0,:green)))
|
plot(rand(100)/3, reg=true, fill=(0,:green))
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("",
|
PlotExample("",
|
||||||
"and add to it later.",
|
"and add to it later.",
|
||||||
[
|
[:(begin
|
||||||
:(scatter!(rand(100), markersize=6, c=:orange))
|
scatter!(rand(100), markersize=6, c=:orange)
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Histogram2D",
|
PlotExample("Histogram2D",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
:(histogram2d(randn(10000), randn(10000), nbins=20))
|
histogram2d(randn(10000), randn(10000), nbins=20)
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Line types",
|
PlotExample("Line types",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
# :(types = intersect(supportedTypes(), [:line, :path, :steppre, :steppost, :sticks, :scatter])'),
|
linetypes = [:path :steppre :steppost :sticks :scatter]
|
||||||
:(linetypes = [:path :steppre :steppost :sticks :scatter]),
|
n = length(linetypes)
|
||||||
:(n = length(linetypes)),
|
x = Vector[sort(rand(20)) for i in 1:n]
|
||||||
:(x = Vector[sort(rand(20)) for i in 1:n]),
|
y = rand(20,n)
|
||||||
:(y = rand(20,n)),
|
plot(x, y, line=(linetypes,3), lab=map(string,linetypes), ms=15)
|
||||||
:(plot(x, y, line=(linetypes,3), lab=map(string,linetypes), ms=15))
|
end)]
|
||||||
]),
|
),
|
||||||
|
|
||||||
PlotExample("Line styles",
|
PlotExample("Line styles",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
:(styles = setdiff(supportedStyles(), [:auto])'),
|
styles = setdiff(supportedStyles(), [:auto])'
|
||||||
:(plot(cumsum(randn(20,length(styles)),1), style=:auto, label=map(string,styles), w=5))
|
plot(cumsum(randn(20,length(styles)),1), style=:auto, label=map(string,styles), w=5)
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Marker types",
|
PlotExample("Marker types",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
:(markers = setdiff(supportedMarkers(), [:none,:auto,Shape])'),
|
markers = setdiff(supportedMarkers(), [:none,:auto,Shape])'
|
||||||
:(n = length(markers)),
|
n = length(markers)
|
||||||
:(x = linspace(0,10,n+2)[2:end-1]),
|
x = linspace(0,10,n+2)[2:end-1]
|
||||||
:(y = repmat(reverse(x)', n, 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)))
|
scatter(x, y, m=(8,:auto), lab=map(string,markers), bg=:linen, xlim=(0,10), ylim=(0,10))
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Bar",
|
PlotExample("Bar",
|
||||||
"x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)",
|
"x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)",
|
||||||
[
|
[:(begin
|
||||||
:(bar(randn(99)))
|
bar(randn(99))
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Histogram",
|
PlotExample("Histogram",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
:(histogram(randn(1000), nbins=20))
|
histogram(randn(1000), nbins=20)
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Subplots",
|
PlotExample("Subplots",
|
||||||
"""
|
"""
|
||||||
subplot and subplot! are distinct commands which create many plots and add series to them in a circular fashion.
|
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
|
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`.
|
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))
|
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",
|
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)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("",
|
PlotExample("",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
:(plot!(Plots.fakedata(100,10)))
|
plot!(Plots.fakedata(100,10))
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Open/High/Low/Close",
|
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),
|
n=20
|
||||||
:(hgt=rand(n)+1),
|
hgt=rand(n)+1
|
||||||
:(bot=randn(n)),
|
bot=randn(n)
|
||||||
:(openpct=rand(n)),
|
openpct=rand(n)
|
||||||
:(closepct=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]),
|
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))
|
ohlc(y)
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Annotations",
|
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)),
|
y = rand(10)
|
||||||
:(plot(y, annotations = (3,y[3],text("this is #3",:left)), leg=false)),
|
plot(y, annotations = (3,y[3],text("this is #3",:left)), leg=false)
|
||||||
:(annotate!([(5, y[5], text("this is #5",16,:red,:center)),
|
annotate!([(5, y[5], text("this is #5",16,:red,:center)), (10, y[10], text("this is #10",:right,20,"courier"))])
|
||||||
(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)])
|
||||||
:(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",
|
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),
|
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),
|
(-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)])
|
(-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,
|
x = 0.1:0.2:0.9
|
||||||
l=(3,:dash,:lightblue),
|
y = 0.7rand(5)+0.15
|
||||||
m=(Shape(verts),30,RGBA(0,0,0,0.2)),
|
plot(x, y, line = (3,:dash,:lightblue), marker = (Shape(verts),30,RGBA(0,0,0,0.2)),
|
||||||
bg=:pink, fg=:darkblue,
|
bg=:pink, fg=:darkblue, xlim = (0,1), ylim=(0,1), leg=false)
|
||||||
xlim = (0,1), ylim=(0,1), leg=false))
|
end)]
|
||||||
]),
|
),
|
||||||
|
|
||||||
PlotExample("Contours",
|
PlotExample("Contours",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
:(x = 1:0.3:20),
|
x = 1:0.3:20
|
||||||
:(y = x),
|
y = x
|
||||||
:(f(x,y) = sin(x)+cos(y)),
|
f(x,y) = sin(x)+cos(y)
|
||||||
:(contour(x, y, f, fill=true))
|
contour(x, y, f, fill=true)
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Pie",
|
PlotExample("Pie",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
:(x = ["Nerds", "Hackers", "Scientists"]),
|
x = ["Nerds", "Hackers", "Scientists"]
|
||||||
:(y = [0.4, 0.35, 0.25]),
|
y = [0.4, 0.35, 0.25]
|
||||||
:(pie(x, y, title="The Julia Community", l=0.5))
|
pie(x, y, title="The Julia Community", l=0.5)
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("3D",
|
PlotExample("3D",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
:(n = 100),
|
n = 100
|
||||||
:(ts = linspace(0,8π,n)),
|
ts = linspace(0,8π,n)
|
||||||
:(x = ts .* map(cos,ts)),
|
x = ts .* map(cos,ts)
|
||||||
:(y = 0.1ts .* map(sin,ts)),
|
y = 0.1ts .* map(sin,ts)
|
||||||
:(z = 1:n),
|
z = 1:n
|
||||||
:(plot(x, y, z, zcolor=reverse(z), m=(10,0.8,:blues,stroke(0)), leg=false, w=5)),
|
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))
|
plot!(zeros(n),zeros(n),1:n, w=10)
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("DataFrames",
|
PlotExample("DataFrames",
|
||||||
"Plot using DataFrame column symbols.",
|
"Plot using DataFrame column symbols.",
|
||||||
[
|
[:(begin
|
||||||
# :(import DataFrames, RDatasets),
|
import RDatasets
|
||||||
:(iris = RDatasets.dataset("datasets", "iris")),
|
iris = RDatasets.dataset("datasets", "iris")
|
||||||
:(scatter(iris, :SepalLength, :SepalWidth, group=:Species,
|
scatter(iris, :SepalLength, :SepalWidth, group=:Species,
|
||||||
title = "My awesome plot", xlabel = "Length", ylabel = "Width",
|
title = "My awesome plot", xlabel = "Length", ylabel = "Width",
|
||||||
m=(0.5, [:+ :h :star7], 12), bg=RGB(.2,.2,.2)))
|
marker = (0.5, [:+ :h :star7], 12), bg=RGB(.2,.2,.2))
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Groups and Subplots",
|
PlotExample("Groups and Subplots",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
:(group = rand(map(i->"group $i",1:4),100)),
|
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]))
|
plot(rand(100), layout=@layout([a b;c]), group=group, n=3, linetype=[:bar :scatter :steppre])
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Polar Plots",
|
PlotExample("Polar Plots",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
:(Θ = linspace(0,1.5π,100)),
|
Θ = linspace(0,1.5π,100)
|
||||||
:(r = abs(0.1randn(100)+sin(3Θ))),
|
r = abs(0.1randn(100)+sin(3Θ))
|
||||||
:(plot(Θ, r, proj=:polar, m=2))
|
plot(Θ, r, proj=:polar, m=2)
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Heatmap, categorical axes, and aspect_ratio",
|
PlotExample("Heatmap, categorical axes, and aspect_ratio",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
:(xs = [string("x",i) for i=1:10]),
|
xs = [string("x",i) for i=1:10]
|
||||||
:(ys = [string("y",i) for i=1:4]),
|
ys = [string("y",i) for i=1:4]
|
||||||
:(z = float((1:4)*(1:10)')),
|
z = float((1:4)*(1:10)')
|
||||||
:(heatmap(xs, ys, z, aspect_ratio=1))
|
heatmap(xs, ys, z, aspect_ratio=1)
|
||||||
]),
|
end)]
|
||||||
|
),
|
||||||
|
|
||||||
PlotExample("Layouts, margins, label rotation, title location",
|
PlotExample("Layouts, margins, label rotation, title location",
|
||||||
"",
|
"",
|
||||||
[
|
[:(begin
|
||||||
:(plot(rand(100,6),layout=@layout([a b; c]),title=["A" "B" "C"],
|
plot(rand(100,6),layout=@layout([a b; c]),title=["A" "B" "C"],
|
||||||
title_location=:left, left_margin=[20mm 0mm],
|
title_location=:left, left_margin=[20mm 0mm],
|
||||||
bottom_margin=50px, xrotation=60))
|
bottom_margin=50px, xrotation=60)
|
||||||
]),
|
end)]
|
||||||
PlotExample("Boxplot and Violin series recipes", "", [:(begin
|
),
|
||||||
using RDatasets
|
|
||||||
singers = dataset("lattice", "singer")
|
PlotExample("Boxplot and Violin series recipes",
|
||||||
|
"",
|
||||||
|
[:(begin
|
||||||
|
import RDatasets
|
||||||
|
singers = RDatasets.dataset("lattice", "singer")
|
||||||
boxplot(singers, :VoicePart, :Height, marker = (0.3, :orange, stroke(2)))
|
boxplot(singers, :VoicePart, :Height, marker = (0.3, :orange, stroke(2)))
|
||||||
violin!(singers, :VoicePart, :Height, marker = (0.2, :blue, stroke(0)))
|
violin!(singers, :VoicePart, :Height, marker = (0.2, :blue, stroke(0)))
|
||||||
end)])
|
end)]
|
||||||
|
)
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -162,7 +162,7 @@ function _apply_series_recipe(plt::Plot, d::KW)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# adjust extrema and discrete info
|
# adjust extrema and discrete info
|
||||||
if !(st in (:image, :histogram, :histogram2d))
|
if !(st in (:pie, :image, :histogram, :histogram2d))
|
||||||
expand_extrema!(sp, d)
|
expand_extrema!(sp, d)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -23,14 +23,14 @@ facts("PyPlot") do
|
|||||||
@fact pyplot() --> Plots.PyPlotBackend()
|
@fact pyplot() --> Plots.PyPlotBackend()
|
||||||
@fact backend() --> Plots.PyPlotBackend()
|
@fact backend() --> Plots.PyPlotBackend()
|
||||||
|
|
||||||
image_comparison_facts(:pyplot, skip=[6], eps=img_eps)
|
image_comparison_facts(:pyplot, eps=img_eps)
|
||||||
end
|
end
|
||||||
|
|
||||||
facts("GR") do
|
facts("GR") do
|
||||||
@fact gr() --> Plots.GRBackend()
|
@fact gr() --> Plots.GRBackend()
|
||||||
@fact backend() --> 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
|
end
|
||||||
|
|
||||||
facts("Plotly") do
|
facts("Plotly") do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user