started real time updates; fixes #29 (pyplot ijulia display)
This commit is contained in:
parent
2fe21b8547
commit
d781c437de
@ -123,7 +123,7 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Julia 0.4.0-rc2",
|
||||
"display_name": "Julia 0.4.0-rc1",
|
||||
"language": "julia",
|
||||
"name": "julia-0.4"
|
||||
},
|
||||
|
||||
136
examples/playground.ipynb
Normal file
136
examples/playground.ipynb
Normal file
File diff suppressed because one or more lines are too long
@ -49,6 +49,28 @@ function updatePlotItems(plt::Plot{ImmersePackage}, d::Dict)
|
||||
end
|
||||
|
||||
|
||||
# add a new x/y data point to series i
|
||||
function Base.push!(plt::Plot{ImmersePackage}, i::Int, x::Real, y::Real)
|
||||
gplt = plt.o[2]
|
||||
data = gplt.layers[end-i+1].mapping
|
||||
data[:x] = extendSeriesData(data[:x], x)
|
||||
data[:y] = extendSeriesData(data[:y], y)
|
||||
plt
|
||||
end
|
||||
|
||||
# add a new y, and extend x "naturally"
|
||||
function Base.push!(plt::Plot{ImmersePackage}, i::Int, y::Real)
|
||||
gplt = plt.o[2]
|
||||
data = gplt.layers[end-i+1].mapping
|
||||
data[:x] = extendSeriesData(data[:x]) # this will only work with a UnitRange{Int}!!!
|
||||
data[:y] = extendSeriesData(data[:y], y)
|
||||
plt
|
||||
end
|
||||
|
||||
extendSeriesData(v::UnitRange{Int}) = minimum(v):maximum(v)+1
|
||||
extendSeriesData{T<:Real}(v::AVec{T}, z::Real) = (push!(v, convert(T, z)); v)
|
||||
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
@ -173,10 +173,13 @@ convertToAnyVector(v::AVec; kw...) = Any[vi for vi in v], nothing
|
||||
# in computeXandY, we take in any of the possible items, convert into proper x/y vectors, then return.
|
||||
# this is also where all the "set x to 1:length(y)" happens, and also where we assert on lengths.
|
||||
computeX(x::Void, y) = 1:length(y)
|
||||
computeX(x, y) = x
|
||||
computeX(x, y) = copy(x)
|
||||
computeY(x, y::Function) = map(y, x)
|
||||
computeY(x, y) = y
|
||||
computeY(x, y) = copy(y)
|
||||
function computeXandY(x, y)
|
||||
if x == nothing && isa(y, Function)
|
||||
error("If you want to plot the function `$y`, you need to define the x values somehow!")
|
||||
end
|
||||
x, y = computeX(x,y), computeY(x,y)
|
||||
@assert length(x) == length(y)
|
||||
x, y
|
||||
|
||||
@ -125,6 +125,7 @@ function plotter()
|
||||
try
|
||||
@eval import PyPlot
|
||||
@eval export PyPlot
|
||||
PyPlot.ioff()
|
||||
catch
|
||||
error("Couldn't import PyPlot. Install it with: Pkg.add(\"PyPlot\")")
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user