Interactive pcolor in python

566 views Asked by At

I have two numpy arrays of sizes (Number_of_time_steps, N1, N2). Each one represents velocities in a plane of size N1xN2 for Number_of_time_steps which is 12,000 in my case. These two arrays come from two fluid dynamics simulations in which a point is slightly perturbed at time 0 and I want to study the discrepancies caused by the perturbation in the velocity of each point in the grid. To do so, for each time step, I make a plot with 4 subplots: pcolor map of plane 1, pcolor map of plane 2, difference between the planes, and difference between the planes in log scale. I use matplotlib.pyplot.pcolor to create each subplot.

This is something that can be easily done, but the problem is that I will end up with 12,000 of such plots (saved as .png files on the disk). Instead, I want a kind of interactive plot in which I can enter the time step, and it will update the 4 subplots to the corresponding time step from the values in the two existing arrays.

If somebody has any idea on how to solve this problem, be happy to hear about it.

2

There are 2 answers

1
James On BEST ANSWER

For interactive graphics, you should look into Bokeh:

http://docs.bokeh.org/en/latest/docs/quickstart.html

You can create a slider that will bring up the time slices you want to see.

0
tmdavison On

If you can run from within ipython, you could just make a function to plot your given timestep

%matplotlib # set the backend
import matplotlib.pyplot as plt

fig,((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row')

def make_plots(timestep):
    # Clear the subplots
    [ax.cla() for ax in [ax1,ax2,ax3,ax4]]

    # Make your plots. Add whatever options you need
    ax1.pcolor(array1[timestep])
    ax2.pcolor(array2[timestep])
    ax3.pcolor(array1[timestep]-array2[timestep])
    ax4.pcolor(array1[timestep]-array2[timestep])

    # Make axis labels, etc.
    ax1.set_xlabel(...) # etc.

    # Update the figure
    fig.show()

# Plot some timesteps like this
make_plots(0)     # time 0
# wait some time, then plot another
make_plots(100)   # time 100
make_plots(12000) # time 12000