Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A quicky script to make a vincent stacked area plot with the results of the threes simulation [this blog post](
# standard library
import sys
import random
# 3rd party
import numpy as np
import vincent
N_SAMPLES = 10000
# read from stdin
score_distribution = [int(line) for line in sys.stdin]
# what is the expected random-swiper high score, given the number of
# games played?
vincent_data = {
'index': [],
'y1': [],
'y2': [],
'y3': [],
for n_games_played in range(1, 21):
high_score_distribution = []
for i in range(N_SAMPLES):
high_score = max(random.choice(score_distribution)
for j in xrange(n_games_played))
# calculate sizes needed for stacked area
lower = np.percentile(high_score_distribution, 5)
size = np.percentile(high_score_distribution, 95) - lower
top = 1400 - (lower + size)
# do this to get in correct vincent format
# make the chart
stacked = vincent.StackedArea(vincent_data, iter_idx='index')
stacked.axis_titles(x='games played', y='high score')
stacked.to_json('stacked.json', html_out=True, html_path='index.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment