Better time varying plotting
See original GitHub issueDescription
There are a few examples of plotting time-varying data using vtki:
These examples are all a bit convoluted and difficult for new users to experiment with. I propose a new feature in the plotting code that will handle all the background threading nuances so that new users (and power users like myself) do not have to make sure old threads are cleaned up and everything will simply work.
Proposal
Perhaps we could create a new function on the plotters called run_update_thread(func, **kwargs) that will take a user-defined function and it’s keyword arguments. Then vtki will handle setting up the background threads and managing them when they are no longer in use.
I’m thinking this is necessary because I have seen a few users try to use the background threads and then try to make a change and end up with numerous background threads that are still updating old plotters and eating up memory/resources (I also do this all the time and end up to restarting my kernel).
This type of feature would make sure any threads associated with a plotter are killed when the plotter is closed.
Psuedo-Code
Below is what I’m thinking this might look like. I’m also brainstorming ideas of how we could have a user define a loop statement and then tell vtki to run that loop making sure to use a defined time step between each iteration if desired.
import vtki
import numpy as np
x = np.arange(-10, 10, 0.25)
y = np.arange(-10, 10, 0.25)
x, y = np.meshgrid(x, y)
r = np.sqrt(x**2 + y**2)
z = np.sin(r)
# Create and structured surface
grid = vtki.StructuredGrid(x, y, z)
grid.point_array['foo'] = z.ravel()
# Creat a plotter object and set the scalars to the Z height
p = vtki.BackgroundPlotter()
p.add_mesh(grid)
def my_func():
"""My user defined function that will update the plotter"""
nframe = 25
for phase in np.linspace(0, 2*np.pi, nframe + 1)[:nframe]:
grid.points[:,-1] = np.sin(r + phase)
grid.point_array['foo'] = z.ravel()
return None
# Now repeatedly run that function!
p.run_update_thread(my_func, tstep=0.01)
Need feedback
I’m simply brainstorming what users might want/need and I’m hoping to solicit feedback. For those of you who I know are interested in time-varying visualizations, what would you like to see?: @tomtomatron and @sgkang
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)

Top Related StackOverflow Question
I like the simplification. I accidentally have extra threads running all the time too - and end up restarting the kernel. You may want to retain the ability to have specific threads updating based on specific functions though. Might be nice for plotting more complicated time-varying data.
Closing this to defer to #412