id,node_id,number,title,user,state,locked,assignee,milestone,comments,created_at,updated_at,closed_at,author_association,active_lock_reason,draft,pull_request,body,reactions,performed_via_github_app,state_reason,repo,type 349026158,MDU6SXNzdWUzNDkwMjYxNTg=,2355,Animated plots - a suggestion for implementation,35968931,closed,0,,,9,2018-08-09T08:23:17Z,2020-08-16T08:07:12Z,2020-08-16T08:07:12Z,MEMBER,,,,"**It'd be awesome if one could animate the plots xarray creates using matplotlib just by specifying the dimension over which to animate the plot.** This would allow for rapid visualisation of time-evolving data and could potentially be very powerful (imagine a grid of faceted 2d plots, all evolving together over time). I know that there are already some libraries which can create animated plots of xarray data (e.g. Holoviews), but I think that it's within xarray's scope (#2030) to add another dimension to its default matplotlib-style plotting capabilities. **How?** I saw this new package for making it easier to animate matplotlib plots using the funcanimation module: [animatplot](https://github.com/t-makaro/animatplot). It essentially works by wrapping matplotlib commands like `plt.imshow()` to instead return ""blocks"". These blocks can then be animated by feeding them into an `animation` class. An introductory script to plot line data can be found [here](https://animatplot.readthedocs.io/en/latest/tutorial/getting_started..html), but basically has the form ```python import animatplot as amp import matplotlib.pyplot as plt X, Y = load_data_somehow block = amp.blocks.Line(X, Y) anim = amp.Animation([block]) anim.save_gif(""animated_line"") plt.show() ``` which creates a basic gif like this: ![animated line gif](https://user-images.githubusercontent.com/35968931/43885402-a3373002-9b6d-11e8-9b3d-f4e588a71a22.gif) I think that it might be possible to integrate this kind of animation-plotting tool by adding an optional dimension argument to xarray's plotting methods, which if given causes the function to call the wrapped animatplot plotting command instead of the bare matplotlib one. It would then return the corresponding ""block"" ready to be animated. Using the resulting code might only require a few lines to create an impressive visualisation: ```python turb2d = xr.load_dataset(""turbulent_fluid_data.nc"") block = turb2d[""density""].plot.imshow(animate_over='time') anim = Animation([block]) anim.save_gif(""fluid_density.gif"") plt.show() ``` ![n_over_time](https://user-images.githubusercontent.com/35968931/43887058-83d4161c-9b72-11e8-978d-fcb8e071a37a.gif) **What would need changing?** If we take the `da.plot.imshow()` example, then the way I'm imagining this would be done is to add the optional argument `animate_over` to the `plot_2d` decorator, and use it to choose between returning the matplotlib artist (as it does currently) or the ""block"". It would also mean altering the logic inside `plot_2d` and `imshow` to account for the fact you would be calling this on a 3D dataarray instead of a 2D one. I wanted to ask about this before delving into the code too much or submitting a pull request, in case there is some problem with the idea. What do you think?","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/2355/reactions"", ""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue