Created
August 19, 2020 13:59
-
-
Save AgeOfMarcus/673de39bbfd96ec070c0d9342f16b198 to your computer and use it in GitHub Desktop.
dice-roll-plot.ipynb
This file contains hidden or 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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "dice-roll-plot.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"authorship_tag": "ABX9TyN6xiVh0+bPFI9VKqA6RLb3", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/AgeOfMarcus/673de39bbfd96ec070c0d9342f16b198/dice-roll-plot.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "AKw_zs6MogjW", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"# Dice roll plotter\n", | |
"\n", | |
"This program will roll a number of dice `x` amount of times and plot the results, as well as displaying other information." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "1i7ElRc0q_h8", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"## Installation" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "2NL6zdZIrBHT", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 1000 | |
}, | |
"outputId": "946bd696-ded5-4b98-ca4e-526d6eeef86b" | |
}, | |
"source": [ | |
"!pip install nbinteract" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Collecting nbinteract\n", | |
" Downloading https://files.pythonhosted.org/packages/92/92/0047f909ccae3ca35c45007b4015d89ed17b226bb1a0ef38d5c5f0aee9bf/nbinteract-0.2.5-py3-none-any.whl\n", | |
"Collecting IPython<8,>=6\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/23/6a/210816c943c9aeeb29e4e18a298f14bf0e118fe222a23e13bfcc2d41b0a4/ipython-7.16.1-py3-none-any.whl (785kB)\n", | |
"\u001b[K |████████████████████████████████| 788kB 9.9MB/s \n", | |
"\u001b[?25hCollecting nbformat<5,>=4.4.0\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/da/27/9a654d2b6cc1eaa517d1c5a4405166c7f6d72f04f6e7eea41855fe808a46/nbformat-4.4.0-py2.py3-none-any.whl (155kB)\n", | |
"\u001b[K |████████████████████████████████| 163kB 39.7MB/s \n", | |
"\u001b[?25hRequirement already satisfied: toolz<1,>=0.8 in /usr/local/lib/python3.6/dist-packages (from nbinteract) (0.10.0)\n", | |
"Requirement already satisfied: ipywidgets<8,>=7.5.0 in /usr/local/lib/python3.6/dist-packages (from nbinteract) (7.5.1)\n", | |
"Requirement already satisfied: numpy<2,>=1 in /usr/local/lib/python3.6/dist-packages (from nbinteract) (1.18.5)\n", | |
"Requirement already satisfied: docopt<1,>=0.6.2 in /usr/local/lib/python3.6/dist-packages (from nbinteract) (0.6.2)\n", | |
"Requirement already satisfied: nbconvert<6,>=5.3 in /usr/local/lib/python3.6/dist-packages (from nbinteract) (5.6.1)\n", | |
"Collecting bqplot==0.11.0\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/ba/bd/d897493e196f14e2939b132c1d2adf966a327df2ae6716a1b665075f338b/bqplot-0.11.0-py2.py3-none-any.whl (1.5MB)\n", | |
"\u001b[K |████████████████████████████████| 1.5MB 35.2MB/s \n", | |
"\u001b[?25hRequirement already satisfied: Jinja2<3,>=2.10 in /usr/local/lib/python3.6/dist-packages (from nbinteract) (2.11.2)\n", | |
"Requirement already satisfied: traitlets<5,>=4.3 in /usr/local/lib/python3.6/dist-packages (from nbinteract) (4.3.3)\n", | |
"Requirement already satisfied: pickleshare in /usr/local/lib/python3.6/dist-packages (from IPython<8,>=6->nbinteract) (0.7.5)\n", | |
"Requirement already satisfied: decorator in /usr/local/lib/python3.6/dist-packages (from IPython<8,>=6->nbinteract) (4.4.2)\n", | |
"Requirement already satisfied: pexpect; sys_platform != \"win32\" in /usr/local/lib/python3.6/dist-packages (from IPython<8,>=6->nbinteract) (4.8.0)\n", | |
"Collecting prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/72/65/a3ef98b56d57a6d0a04cea5810ecbf3700a225d296ca298b3442dddebb42/prompt_toolkit-3.0.6-py3-none-any.whl (354kB)\n", | |
"\u001b[K |████████████████████████████████| 358kB 43.8MB/s \n", | |
"\u001b[?25hRequirement already satisfied: pygments in /usr/local/lib/python3.6/dist-packages (from IPython<8,>=6->nbinteract) (2.1.3)\n", | |
"Requirement already satisfied: jedi>=0.10 in /usr/local/lib/python3.6/dist-packages (from IPython<8,>=6->nbinteract) (0.17.2)\n", | |
"Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python3.6/dist-packages (from IPython<8,>=6->nbinteract) (49.2.0)\n", | |
"Requirement already satisfied: backcall in /usr/local/lib/python3.6/dist-packages (from IPython<8,>=6->nbinteract) (0.2.0)\n", | |
"Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /usr/local/lib/python3.6/dist-packages (from nbformat<5,>=4.4.0->nbinteract) (2.6.0)\n", | |
"Requirement already satisfied: ipython-genutils in /usr/local/lib/python3.6/dist-packages (from nbformat<5,>=4.4.0->nbinteract) (0.2.0)\n", | |
"Requirement already satisfied: jupyter-core in /usr/local/lib/python3.6/dist-packages (from nbformat<5,>=4.4.0->nbinteract) (4.6.3)\n", | |
"Requirement already satisfied: ipykernel>=4.5.1 in /usr/local/lib/python3.6/dist-packages (from ipywidgets<8,>=7.5.0->nbinteract) (4.10.1)\n", | |
"Requirement already satisfied: widgetsnbextension~=3.5.0 in /usr/local/lib/python3.6/dist-packages (from ipywidgets<8,>=7.5.0->nbinteract) (3.5.1)\n", | |
"Requirement already satisfied: mistune<2,>=0.8.1 in /usr/local/lib/python3.6/dist-packages (from nbconvert<6,>=5.3->nbinteract) (0.8.4)\n", | |
"Requirement already satisfied: testpath in /usr/local/lib/python3.6/dist-packages (from nbconvert<6,>=5.3->nbinteract) (0.4.4)\n", | |
"Requirement already satisfied: pandocfilters>=1.4.1 in /usr/local/lib/python3.6/dist-packages (from nbconvert<6,>=5.3->nbinteract) (1.4.2)\n", | |
"Requirement already satisfied: bleach in /usr/local/lib/python3.6/dist-packages (from nbconvert<6,>=5.3->nbinteract) (3.1.5)\n", | |
"Requirement already satisfied: defusedxml in /usr/local/lib/python3.6/dist-packages (from nbconvert<6,>=5.3->nbinteract) (0.6.0)\n", | |
"Requirement already satisfied: entrypoints>=0.2.2 in /usr/local/lib/python3.6/dist-packages (from nbconvert<6,>=5.3->nbinteract) (0.3)\n", | |
"Collecting traittypes>=0.0.6\n", | |
" Downloading https://files.pythonhosted.org/packages/9c/d1/8d5bd662703cc1764d986f6908a608777305946fa634d34c470cd4a1e729/traittypes-0.2.1-py2.py3-none-any.whl\n", | |
"Requirement already satisfied: pandas in /usr/local/lib/python3.6/dist-packages (from bqplot==0.11.0->nbinteract) (1.0.5)\n", | |
"Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.6/dist-packages (from Jinja2<3,>=2.10->nbinteract) (1.1.1)\n", | |
"Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from traitlets<5,>=4.3->nbinteract) (1.15.0)\n", | |
"Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.6/dist-packages (from pexpect; sys_platform != \"win32\"->IPython<8,>=6->nbinteract) (0.6.0)\n", | |
"Requirement already satisfied: wcwidth in /usr/local/lib/python3.6/dist-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->IPython<8,>=6->nbinteract) (0.2.5)\n", | |
"Requirement already satisfied: parso<0.8.0,>=0.7.0 in /usr/local/lib/python3.6/dist-packages (from jedi>=0.10->IPython<8,>=6->nbinteract) (0.7.1)\n", | |
"Requirement already satisfied: tornado>=4.0 in /usr/local/lib/python3.6/dist-packages (from ipykernel>=4.5.1->ipywidgets<8,>=7.5.0->nbinteract) (5.1.1)\n", | |
"Requirement already satisfied: jupyter-client in /usr/local/lib/python3.6/dist-packages (from ipykernel>=4.5.1->ipywidgets<8,>=7.5.0->nbinteract) (5.3.5)\n", | |
"Requirement already satisfied: notebook>=4.4.1 in /usr/local/lib/python3.6/dist-packages (from widgetsnbextension~=3.5.0->ipywidgets<8,>=7.5.0->nbinteract) (5.3.1)\n", | |
"Requirement already satisfied: webencodings in /usr/local/lib/python3.6/dist-packages (from bleach->nbconvert<6,>=5.3->nbinteract) (0.5.1)\n", | |
"Requirement already satisfied: packaging in /usr/local/lib/python3.6/dist-packages (from bleach->nbconvert<6,>=5.3->nbinteract) (20.4)\n", | |
"Requirement already satisfied: python-dateutil>=2.6.1 in /usr/local/lib/python3.6/dist-packages (from pandas->bqplot==0.11.0->nbinteract) (2.8.1)\n", | |
"Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/dist-packages (from pandas->bqplot==0.11.0->nbinteract) (2018.9)\n", | |
"Requirement already satisfied: pyzmq>=13 in /usr/local/lib/python3.6/dist-packages (from jupyter-client->ipykernel>=4.5.1->ipywidgets<8,>=7.5.0->nbinteract) (19.0.2)\n", | |
"Requirement already satisfied: terminado>=0.8.1 in /usr/local/lib/python3.6/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.5.0->nbinteract) (0.8.3)\n", | |
"Requirement already satisfied: Send2Trash in /usr/local/lib/python3.6/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets<8,>=7.5.0->nbinteract) (1.5.0)\n", | |
"Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.6/dist-packages (from packaging->bleach->nbconvert<6,>=5.3->nbinteract) (2.4.7)\n", | |
"\u001b[31mERROR: jupyter-console 5.2.0 has requirement prompt-toolkit<2.0.0,>=1.0.0, but you'll have prompt-toolkit 3.0.6 which is incompatible.\u001b[0m\n", | |
"\u001b[31mERROR: google-colab 1.0.0 has requirement ipython~=5.5.0, but you'll have ipython 7.16.1 which is incompatible.\u001b[0m\n", | |
"Installing collected packages: prompt-toolkit, IPython, nbformat, traittypes, bqplot, nbinteract\n", | |
" Found existing installation: prompt-toolkit 1.0.18\n", | |
" Uninstalling prompt-toolkit-1.0.18:\n", | |
" Successfully uninstalled prompt-toolkit-1.0.18\n", | |
" Found existing installation: ipython 5.5.0\n", | |
" Uninstalling ipython-5.5.0:\n", | |
" Successfully uninstalled ipython-5.5.0\n", | |
" Found existing installation: nbformat 5.0.7\n", | |
" Uninstalling nbformat-5.0.7:\n", | |
" Successfully uninstalled nbformat-5.0.7\n", | |
"Successfully installed IPython-7.16.1 bqplot-0.11.0 nbformat-4.4.0 nbinteract-0.2.5 prompt-toolkit-3.0.6 traittypes-0.2.1\n" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.colab-display-data+json": { | |
"pip_warning": { | |
"packages": [ | |
"IPython", | |
"prompt_toolkit" | |
] | |
} | |
} | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "w9QagbjjrDN3", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"## Generating data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "pN8IW8pEotBN", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"%matplotlib inline\n", | |
"from ipywidgets import interactive\n", | |
"import nbinteract as nbi\n", | |
"import numpy as np" | |
], | |
"execution_count": 1, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "JGH0H0yho-eg", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"rolls = np.random.choice([1, 2, 3, 4, 5, 6], size=10000)\n", | |
"averages = np.cumsum(rolls) / np.arange(1, 10001)\n", | |
"\n", | |
"def x_vals(num_rolls):\n", | |
" return range(num_rolls)\n", | |
"\n", | |
"# The function to generate y-values gets called with the\n", | |
"# x-values as its first argument.\n", | |
"def y_vals(xs):\n", | |
" return averages[:len(xs)]" | |
], | |
"execution_count": 2, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "H4bNj96sqSig", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"# Display Graph" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "l7g8tN6qqUgz", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 164 | |
}, | |
"outputId": "fdab856f-1a79-4480-a23b-4fe981f8f621" | |
}, | |
"source": [ | |
"line = nbi.line(x_vals, y_vals, num_rolls=(1, 10000))" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "error", | |
"ename": "NameError", | |
"evalue": "ignored", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-1-cba5e8cc613b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mline\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnbi\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mline\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_vals\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_vals\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnum_rolls\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m10000\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mNameError\u001b[0m: name 'nbi' is not defined" | |
] | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment