Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation interface #111

Closed
gdkrmr opened this issue Jan 11, 2016 · 17 comments
Closed

Animation interface #111

gdkrmr opened this issue Jan 11, 2016 · 17 comments

Comments

@gdkrmr
Copy link

gdkrmr commented Jan 11, 2016

There is an issue with the current animation interface:

  1. using Plots; anim = Animation() gives an error, shouldn't this initialize an empty animation object?
  2. Something like this does not work:
plot()
anim = Animation()
for i in 1:0.1:π
    plot([sin,cos], 0, π)
    scatter!([i,i],[sin])
    frame(anim)
end
gif(anim)

An ugly workaround would be this:

plot()
anim = Animation()
for i in 0:0.1:π
    plot([sin,cos], 0, π)
    scatter!([i],[sin])
    scatter!([i],[cos])
    anim = Animation(current(),anim.dir,anim.frames)
    frame(anim)
end
gif(anim)

Here is what my intuition would expect: Animation should be mutable, so that anim.plt can be changed and frame() should always set anim.plt to current().

@tbreloff
Copy link
Member

Your second example won't work. You're creating a new animation in each iteration. The first example should work fine. Are you on master? If not, I recommend a Pkg.checkout("Plots"). If it still doesn't work after a checkout let me know.

On Jan 11, 2016, at 3:42 AM, gdkrmr notifications@github.com wrote:

There is an issue with the current animation interface:
1 using Plots; anim = Animation() gives an error, shouldn't this initialize an empty animation object?
2 Something like this does not work:

plot()
anim = Animation()
for i in 1:01:π
plot([sin,cos], 0, π)
scatter!([i,i],[sin])
frame(anim)
end
gif(anim)
An ugly workaround would be this:

plot()
anim = Animation()
for i in 0:01:π
plot([sin,cos], 0, π)
scatter!([i],[sin])
scatter!([i],[cos])
anim = Animation(current(),animdir,animframes)
frame(anim)
end
gif(anim)
Here is what my intuition would expect: Animation should be mutable, so that animplt can be changed and frame() should always set animplt to current()


Reply to this email directly or view it on GitHub.

@gdkrmr
Copy link
Author

gdkrmr commented Jan 11, 2016

the second example is what actually works for me :-)
I have version 0.5.1

@tbreloff
Copy link
Member

Ok I understand now why the second version works now, but both examples are very inefficient. Here's some pointers:

  • plot or subplot will open up a brand new window/figure. This is not what you want... you really just want to update the data for one of the series
  • Animation() should work fine if you checkout... there was a recent PR adding an empty constructor
  • You can update just the underlying series data by indexing on the Plot object (i.e. getindex and setindex! are defined for the Plot)

So with those notes in mind, a better way to do what you're trying to do is this (which works for me):

using Plots
anim = Animation()
p = plot([sin,cos], 0, π, size=(300,300))
scatter!([0], [sin,cos])
for i in 0:0.1:π
    p[3] = [i], [sin(i)]
    p[4] = [i], [cos(i)]
    frame(anim)
end
gif(anim)

tmp

@gdkrmr
Copy link
Author

gdkrmr commented Jan 11, 2016

ok, thanks, it works.
How would I reassign coordinates in scatter3d?

@tbreloff
Copy link
Member

Sadly that's not implemented yet... an example placeholder is here: https://github.com/tbreloff/Plots.jl/blob/master/src/backends/pyplot.jl#L441-L444

@gdkrmr
Copy link
Author

gdkrmr commented Jan 11, 2016

ok, thanks for the help.

@tbreloff
Copy link
Member

tbreloff commented Feb 8, 2016

I added a new macro: @animate (on dev branch). This allows for some boilerplate reduction. Here's a modification of the example above:

using Plots
pyplot(size=(300,200))
p = plot([sin,cos], 0, π, lab=[:sin :cos])
scatter!(1, lab="")
anim = @animate for x in 0:0.1:π
    p[3] = [x,x], [sin(x),cos(x)]
end
gif(anim)

tmp

@pkofod
Copy link
Contributor

pkofod commented Feb 8, 2016

Can't get any easier than that!

@Evizero
Copy link
Member

Evizero commented Feb 8, 2016

nice. I will try this soon

@pkofod
Copy link
Contributor

pkofod commented Feb 9, 2016

It's nice that you can still frame(anim) if fps=1 is too fast.
tmp

@tbreloff
Copy link
Member

tbreloff commented Feb 9, 2016

@pkofod based on your wording, it seems like you might be confused on fps. It's frames per second, which is just how many of the calls to frame(anim) to fit into 1 second of real time (after the frames have been generated already).

However, if you really meant "I don't want to save a frame on each loop iteration"... I was thinking about adding some syntax to the macro, maybe like:

p = plot(1)
anim = @animate when(mod1(i, 3) == 1) for i=1:100
    push!(p, 1, rand())
end

and maybe the shorthand:

p = plot(1)
anim = @animate every(3) for i=1:100
    push!(p, 1, rand())
end

which would save a frame on every 3rd point added. It would expand to:

p = plot(1)
anim = begin
    anim = Animation()
    for i=1:100
        push!(p, 1, rand())
        if mod1(i, 3) == 1
            frame(anim)
        end
    end
    anim
end

Thoughts? Ideas for alternative syntax?

@pkofod
Copy link
Contributor

pkofod commented Feb 9, 2016

@tbreloff , I was actually wrong and thought I was able to create two frames in a row, such that it would show two identical frames in a row (every frame is there twice, so with fps = 1 it would appear to have fps = 0.5 which is not possible as per your explanation), actually I was just able to write frame(anim) because anim was previously defined, but it did nothing (of course).

begin EDIT
So what I was looking for was a sort of repeat frame n times keyword, but apparently I was actually satisfied with fps=1, so...
end EDIT

I like both when for that general use and every for the case most would probably need.

@Evizero
Copy link
Member

Evizero commented Feb 9, 2016

+1 for the macro suggestions

@tbreloff
Copy link
Member

This is mostly done. I invite you to try it out on the dev branch. Here's the highlights:

A new macro @gif simplifies things more... choose from:

anim = @animate for i=1:10
  plot(rand(i))
end
gif(anim)

or

@gif for i=1:10
  plot(rand(i))
end

Keyword every followed by a positive integer after the for loop will only save only those frames. So "every 5" will save frames for loop iterations [1,6,11,...]:

@gif for i=1:10
  plot(rand(i))
end every 5

Keyword when followed by any valid boolean expression will only save a frame when the expression evaluates to true. A full example:

using Plots; pyplot(size=(300,200))
x = 0:0.1:2π
p = scatter(1, xlim=extrema(x), ylim=(-1,1))

@gif for xi in x
    push!(p, 1, xi, sin(xi))
end when abs(sin(xi))>0.2

Let me know what you think! (and if there are bugs, of course)

@Evizero
Copy link
Member

Evizero commented Feb 17, 2016

Looks awesome. I will play with this

@pkofod
Copy link
Contributor

pkofod commented Feb 17, 2016

👍 from here as well, I will play around with it some time next week.

@tbreloff
Copy link
Member

tbreloff commented Mar 8, 2016

I'm not sure why this is still open... I think the functionality is finished?

@tbreloff tbreloff closed this as completed Mar 8, 2016
t-bltg added a commit that referenced this issue Oct 6, 2022
t-bltg added a commit that referenced this issue Oct 6, 2022
* use Dates

* Add compat for RecipesBase

* Fix badges

* Plots test

* Fix travis

* Forgot using

* Update .travis.yml

Co-Authored-By: Anshul Singhvi <asinghvi17@simons-rock.edu>

* Use ds/rewrite

* Try with --project


Credit: Fredrik Ekre

* Use latest stable julia version

* Allow failures on MacOS

* Docs deployment

* Literate + enable deploy

* Update Project.toml

* fix missing comma

* Fix error

* try fixing repo name

* small change to trigger CI

* play better with Literate

* allow type recipes for `Number`s in arrays and surfaces

* small fixes

* skip maybestrings

* fix ambiguity

* Add badge

* Fix build badge link

* Show status only for master branch

* Fix README docs link

* remove subdomain

* Create TagBot.yml

* fix surface type recipe

* bump version

* fix error for grouping

* bump version

* further grouping fixes

* bump version

* fix plotting functions

* bump version

* downgrade version

* fix plotting rowvector of functions

* bump version

* support parametric type in `@userplot`

* add docs for parametric type in `@userplot`

* bump version

* fix grouping

* bump version

* bump PlotUtils compat

* bump version

* add zulip chat link to readme [skip ci]

* add zulip link [skip ci]

* Fix typo in docs

`AbstractArry` -> `AbstractArray`

* add hook after series decomposition (#52)

* add process_sliced_series_attributes!

* export process_slice_series_attrributes!

* remove `kw`

* Update Project.toml

[skip ci]

* Initial pass at CI

* Add script from Plots

* Update to MakieRecipes

* comment out artifact uploads

* Plots test

* CairoMakie tests

* Forgot using

* Update .travis.yml

Co-Authored-By: Anshul Singhvi <asinghvi17@simons-rock.edu>

* Use ds/rewrite

* Try with --project

* Another try

Credit: Fredrik Ekre

* Import examples from MakieRecipes

* add separately

* dev

* $(mktemp -d)

* Update .github/workflows/CI.yml

Co-Authored-By: Anshul Singhvi <asinghvi17@simons-rock.edu>

* use temp_for_test

* fix typo

* Update .github/workflows/CI.yml

* ensure that images are uploaded

* Pass a begin block to testset

* fix the macro

* seriously, I forgot .png?

* Update .travis.yml

* Fix split_attribute (#53)

* Fix a typo in the `recipe_pipeline!` constructor (#54)

* bump version

* fix time and period recipes

* bump version

* Fix typo (#56)

* implement `Base.axes` for `Volume`

* bump version

* Update group.jl

* implement iterate for Surface and Volume

* bump version

* use NaNMath log functions

* Add one_arg_shorthands macro (#73)

* Add one_arg_shorthands macro

* export one_arg_shorthands

* patch version [skip ci]

* Add :mesh3d as 3d series type (#62)

* 0.1.12 [skip ci]

* add compat for NaNMath

* dispatch processing of axis args on the plot object (#63)

* dispatch processing of axis args on the plot object

* Update type_recipe.jl

* Update type_recipe.jl

* Update type_recipe.jl

* add to API

* Update api.jl

* 0.1.13

* remove one_arg_shorthands macro (#74)

It didn't work out as intended

* 1.1.0

* more friendly error when x,y shape mis-match

* AbstractDict plot sorted

* more friendly error when x,y shape mis-match (#65)

* more friendly error when x,y shape mis-match

* don't touch z

* Update src/user_recipe.jl

Co-authored-by: Daniel Schwabeneder <daschw@disroot.org>

* switch to github-actions and update runtests.jl to run Plots test images

* update CI.yml

* keep makie tests

* move `signature_string` to RecipesPipeline

* minor version bump

* Revert "minor version bump"

This reverts commit 63c713b7808adf305484a9724cef9eabae2a0702.

* move `warn_on_recipe_aliases!` from Plots and add some `@nospecialize`

* add CompileBot

* minor version bump

* add precompile statements

* bump version

* add new line at end of file

* add recipe for list of NamedTuples

* add newline

* update tagbot action

* add recipe for list of NamedTuples

* move `warn_on_recipe_aliases!` from Plots and add some `@nospecialize`

* update tagbot action

* Fix broken histogram and stepbins plotting

* Increase package version to v0.2.1

* Update precompile_*.jl file

* add TestImages test dependency

* refine friendly error (#75)

* Update precompile_*.jl file

* don't stringify argument to `warn_on_recipe_aliases!` early
needs matching Plots changes

* minor release

* add `@nospecialize` annotations

* release

* update CompileBot

* update TESTCMD in CI

* fix TESTCMD in compilebot action

* Update precompile_*.jl file

* release

* Update README.md

[skip ci]

* don't catch all the MethodErrors (#87)

* don't catch all the MethodErrors

* remove `@show`

* 0.3.3 [skip ci]

* add mesh3d for GR

* v0.3.4

* Small improvement in inferrability (#82)

* 1.1.2 [skip ci]

* CI: tentative fix

* CI: add LinearAlgebra (#96)

Co-authored-by: t-bltg <t-bltg@users.noreply.github.com>

* Test for error value from `apply_recipe` fallback. (#95)

* v0.3.5 [skip ci]

* Add `Downloads` test dependency

Complement #3766

* Remove try/catch needed for compatibility with Plots.jl v1.21.0 and earlier (#97)

* Improve groups perf from O(MxN) to O(M) (#98)

* Update MakieRecipes URL

* Update precompile_*.jl file (#91)

* v0.3.6 [skip ci]

* Revert try/catch for patch version

* v0.3.7 (#101) [skip ci]

* v0.4.0 (#102) [skip ci]

* Avoid Vararg UnionAll dispatch (#104)

* Avoid Vararg UnionAll dispatch

Fixes JuliaPlots/RecipesPipeline.jl#103

* fix fix

Co-authored-by: Simon Christ <SimonChrist@gmx.de>

* 0.4.1 [skip ci]

* move layout macro from plots (#85)

* 1.2.0 [skip ci]

* remove pct

* 1.2.1 [skip ci]

* Update Project.toml

* respect defaults for fillrange and ribbon (#106)

* respect defaults for fillrange and ribbon

* remove fillrange and ribbon handling from RecipesPipeline

* update ci

* set version

* Update CI.yml

* move documentation to gh-actions

* update run commands

* Update Documentation.yml

* Allow `NanMath` 1.0 - bump version (#108)

Co-authored-by: t-bltg <tf.bltg@gmail.com>

* Fix `unzip` for empty vectors (#110)

* 0.5.2 [skip ci]

* update url with https://docs.juliaplots.org/stable/generated/supported/#Keyword-Arguments (#89)

* Update precompile_*.jl file (#109)

Co-authored-by: t-bltg <t-bltg@users.noreply.github.com>

* run  snoopcompile on pust to master only

* update compat bounds (#111)

* 0.6.0 [skip ci]

* Update precompile_*.jl file (#112)

Co-authored-by: t-bltg <t-bltg@users.noreply.github.com>

* `SnoopCompile` labels

* use ssh key for `TagBot` (#91)

* fix julia scripts in markdown (#90)

* add missing language specification in md

* replace type with struct

* fix `SnoopCompile` (#113)

* update compat bounds

* run snoop on master only

* update precompile

* Update precompile_*.jl file (#114)

Co-authored-by: t-bltg <t-bltg@users.noreply.github.com>

* 0.6.1 [skip ci]

* fix plotting `Union{Missing,Real}` arrays (#116)

* Update precompile_*.jl file (#115)

Co-authored-by: t-bltg <t-bltg@users.noreply.github.com>

* 0.6.2 [skip ci]

* fix formatters (#118)

* 0.6.3 [skip ci]

* Update precompile_*.jl file (#117)

Co-authored-by: BeastyBlacksmith <BeastyBlacksmith@users.noreply.github.com>

* Create invalidations.yml (#93)

This is based on https://github.com/julia-actions/julia-invalidations. Adding such checks came up in https://discourse.julialang.org/t/potential-performance-regressions-in-julia-1-8-for-special-un-precompiled-type-dispatches-and-how-to-fix-them/86359. I suggest to add this check here since this package is widely used as a dependency.

* rework precompilation using `SnoopPrecompile` - document `@layout` (#94)

* document `@layout`

* rewok precompile statements using `SnoopPrecompile`

* add ci

* bump julia to `1.6` for failing CI

* 1.3.0

* more efficient `DefaultsDict` iteration (#121)

* bump julia version in `ci` (#122)

* 0.6.4

* Add methods to access separate keysets of the DefaultsDict (#124)

* bump version [skip ci]

* DefaultsDict - correctness and performance tweaks for large numbers of series (#126)

* 0.6.6 [skip ci]

* Fix a deprecated syntax in docs of macro `@recipe` (#95)

* fix broken docs

* remove

* remove un-needed files

* RP tests

Co-authored-by: Daniel Schwabeneder <daschw@disroot.org>
Co-authored-by: Sebastian Micluța-Câmpeanu <m.c.sebastian95@gmail.com>
Co-authored-by: Sebastian Micluța-Câmpeanu <31181429+SebastianM-C@users.noreply.github.com>
Co-authored-by: Anshul Singhvi <asinghvi17@simons-rock.edu>
Co-authored-by: Lirimy <31124605+Lirimy@users.noreply.github.com>
Co-authored-by: mtsch <matijacufar@gmail.com>
Co-authored-by: Simon Christ <SimonChrist@gmx.de>
Co-authored-by: JonasIsensee <jonas.isensee@web.de>
Co-authored-by: Michael Abbott <me@pseudomac>
Co-authored-by: Benoit Pasquier <4486578+briochemc@users.noreply.github.com>
Co-authored-by: Michael Krabbe Borregaard <mkborregaard@snm.ku.dk>
Co-authored-by: Adrian Dawid <dwd31415@users.noreply.github.com>
Co-authored-by: Moelf <proton@jling.dev>
Co-authored-by: Oliver Schulz <oschulz@mpp.mpg.de>
Co-authored-by: daschw <daschw@users.noreply.github.com>
Co-authored-by: Moelf <Moelf@users.noreply.github.com>
Co-authored-by: Jeremy Bejanin <jeremy.bejanin@gmail.com>
Co-authored-by: t-bltg <t-bltg@users.noreply.github.com>
Co-authored-by: Tim Holy <tim.holy@gmail.com>
Co-authored-by: Nicholas Bauer <nicholasbauer@outlook.com>
Co-authored-by: Mike Keehan <21029749+mdkeehan@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Christopher Rackauckas <chrisrackauckas@gmail.com>
Co-authored-by: Kristoffer Carlsson <kcarlsson89@gmail.com>
Co-authored-by: Yuto Horikawa <hyrodium@gmail.com>
Co-authored-by: Rafael Schouten <rafaelschouten@gmail.com>
Co-authored-by: MrHenning <5331081+MrHenning@users.noreply.github.com>
Co-authored-by: BeastyBlacksmith <BeastyBlacksmith@users.noreply.github.com>
Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com>
Co-authored-by: Ryan <25192197+singularitti@users.noreply.github.com>
Jonas-a-Zimmermann pushed a commit to Jonas-a-Zimmermann/Plots.jl that referenced this issue Oct 29, 2024
…aFrame_syntax

Deprecate old DataFrames syntax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants