Last active
December 22, 2015 05:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Thanks! The code has been changed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
note:
x_min = np.nanmax(x)
x_max = np.nanmin(x)