Last active
February 26, 2020 08:19
-
-
Save bixel/56464ebab28e6e97c8a4dbea0d29d999 to your computer and use it in GitHub Desktop.
Create animated normal distribution histogram as an emoji
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
#! /usr/bin/env python3 | |
import matplotlib.pyplot as plt | |
from matplotlib.animation import FuncAnimation | |
import numpy as np | |
content, bins = np.histogram(np.random.normal(size=10), bins=12, range=(-5, 5)) | |
fig = plt.figure(figsize=(1, 1)) | |
container = plt.bar(bins[:-1], content, width=bins[1] - bins[0], align='edge') | |
ax = plt.gca() | |
ax.tick_params(axis='y', direction='in') | |
ax.get_yaxis().set_ticklabels([]) | |
plt.xticks(ticks=[]) | |
plt.tight_layout(pad=0) | |
def update(i): | |
print(i) | |
size = 200 / (201 - i) | |
content = np.histogram(np.random.normal(size=int(size)), bins=bins)[0] | |
for patch, count in zip(container.patches, content): | |
patch.set_height(patch.get_height() + count) | |
ax.relim() | |
ax.autoscale_view() | |
return container, ax | |
if __name__ == '__main__': | |
anim = FuncAnimation(fig, update, frames=range(200), interval=10) | |
anim.save('animation.gif', dpi=80, writer='imagemagick') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will look somewhat like