Created
December 28, 2020 12:23
-
-
Save ShuaiGuo16/ae51b17f98cc0aa6cc8e4ed4fc72dfa2 to your computer and use it in GitHub Desktop.
Animate histogram
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
# Set up the histogram axis | |
ax_hist = ax.twinx() # Make an identical copy | |
ax_hist.set_ylim(0, 10.2) | |
ax_hist.set_yticks(list(range(0,10,2))) | |
ax_hist.set_ylabel('Count', fontsize=15) | |
# Initiate camera | |
camera = Camera(fig) | |
# A list of range values | |
R = [] | |
# Create individual frames | |
for i in range(traj_num): | |
for j in range(1,traj_X.shape[1]+1): | |
# Projectile's trajectory | |
x, y = traj_X[i][0:j], traj_Y[i][0:j] | |
# Show Projectile's location | |
ax.plot(x[-1], y[-1], marker='o', markersize=12, markeredgecolor='r', markerfacecolor='r') | |
# Show Projectile's trajectory | |
ax.plot(x, y, color='b', lw=2, linestyle='--') | |
# Show histogram | |
if j==traj_X.shape[1]: | |
R.append(Range[i]) | |
ax_hist.hist(R, bins=bins, edgecolor=(1.0, 0.5, 0.25), fc=(1.0, 0.5, 0.25, 0.5)) | |
# Capture frame | |
camera.snap() | |
anim = camera.animate(interval = 40, repeat = True, repeat_delay = 500) | |
HTML(anim.to_html5_video()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment