Skip to content

Instantly share code, notes, and snippets.

@bixel
Last active February 26, 2020 08:19
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 bixel/56464ebab28e6e97c8a4dbea0d29d999 to your computer and use it in GitHub Desktop.
Save bixel/56464ebab28e6e97c8a4dbea0d29d999 to your computer and use it in GitHub Desktop.
Create animated normal distribution histogram as an emoji
#! /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')
@bixel
Copy link
Author

bixel commented Feb 26, 2020

This will look somewhat like
animation

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