added dependency on Requires; added support for plotting tuples/FixedSizeArrays; added animate macro; legend ignores empty labels in gadfly/pyplot
This commit is contained in:
parent
ac3c041d6d
commit
5db9493d2b
@ -6,6 +6,7 @@ module Plots
|
|||||||
using Compat
|
using Compat
|
||||||
using Reexport
|
using Reexport
|
||||||
@reexport using Colors
|
@reexport using Colors
|
||||||
|
using Requires
|
||||||
|
|
||||||
export
|
export
|
||||||
Plot,
|
Plot,
|
||||||
@ -114,6 +115,7 @@ export
|
|||||||
Animation,
|
Animation,
|
||||||
frame,
|
frame,
|
||||||
gif,
|
gif,
|
||||||
|
@animate,
|
||||||
|
|
||||||
# recipes
|
# recipes
|
||||||
PlotRecipe,
|
PlotRecipe,
|
||||||
|
|||||||
@ -51,3 +51,36 @@ end
|
|||||||
function Base.writemime(io::IO, ::MIME"text/html", agif::AnimatedGif)
|
function Base.writemime(io::IO, ::MIME"text/html", agif::AnimatedGif)
|
||||||
write(io, "<img src=\"$(relpath(agif.filename))?$(rand())>\" />")
|
write(io, "<img src=\"$(relpath(agif.filename))?$(rand())>\" />")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------
|
||||||
|
|
||||||
|
"""
|
||||||
|
Collect one frame per for-block iteration and return an `Animation` object.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
p = plot(1)
|
||||||
|
anim = @animate for x=0:0.1:5
|
||||||
|
push!(p, 1, sin(x))
|
||||||
|
end
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
macro animate(forloop::Expr)
|
||||||
|
if forloop.head != :for
|
||||||
|
error("@animate macro expects a for-block. got: $(forloop.head)")
|
||||||
|
end
|
||||||
|
|
||||||
|
# add the call to frame to the end of each iteration
|
||||||
|
animsym = gensym("anim")
|
||||||
|
block = forloop.args[2]
|
||||||
|
push!(block.args, :(frame($animsym)))
|
||||||
|
|
||||||
|
# full expression:
|
||||||
|
esc(quote
|
||||||
|
$animsym = Animation() # init animation object
|
||||||
|
$forloop # for loop, saving a frame after each iteration
|
||||||
|
$animsym # return the animation object
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|||||||
@ -234,7 +234,7 @@ end
|
|||||||
function addToGadflyLegend(plt::Plot, d::Dict)
|
function addToGadflyLegend(plt::Plot, d::Dict)
|
||||||
|
|
||||||
# add the legend?
|
# add the legend?
|
||||||
if plt.plotargs[:legend] != :none
|
if plt.plotargs[:legend] != :none && d[:label] != ""
|
||||||
gplt = getGadflyContext(plt)
|
gplt = getGadflyContext(plt)
|
||||||
|
|
||||||
# add the legend if needed
|
# add the legend if needed
|
||||||
|
|||||||
@ -687,6 +687,7 @@ function addPyPlotLegend(plt::Plot, ax)
|
|||||||
if leg != :none
|
if leg != :none
|
||||||
# gotta do this to ensure both axes are included
|
# gotta do this to ensure both axes are included
|
||||||
args = filter(x -> !(x[:linetype] in (:hist,:density,:hexbin,:heatmap,:hline,:vline,:contour, :surface, :wireframe, :path3d, :scatter3d)), plt.seriesargs)
|
args = filter(x -> !(x[:linetype] in (:hist,:density,:hexbin,:heatmap,:hline,:vline,:contour, :surface, :wireframe, :path3d, :scatter3d)), plt.seriesargs)
|
||||||
|
args = filter(x -> x[:label] != "", args)
|
||||||
if length(args) > 0
|
if length(args) > 0
|
||||||
leg = ax[:legend]([d[:serieshandle] for d in args],
|
leg = ax[:legend]([d[:serieshandle] for d in args],
|
||||||
[d[:label] for d in args],
|
[d[:label] for d in args],
|
||||||
|
|||||||
19
src/plot.jl
19
src/plot.jl
@ -437,6 +437,25 @@ createKWargsList{T<:Real}(plt::PlottingObject, fx::FuncOrFuncs, fy::FuncOrFuncs,
|
|||||||
createKWargsList{T<:Real}(plt::PlottingObject, u::AVec{T}, fx::FuncOrFuncs, fy::FuncOrFuncs; kw...) = createKWargsList(plt, mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u); kw...)
|
createKWargsList{T<:Real}(plt::PlottingObject, u::AVec{T}, fx::FuncOrFuncs, fy::FuncOrFuncs; kw...) = createKWargsList(plt, mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u); kw...)
|
||||||
createKWargsList(plt::PlottingObject, fx::FuncOrFuncs, fy::FuncOrFuncs, umin::Real, umax::Real, numPoints::Int = 1000; kw...) = createKWargsList(plt, fx, fy, linspace(umin, umax, numPoints); kw...)
|
createKWargsList(plt::PlottingObject, fx::FuncOrFuncs, fy::FuncOrFuncs, umin::Real, umax::Real, numPoints::Int = 1000; kw...) = createKWargsList(plt, fx, fy, linspace(umin, umax, numPoints); kw...)
|
||||||
|
|
||||||
|
# (x,y) tuples
|
||||||
|
function createKWargsList{R1<:Real,R2<:Real}(plt::PlottingObject, xy::AVec{Tuple{R1,R2}}; kw...)
|
||||||
|
createKWargsList(plt, unzip(xy)...; kw...)
|
||||||
|
end
|
||||||
|
function createKWargsList{R1<:Real,R2<:Real}(plt::PlottingObject, xy::Tuple{R1,R2}; kw...)
|
||||||
|
createKWargsList(plt, [xy[1]], [xy[2]]; kw...)
|
||||||
|
end
|
||||||
|
|
||||||
|
@require FixedSizeArrays begin
|
||||||
|
unzip{T}(x::AVec{FixedSizeArrays.Vec{2,T}}) = T[xi[1] for xi in x], T[xi[2] for xi in x]
|
||||||
|
unzip{T}(x::FixedSizeArrays.Vec{2,T}) = T[x[1]], T[x[2]]
|
||||||
|
|
||||||
|
function createKWargsList{T<:Real}(plt::PlottingObject, xy::AVec{FixedSizeArrays.Vec{2,T}}; kw...)
|
||||||
|
createKWargsList(plt, unzip(xy)...; kw...)
|
||||||
|
end
|
||||||
|
function createKWargsList{T<:Real}(plt::PlottingObject, xy::FixedSizeArrays.Vec{2,T}; kw...)
|
||||||
|
createKWargsList(plt, [xy[1]], [xy[2]]; kw...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# special handling... no args... 1 series
|
# special handling... no args... 1 series
|
||||||
|
|||||||
@ -2,6 +2,7 @@ julia 0.4
|
|||||||
|
|
||||||
Colors
|
Colors
|
||||||
Reexport
|
Reexport
|
||||||
|
Requires
|
||||||
FactCheck
|
FactCheck
|
||||||
Gadfly
|
Gadfly
|
||||||
Images
|
Images
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user