Skip to content

Instantly share code, notes, and snippets.

@JimHokanson
Last active December 22, 2015 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimHokanson/6425605 to your computer and use it in GitHub Desktop.
Save JimHokanson/6425605 to your computer and use it in GitHub Desktop.
Simple script to plot worm movement. A move to using an animation module would probably be more appropriate.
import matplotlib.pyplot as plt
import h5py
import numpy as np
#SPEED_UP = 4
#DT = 0.05
file_path = u'F:/worm_data/segworm_data/features/798 JU258 on food R_2010_11_25__16_34_17___1___9_features.mat'
h = h5py.File(file_path, 'r')
x = h["worm"]["posture"]["skeleton"]["x"].value
y = h["worm"]["posture"]["skeleton"]["y"].value
h.close()
#NOTE: Dropped frames show up as NaN
x_min = np.nanmin(x) #Why is this not a method of the object?
x_max = np.nanmax(x)
y_min = np.nanmin(y)
y_max = np.nanmax(y)
n_frames = x.shape[0]
fig, ax = plt.subplots()
points, = ax.plot(x[0,:], y[0,:]) #marker='o', linestyle='None'
ax.set_xlim(x_min, x_max)
ax.set_ylim(y_min, y_max)
for iFrame in range(n_frames):
points.set_data(x[iFrame,:], y[iFrame,:])
#I just wanted it to plot fast, not sure if 0 would be better
plt.pause(0.001)
@kneuron
Copy link

kneuron commented Sep 13, 2013

note:
x_min = np.nanmax(x)
x_max = np.nanmin(x)

@JimHokanson
Copy link
Author

Thanks! The code has been changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment