├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE.txt ├── MANIFEST.in ├── README.md ├── check.sh ├── conda ├── meta.yaml └── upload.sh ├── docker └── ubuntu1604 ├── docs ├── conda.md ├── dot_commands.md ├── nbconvert_pdf_via_latex.md └── virtualenvs.md ├── external ├── README └── seaborn │ ├── COPYING │ ├── README │ └── dist │ ├── .coveragerc │ ├── .gitignore │ ├── .mailmap │ ├── .travis.yml │ ├── CONTRIBUTING.md │ ├── LICENSE │ ├── MANIFEST.in │ ├── Makefile │ ├── README.md │ ├── devel_requirements_py2.txt │ ├── devel_requirements_py3.txt │ ├── doc │ ├── .gitignore │ ├── Makefile │ ├── _static │ │ ├── copybutton.js │ │ └── style.css │ ├── api.rst │ ├── conf.py │ ├── index.rst │ ├── installing.rst │ ├── introduction.rst │ ├── releases │ │ ├── v0.2.0.txt │ │ ├── v0.2.1.txt │ │ ├── v0.3.0.txt │ │ ├── v0.3.1.txt │ │ ├── v0.4.0.txt │ │ ├── v0.5.0.txt │ │ ├── v0.5.1.txt │ │ ├── v0.6.0.txt │ │ ├── v0.7.0.txt │ │ └── v0.7.1.txt │ ├── sphinxext │ │ ├── ipython_console_highlighting.py │ │ ├── ipython_directive.py │ │ ├── plot_directive.py │ │ └── plot_generator.py │ ├── tutorial.rst │ ├── tutorial │ │ ├── Makefile │ │ ├── aesthetics.ipynb │ │ ├── axis_grids.ipynb │ │ ├── categorical.ipynb │ │ ├── color_palettes.ipynb │ │ ├── distributions.ipynb │ │ ├── regression.ipynb │ │ └── tools │ │ │ ├── nb_to_doc.py │ │ │ └── nbstripout │ └── whatsnew.rst │ ├── examples │ ├── .gitignore │ ├── anscombes_quartet.py │ ├── color_palettes.py │ ├── cubehelix_palette.py │ ├── distplot_options.py │ ├── elaborate_violinplot.py │ ├── faceted_histogram.py │ ├── facets_with_custom_projection.py │ ├── factorplot_bars.py │ ├── grouped_boxplot.py │ ├── grouped_violinplots.py │ ├── heatmap_annotation.py │ ├── hexbin_marginals.py │ ├── horizontal_barplot.py │ ├── horizontal_boxplot.py │ ├── interactplot.py │ ├── joint_kde.py │ ├── logistic_regression.py │ ├── many_facets.py │ ├── many_pairwise_correlations.py │ ├── marginal_ticks.py │ ├── multiple_joint_kde.py │ ├── multiple_regression.py │ ├── network_correlations.py │ ├── pair_grid_with_kde.py │ ├── paired_pointplots.py │ ├── pairgrid_dotplot.py │ ├── pointplot_anova.py │ ├── regression_marginals.py │ ├── residplot.py │ ├── scatterplot_categorical.py │ ├── scatterplot_matrix.py │ ├── simple_violinplots.py │ ├── structured_heatmap.py │ ├── timeseries_bootstrapped.py │ ├── timeseries_from_dataframe.py │ ├── timeseries_of_barplots.py │ └── tips.csv │ ├── licences │ ├── HUSL_LICENSE │ └── SIX_LICENSE │ ├── requirements.txt │ ├── seaborn │ ├── __init__.py │ ├── algorithms.py │ ├── apionly.py │ ├── axisgrid.py │ ├── categorical.py │ ├── crayons.py │ ├── distributions.py │ ├── external │ │ ├── __init__.py │ │ ├── husl.py │ │ └── six.py │ ├── linearmodels.py │ ├── matrix.py │ ├── miscplot.py │ ├── palettes.py │ ├── rcmod.py │ ├── tests │ │ ├── __init__.py │ │ ├── test_algorithms.py │ │ ├── test_axisgrid.py │ │ ├── test_categorical.py │ │ ├── test_distributions.py │ │ ├── test_linearmodels.py │ │ ├── test_matrix.py │ │ ├── test_miscplot.py │ │ ├── test_palettes.py │ │ ├── test_rcmod.py │ │ └── test_utils.py │ ├── timeseries.py │ ├── utils.py │ ├── widgets.py │ └── xkcd_rgb.py │ ├── setup.py │ └── testing │ ├── deps_minimal_2.7.txt │ ├── deps_modern_2.7.txt │ ├── deps_modern_3.4.txt │ ├── deps_modern_3.5.txt │ └── matplotlibrc ├── pythenv.sh ├── script ├── code_blocks.py ├── manager.py └── tex_header.tex ├── setup.py ├── src ├── __init__.py ├── jsviz │ ├── __init__.py │ ├── bar.js │ ├── depprob.js │ ├── heatmap.js │ ├── inline.js │ ├── jsviz.py │ ├── pairplot.js │ └── scatter.js ├── jupyter │ ├── __init__.py │ └── magics.py ├── magics.py ├── sessions.py ├── utils_bql.py ├── utils_mml.py ├── utils_plot.py ├── utils_sql.py └── utils_unix.py └── tests ├── __init__.py ├── conftest.py ├── test_nullop.py └── test_plot_smoke.py /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /src/version.py 3 | .ipynb_checkpoints* 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | dist: trusty 3 | env: 4 | global: 5 | - PACKAGE_NAME=iventure 6 | # get all the branches referencing this commit 7 | - REAL_BRANCH=$(git ls-remote origin | sed -n "\|$TRAVIS_COMMIT\s\+refs/heads/|{s///p}") 8 | 9 | python: 10 | - 2.7 11 | 12 | install: 13 | - wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh; 14 | - bash miniconda.sh -b -p $HOME/miniconda 15 | - export PATH="$HOME/miniconda/bin:$PATH" 16 | - hash -r 17 | - conda config --set always_yes yes --set changeps1 no 18 | - conda info -a 19 | - conda install -q conda=4.6.14 conda-build 20 | 21 | script: 22 | - export CONDA_PACKAGE_VERSION="${TRAVIS_TAG:-$(date +%Y.%m.%d)}" 23 | # remove leading v from tags if they exist 24 | - CONDA_PACKAGE_VERSION="$(sed s/^v// <<<$CONDA_PACKAGE_VERSION)" 25 | - conda build . -c probcomp -c anaconda 26 | - conda install iventure --use-local 27 | 28 | after_success: 29 | - bash conda/upload.sh 30 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Please refer to [CONTRIBUTING.md](https://github.com/probcomp/bayeslite/blob/master/CONTRIBUTING.md) 4 | in the bayeslite repository for probcomp-specific standards. 5 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include HACKING 2 | include README.md 3 | include VERSION 4 | include check.sh 5 | include docs/virtualenvs.md 6 | include pythenv.sh 7 | include requirements.txt 8 | include tests/test_nullop.py 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Interactive Environment For Probabilistic Programming for Probabilistic Data Analysis 2 | 3 | [![Build Status](https://travis-ci.org/probcomp/iventure.svg?branch=master)](https://travis-ci.org/probcomp/iventure) 4 | 5 | ## About 6 | 7 | iventure serves as a jupyter-based front-end for [BayesDB](https://github.com/probcomp/bayeslite). 8 | 9 | ## Installing 10 | 11 | For access to iventure, please refer to the release webpage of the 12 | [Probabilistic Computing Stack](http://probcomp.org/open-probabilistic-programming-stack/). 13 | 14 | ## Tutorial Notebooks 15 | 16 | Please refer to the following tutorial notebooks for illustrative probabilistic 17 | data analysis tasks on real-world datasets: 18 | 19 | - [Exploratory analysis](https://probcomp-1.csail.mit.edu/20170720-darpa/gapminder-exploratory.html) 20 | on Gapminder, a dataset of global macroeconomic indicators of education, 21 | poverty, environment and health. 22 | 23 | - [Predictive analysis](https://probcomp-1.csail.mit.edu/20170720-darpa/satellites-predictive.html) 24 | on a table of Earth satellites from the Union of Concerned Scientists. 25 | 26 | ## Magics Usage 27 | 28 | The `magics.py` contains cell magics which allow for interactive probabilistic 29 | programming in a Jupyter notebook. 30 | 31 | In the first cell of a Jupyter notebook, load the extension. 32 | ``` 33 | %load_ext iventure.magics 34 | ``` 35 | 36 | #### Open a bdb file 37 | ``` 38 | %bayesdb foo.bdb 39 | ``` 40 | 41 | #### Write MML programs 42 | ``` 43 | %mml CREATE POPULATION ... 44 | ``` 45 | or, for multi-line schemas. 46 | ``` 47 | %%mml 48 | DROP POPULATION xyz; 49 | CREATE POPULATION xyz for t (...); 50 | ``` 51 | 52 | #### Write BQL programs 53 | ``` 54 | %bql ESTIMATE MUTUAL INFORMATION OF x WITH y WITHIN xyz; 55 | ``` 56 | or, for multi-line queries 57 | ``` 58 | %%bql 59 | CREATE TEMP TABLE depprobs AS 60 | ESTIMATE DEPENDENCE PROBABILITY FROM PARIWSE VARIABLES OF xyz; 61 | .plot SELECT * FROM depprobs 62 | ``` 63 | 64 | #### Use dot commands for BQL shorthands 65 | ``` 66 | %bql .nullify satellites_t NaN 67 | %bql .population satellites_p 68 | ``` 69 | 70 | #### Use dot commands with BQL for plotting 71 | ``` 72 | %bql .scatter SELECT apogee_km, perigee_km FROM satellites_t LIMIT 100; 73 | ``` 74 | -------------------------------------------------------------------------------- /check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -Ceu 4 | 5 | : ${PYTHON:=python} 6 | 7 | root=`cd -- "$(dirname -- "$0")" && pwd` 8 | 9 | ( 10 | set -Ceu 11 | cd -- "${root}" 12 | rm -rf build 13 | "$PYTHON" setup.py build 14 | export MPLBACKEND=pdf 15 | if [ $# -eq 0 ]; then 16 | # By default, when running all tests, skip tests that have 17 | # been marked for continuous integration by using __ci_ in 18 | # their names. (git grep __ci_ to find these.) 19 | ./pythenv.sh "$PYTHON" -m pytest -k "not __ci_" --pyargs iventure 20 | else 21 | # If args are specified, run all tests, including continuous 22 | # integration tests, for the selected components. 23 | ./pythenv.sh "$PYTHON" -m pytest "$@" 24 | fi 25 | ) 26 | -------------------------------------------------------------------------------- /conda/meta.yaml: -------------------------------------------------------------------------------- 1 | package: 2 | name: iventure 3 | version: {{ CONDA_PACKAGE_VERSION }} 4 | 5 | source: 6 | path: ../ 7 | 8 | build: 9 | script: python setup.py install 10 | 11 | requirements: 12 | build: 13 | - git 14 | - python 2.7.* 15 | run: 16 | # add bayeslite>0.2.0rc1 when it's packaged 17 | - matplotlib 1.5.* 18 | - numpy 1.11.* 19 | - pandas 0.18.* 20 | - scipy 0.17.* 21 | 22 | test: 23 | requires: 24 | - pytest 2.8.* 25 | - python 2.7.* 26 | commands: 27 | - python -m pytest --pyargs iventure 28 | 29 | about: 30 | home: https://github.com/probcomp/iventure 31 | -------------------------------------------------------------------------------- /conda/upload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -ev 3 | 4 | # fyi, the logic below is necessary due to the fact that on a tagged build, TRAVIS_BRANCH and TRAVIS_TAG are the same 5 | # in the case of a tagged build, use the REAL_BRANCH env var defined in travis.yml 6 | if [ -n "${TRAVIS_TAG}" ]; then 7 | conda install anaconda-client 8 | # if tag didn't come from master, add the "dev" label 9 | if [ ${REAL_BRANCH} = "master" ]; then 10 | anaconda -t ${CONDA_UPLOAD_TOKEN} upload -u ${CONDA_USER} ~/miniconda/conda-bld/linux-64/${PACKAGE_NAME}-*.tar.bz2 --force 11 | else 12 | anaconda -t ${CONDA_UPLOAD_TOKEN} upload -u ${CONDA_USER} -l dev ~/miniconda/conda-bld/linux-64/${PACKAGE_NAME}-*.tar.bz2 --force 13 | fi 14 | elif [ ${TRAVIS_BRANCH} = "master" ]; then 15 | if [ ${TRAVIS_EVENT_TYPE} = "cron" ]; then 16 | # don't build package for nightly cron.. this is just for test stability info 17 | exit 0 18 | else 19 | conda install anaconda-client 20 | anaconda -t ${CONDA_UPLOAD_TOKEN} upload -u ${CONDA_USER} -l edge ~/miniconda/conda-bld/linux-64/${PACKAGE_NAME}-*.tar.bz2 --force 21 | fi 22 | else 23 | exit 0 24 | fi 25 | -------------------------------------------------------------------------------- /docker/ubuntu1604: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | MAINTAINER MIT Probabilistic Computing Project 3 | 4 | RUN apt-get update -qq && apt-get install -qq \ 5 | git \ 6 | python-jsonschema \ 7 | python-numpy \ 8 | python-pandas \ 9 | python-pytest \ 10 | python-scipy \ 11 | python-six \ 12 | python-matplotlib \ 13 | ; # end of package list 14 | 15 | ADD . /iventure 16 | WORKDIR /iventure 17 | RUN \ 18 | ./docker/deps/bayeslite-apsw/pythenv.sh \ 19 | ./docker/deps/bayeslite/pythenv.sh \ 20 | ./docker/deps/cgpm/pythenv.sh \ 21 | ./docker/deps/crosscat/pythenv.sh \ 22 | ./check.sh 23 | RUN python setup.py sdist 24 | RUN python setup.py bdist 25 | -------------------------------------------------------------------------------- /docs/conda.md: -------------------------------------------------------------------------------- 1 | # Setting up a conda environment with probcomp repositories and their dependencies 2 | 3 | These instructions are tested on `Ubuntu 18.04`, different Linux distributions 4 | might require small modifications. All of these commands perform a local 5 | installation for the current user, they do not modify any system-wide state or 6 | require root access. 7 | 8 | #### Retrieve the required installation files. 9 | 10 | ```bash 11 | $ wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O /tmp/miniconda.sh 12 | $ wget https://raw.githubusercontent.com/probcomp/notebook/master/files/conda_python2.txt -O /tmp/conda_python2.txt 13 | $ wget https://raw.githubusercontent.com/probcomp/notebook/master/files/conda_probcomp.txt -O /tmp/conda_probcomp.txt 14 | ``` 15 | 16 | #### Install conda and environment containing the probcomp software. 17 | 18 | ```bash 19 | $ bash /tmp/miniconda.sh -b -p ${HOME}/miniconda 20 | $ . ${HOME}/miniconda/etc/profile.d/conda.sh 21 | $ conda install --yes conda=4.6.14 conda-build 22 | $ conda create -n probcomp --yes --file /tmp/conda_python2.txt python=2.7 23 | $ conda install -n probcomp --quiet --yes \ 24 | -c probcomp -c cidermole -c fritzo -c ursusest \ 25 | --file /tmp/conda_probcomp.txt 26 | ``` 27 | 28 | Optional: The line `. ${HOME}/miniconda/etc/profile.d/conda.sh` needs to be run 29 | for the `conda` command to be available, consider adding this line to your 30 | `.bashrc` or `.zshrc` file. 31 | 32 | #### Activate the environment and run some tests. 33 | 34 | ```bash 35 | $ conda activate probcomp 36 | $ python -m pytest --pyargs bayeslite 37 | ``` 38 | 39 | #### Developing a project. 40 | 41 | To develop a project, such as bayeslite, first uninstall it from conda, and 42 | build the source directly. 43 | 44 | ```bash 45 | $ conda remove --force bayeslite 46 | $ git clone git@github.com:probcomp/bayeslite 47 | $ python setup.py install 48 | ``` 49 | -------------------------------------------------------------------------------- /docs/dot_commands.md: -------------------------------------------------------------------------------- 1 | # jupyter_probcomp dot commands 2 | Dot commands in the BQL section below should be prepended by `%bql` (for 3 | single-line commands) or `%%bql` (for multi-line commands). Similarly, those in 4 | the MML section should be prepended by `%mml` or `%%mml` and those in the SQL 5 | section should be prepended by `%sql` or `%%sql`. 6 | 7 | ## BQL 8 | - `%bql .assert ` 9 | 10 | Returns a message indicating whether the test represented by `` 11 | passed or failed, i.e. whether `` returned 1 or 0. 12 | 13 | - `%bql .nullify ` 14 | 15 | Converts all instances of `` in `
` to SQL `NULL`. 16 | 17 | - `%bql .population ` 18 | 19 | Returns a table of the variables (including their statistical types) and 20 | generators for ``. 21 | 22 | - `%bql .subsample_columns
[--keep [...]] [--seed SEED]` 23 | 24 | Creates a new table named `` containing `` columns 25 | from `
`. Any columns listed after the `--keep` flag are kept, columns 26 | listed after `--drop` flag are dropped, and the remainder are randomly 27 | sampled from `
`. 28 | 29 | - `%bql .table
` 30 | 31 | Returns a table of the PRAGMA schema of `
`. 32 | 33 | ### Plotting 34 | #### Interactive 35 | Interactive plotting can be enabled by running `%vizgpm inline`. 36 | The following dot commands work the same as their standard equivalents below, 37 | with additional capabilities for scrolling around and selecting data in the 38 | plots. 39 | 40 | - `%bql .interactive_bar ` 41 | 42 | - `%bql .interactive_heatmap ` 43 | 44 | - `%bql .interactive_scatter ` 45 | 46 | Additionally, interactive plotting includes pairplots: 47 | 48 | - `%bql .interactive_pairplot ` 49 | 50 | Pairplot of the data points in the table returned by ``. 51 | 52 | #### Standard 53 | The following plotting dot commands can take several optional arguments, 54 | described in "Optional arguments" below. Each dot command can take multiple 55 | optional arguments in `[options]`, each of the form `--=`. 56 | 57 | - `%bql .bar [options] ` 58 | 59 | Vertical barplot of the data points in the table returned by ``. The 60 | first column is (nominal) names, and the second column is (numerical) 61 | values. 62 | 63 | - `%bql .barh [options] ` 64 | 65 | Horizontal barplot of the data points in the table returned by ``. 66 | The first column is (nominal) names, and the second column is (numerical) 67 | values. 68 | 69 | - `%bql .clustermap [options] ` 70 | 71 | Clustermap plotted by pivoting the last three columns of the table returned 72 | by `` (typically an `ESTIMATE PAIRWISE` query in BQL). 73 | 74 | - `%bql .density [options] ` 75 | 76 | Density plot of the data points in the table returned by ``. If the 77 | table has one column, then a regular density plot is produced. If the table 78 | has two columns, then the final column is used as the label for each data 79 | point. 80 | 81 | - `%bql .heatmap [options] ` 82 | 83 | Heatmap plotted by pivoting the last three columns of the table returned by 84 | `` (typically an `ESTIMATE PAIRWISE` query in BQL). 85 | 86 | - `%bql .histogram_nominal [options] ` 87 | 88 | Histogram of the NOMINAL data points in the table returned by ``. If 89 | the table has one column, then a regular histogram is produced. If the table 90 | has two columns, then the final column is used as the label for each data 91 | point. 92 | 93 | - `%bql .histogram_numerical [options] ` 94 | 95 | Histogram of the NUMERICAL data points in the table returned by ``. 96 | If the table has one column, then a regular histogram is produced. If the 97 | table has two columns, then the final column is used as the label for each 98 | data point. 99 | 100 | - `%bql .render_crosscat [special_options] ` 101 | 102 | Renders the state of the CrossCat model `` in 103 | ``. Instead of the standard optional arguments, this 104 | function takes the following special optional arguments: 105 | - `--subsample=` 106 | 107 | Number of rows to subsample (recommend <50). 108 | 109 | - `--width=` 110 | 111 | Width of the figure. 112 | 113 | - `--height=` 114 | 115 | Height of the figure. 116 | 117 | - `--rowlabels=` 118 | 119 | Name of the column in the base table to use as row labels. 120 | 121 | - `--progress=[True|False]` 122 | 123 | Whether to show a progress bar. 124 | 125 | - `--yticklabeslize=` 126 | 127 | Size of the row labels. 128 | 129 | - `--xticklabeslize=` 130 | 131 | Size of the column labels. 132 | 133 | - `%bql .scatter [options] ` 134 | 135 | Scatter plot of the NUMERICAL data points in the table returned by 136 | ``. If the table has two columns, then a regular scatter plot is 137 | produced. If the table has three columns, then the final column is used as 138 | the label for each data point. 139 | 140 | ##### Optional arguments 141 | - `xmin=` 142 | 143 | Sets the minimum x-axis value to ``. 144 | 145 | - `xmax=` 146 | 147 | Sets the maximum x-axis value to ``. 148 | 149 | - `ymin=` 150 | 151 | Sets the minimum y-axis value to ``. 152 | 153 | - `ymax=` 154 | 155 | Sets the maximum y-axis value to ``. 156 | 157 | - `xlog=` 158 | 159 | Sets the x scale to logarithmic with base ``. 160 | 161 | - `ylog=` 162 | 163 | Sets the y scale to logarithmic with base ``. 164 | 165 | - `xlabel=` 166 | 167 | Sets the x-axis label to ``. 168 | 169 | - `ylabel=` 170 | 171 | Sets the y-axis label to ``. 172 | 173 | - `rug=[True|False]` 174 | 175 | For `.density` only. Default `True`. Setting to `False` turns off plotting 176 | rug marks (the tick marks on the x-axis indicating individual values). 177 | 178 | - `shade=[True|False]` 179 | 180 | For `.density` only. Default `True`. Setting to `False` turns off shading 181 | the area under the density curve. 182 | 183 | ## MML 184 | - `%mml .guess_schema
` 185 | 186 | Returns an MML schema using the guessed statistical types for the columns of 187 | `
`. 188 | 189 | ## SQL 190 | - `%sql .regress_sql [--table=
] ` 191 | 192 | Returns a table of the results of a BQL REGRESS ``. 193 | -------------------------------------------------------------------------------- /docs/nbconvert_pdf_via_latex.md: -------------------------------------------------------------------------------- 1 | # Converting iventure notebooks to pdf via LaTeX 2 | 3 | This document outlines some steps for improving conversion of iventure Jupyter 4 | notebooks to pdf via LaTeX. In particular, these steps: 5 | - make pandas dataframes render as LaTeX tables when converted to pdf 6 | - remove the `In[]:`and `Out[]:` before cells in the pdf 7 | - remove all outputs that are just empty dataframes 8 | - wrap text at the margin 9 | 10 | ## 1. Displaying pandas dataframes as LaTeX tables 11 | Insert the following code into a code cell in the notebook and run it before 12 | running any cells that output pandas dataframes. This will cause the dataframes 13 | to render as they normally would in the HTML version of the notebook, but as 14 | LaTeX tables in the pdf. 15 | 16 | import pandas as pd 17 | 18 | pd.set_option('display.notebook_repr_html', True) 19 | 20 | def _repr_latex_(self): 21 | return self.to_latex() 22 | 23 | pd.DataFrame._repr_latex_ = _repr_latex_ 24 | 25 | ## 2. Adding a custom template for LaTeX conversion 26 | Add the following custom template as `custom.tplx` in `python2.7/site-packages/nbconvert/templates/latex/` 27 | (may be overwritten during upgrades) or another directory of your choice. This 28 | template wraps text at the margin, removes `In[]:` and `Out[]:` before cells in 29 | the pdf, and removes all outputs that are just empty dataframes. 30 | 31 | ((*- extends 'article.tplx' -*)) 32 | %=============================================================================== 33 | % Input 34 | %=============================================================================== 35 | ((* block input scoped *)) 36 | ((( custom_add_prompt(cell.source | wrap_text(88) | highlight_code(strip_verbatim=True), cell) ))) 37 | ((* endblock input *)) 38 | %=============================================================================== 39 | % Output 40 | %=============================================================================== 41 | ((* block execute_result scoped *)) 42 | ((*- for type in output.data | filter_data_type -*)) 43 | ((*- if type in ['text/plain']*)) 44 | ((*- if "Empty DataFrame" in output.data['text/plain']*)) 45 | ((( custom_add_prompt('' | wrap_text(88) | escape_latex, cell) ))) 46 | ((* else -*)) 47 | ((( custom_add_prompt(output.data['text/plain'] | wrap_text(88) | escape_latex, cell) ))) 48 | ((*- endif -*)) 49 | ((* else -*)) 50 | ((( super() ))) 51 | ((*- endif -*)) 52 | ((*- endfor -*)) 53 | ((* endblock execute_result *)) 54 | %============================================================================== 55 | % Define macro custom_add_prompt() (derived from add_prompt() macro in style_ipython.tplx) 56 | %============================================================================== 57 | ((* macro custom_add_prompt(text, cell) -*)) 58 | \begin{Verbatim}[commandchars=\\\{\},fontsize=\scriptsize] 59 | ((( text ))) 60 | \end{Verbatim} 61 | ((*- endmacro *)) 62 | 63 | ## 3. Adding a custom style_ipython template 64 | Replace the existing `python2.7/site-packages/nbconvert/templates/latex/style_ipython.tplx` 65 | with the following. NOTE: this file may be overwritten by upgrades, so it is also 66 | possible to put this file in a another directory (as long as the 67 | `style_ipython.tplx` in `python2.7/site-packages/nbconvert/templates/latex/` is 68 | renamed to avoid conflicts). There is a one-line change in 69 | `((* block execute_result scoped *))`, which completes the removal of `In[]:` 70 | and `Out[]:` when `super()` is called from a subclass. 71 | 72 | ((= IPython input/output style =)) 73 | ((*- extends 'base.tplx' -*)) 74 | % Custom definitions 75 | ((* block definitions *)) 76 | ((( super() ))) 77 | % Pygments definitions 78 | ((( resources.latex.pygments_definitions ))) 79 | % Exact colors from NB 80 | \definecolor{incolor}{rgb}{0.0, 0.0, 0.5} 81 | \definecolor{outcolor}{rgb}{0.545, 0.0, 0.0} 82 | ((* endblock definitions *)) 83 | %=============================================================================== 84 | % Input 85 | %=============================================================================== 86 | ((* block input scoped *)) 87 | ((( add_prompt(cell.source | highlight_code(strip_verbatim=True), cell, 'In', 'incolor') ))) 88 | ((* endblock input *)) 89 | %=============================================================================== 90 | % Output 91 | %=============================================================================== 92 | ((* block execute_result scoped *)) 93 | ((*- for type in output.data | filter_data_type -*)) 94 | ((*- if type in ['text/plain']*)) 95 | ((( add_prompt(output.data['text/plain'] | escape_latex, cell, 'Out', 'outcolor') ))) 96 | ((* else -*)) 97 | ((( super() ))) 98 | ((*- endif -*)) 99 | ((*- endfor -*)) 100 | ((* endblock execute_result *)) 101 | %============================================================================== 102 | % Support Macros 103 | %============================================================================== 104 | % Name: draw_prompt 105 | % Purpose: Renders an output/input prompt 106 | ((* macro add_prompt(text, cell, prompt, prompt_color) -*)) 107 | ((*- if cell.execution_count is defined -*)) 108 | ((*- set execution_count = "" ~ (cell.execution_count | replace(None, " ")) -*)) 109 | ((*- else -*)) 110 | ((*- set execution_count = " " -*)) 111 | ((*- endif -*)) 112 | ((*- set indention = " " * (execution_count | length + 7) -*)) 113 | \begin{Verbatim}[commandchars=\\\{\}] 114 | ((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ execution_count ~ '}]:} ', cont=indention) ))) 115 | \end{Verbatim} 116 | ((*- endmacro *)) 117 | 118 | ## 4. Running nbconvert 119 | From the directory of the desired Jupyter notebook, you can now run: 120 | `jupyter nbconvert --to pdf --template /path/to/custom.tplx `. 121 | Note that being able to specify absolute paths to template files may require 122 | upgrading `nbconvert`. -------------------------------------------------------------------------------- /docs/virtualenvs.md: -------------------------------------------------------------------------------- 1 | # Setting up a python virtualenv with probcomp repositories and their dependencies. 2 | 3 | These instructions are tested on `Ubuntu 16.04.5`, different Linux distributions 4 | might require small modifications. 5 | 6 | #### Retrieve required packages from the Ubuntu standard repositories. 7 | 8 | ```bash 9 | sudo apt-get update -qq && \ 10 | sudo apt-get upgrade -qq && \ 11 | sudo apt-get install -qq \ 12 | build-essential \ 13 | ccache \ 14 | cython \ 15 | git \ 16 | libboost-all-dev \ 17 | libgsl0-dev \ 18 | pandoc \ 19 | python-apsw \ 20 | python-flask \ 21 | python-jsonschema \ 22 | python-matplotlib \ 23 | python-nose \ 24 | python-nose-testconfig \ 25 | python-numpy \ 26 | python-pandas \ 27 | python-pexpect \ 28 | python-pip \ 29 | python-pytest \ 30 | python-requests \ 31 | python-scipy \ 32 | python-six \ 33 | python-sklearn \ 34 | python-statsmodels \ 35 | python-virtualenv \ 36 | ; # end of package list 37 | ``` 38 | 39 | #### Create a virtual environment and install jupyter. 40 | 41 | ```bash 42 | $ virtualenv --system-site-packages /path/to/venv 43 | $ . /path/to/venv/bin/activate 44 | $ pip install --upgrade pip 45 | $ pip install setuptools==44.1.1 ipykernel==4.8.2 notebook==5.2.1 46 | ``` 47 | 48 | #### Retrieve probcomp repositories from Github and build. 49 | 50 | ```bash 51 | $ for project in bayeslite cgpm crosscat iventure Venturecxx; do 52 | git clone git@github.com:probcomp/"${project}".git 53 | cd "${project}" 54 | python setup.py build 55 | pip install --no-deps . 56 | cd .. 57 | done 58 | ``` 59 | 60 | #### Verify import of iventure. 61 | 62 | ```bash 63 | $ python -c 'import iventure.magics' 64 | ``` 65 | 66 | #### Optional: Run the test suite for probcomp repositories (may take a while). 67 | 68 | ```bash 69 | $ for project in bayeslite cgpm crosscat iventure Venturecxx; do 70 | cd "${project}" 71 | ./check.sh 72 | cd .. 73 | done 74 | ``` 75 | -------------------------------------------------------------------------------- /external/README: -------------------------------------------------------------------------------- 1 | This directory contains software that is used in iventure but written 2 | and maintained externally by someone else. We will use the following 3 | organization in order to: 4 | 5 | - Use external software that is not in Ubuntu and does not use Git. 6 | - Keep history of our updates to external software. 7 | - Make local changes as we need and send patches upstream. 8 | - Merge our local changes into external updates. 9 | - Avoid imposing the mess of submodules on users. 10 | 11 | * Directory layout: 12 | 13 | Each subdirectory corresponds to one external package and has the 14 | following contents: 15 | 16 | COPYING summary of copying terms 17 | README notes on upstream, link to upstream web site, &c. 18 | dist/ subdirectory containing the external distribution 19 | prepare.sh script to prepare a distribution for import 20 | ... other supporting files 21 | 22 | prepare.sh should run in the top-level directory of the external 23 | distribution, which will then be imported under dist/. It should only 24 | do clean-ups necessary to make the distribution fit for inclusion in 25 | our tree, such as deleting binary files. Local changes, such as bug 26 | fixes, should be made in separate commits. 27 | 28 | * To import a new external package: 29 | 30 | 1. Write the COPYING and README files and the prepare.sh script, and 31 | commit them. 32 | 33 | 2. Create a temporary Git repository for the package: 34 | 35 | % cd /tmp 36 | % mkdir repo 37 | % cd repo 38 | % git init 39 | 40 | 3. Extract proj-1.2 in external/proj/dist in the temporary repository: 41 | 42 | % mkdir -p external/proj 43 | % cd external/proj 44 | % gunzip -c < /tmp/proj-1.2.tar.gz | tar xf - 45 | % mv proj-1.2 dist 46 | 47 | 4. Run the prepare.sh script: 48 | 49 | % (cd dist && sh /path/to/iventure/external/proj/prepare.sh) 50 | 51 | 5. Commit the result in the temporary repository: 52 | 53 | % git add dist 54 | % git commit 55 | 56 | The commit message should summarize what proj is, specify where 57 | proj-1.2.tar.gz came from, and give its SHA-256 hash. 58 | 59 | 6. In the main repository, create a vendor branch and release tag: 60 | 61 | % cd /path/to/iventure 62 | % git fetch /tmp/repo master:vendor/proj 63 | % git tag vendor/proj-1.2 vendor/proj 64 | 65 | 7. Merge proj-1.2 into the branch you're working on: 66 | 67 | % git merge vendor/proj-1.2 68 | 69 | 8. Push the vendor branch upstream so others can use it: 70 | 71 | % git push origin vendor/proj 72 | 73 | * To see what version we have most recently merged: 74 | 75 | % git log --merges external/proj 76 | 77 | Note: This requires that every `git merge' involved use the release 78 | tag (vendor/proj-1.2), not the vendor branch (vendor/proj). 79 | Everything else will work if you use the vendor branch, so be careful. 80 | 81 | Note: You can't use `git log --merges external/proj/dist', apparently: 82 | it skips the very first merge. Go figure. 83 | 84 | * To see what local changes there are in a external package: 85 | 86 | % git diff vendor/proj-1.2 HEAD -- ./external/proj 87 | % git show vendor/proj-1.2..HEAD -- ./external/proj/dist 88 | 89 | * To update an existing external package: 90 | 91 | 1. Update prepare.sh and check for changes to copying terms. 92 | 93 | 2. Check out the vendor branch in an empty clone of the repository: 94 | 95 | % git clone --no-checkout -b vendor/proj /path/to/iventure /tmp/repo 96 | 97 | 3. Extract proj-1.3 in external/proj/dist in the clone: 98 | 99 | % cd /tmp/repo 100 | % mkdir -p external/proj 101 | % cd external/proj 102 | % gunzip -c < /tmp/proj-1.3.tar.gz | tar xf - 103 | % mv proj-1.3 dist 104 | 105 | 4. Run the prepare script: 106 | 107 | % (cd dist && /path/to/iventure/external/proj/prepare.sh) 108 | 109 | 4. Commit and tag the update: 110 | 111 | % git add --all dist 112 | % git commit 113 | % git tag vendor/proj-1.3 114 | 115 | 5. In the main repository, update the vendor branch and tag it: 116 | 117 | % cd /path/to/iventure 118 | % git fetch /tmp/repo vendor/proj 119 | % git tag vendor/proj-1.3 vendor/proj 120 | 121 | 6. Finally, merge the new release tag: 122 | 123 | % git merge vendor/proj-1.3 124 | -------------------------------------------------------------------------------- /external/seaborn/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2013, Michael L. Waskom 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the {organization} nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /external/seaborn/README: -------------------------------------------------------------------------------- 1 | seaborn - Statistical data visualization library based on matplotlib 2 | 3 | https://seaborn.pydata.org/ 4 | 5 | We have had trouble with version skew and bugs in seaborn in the 6 | past, but it is relatively small and self-contained, so we commit to 7 | a particular version that we can patch for our needs here. 8 | -------------------------------------------------------------------------------- /external/seaborn/dist/.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | include = seaborn/* 3 | omit = *external* 4 | -------------------------------------------------------------------------------- /external/seaborn/dist/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.sw* 3 | build/ 4 | .ipynb_checkpoints/ 5 | dist/ 6 | seaborn.egg-info/ 7 | .coverage 8 | cover/ 9 | .idea 10 | -------------------------------------------------------------------------------- /external/seaborn/dist/.mailmap: -------------------------------------------------------------------------------- 1 | Michael Waskom mwaskom 2 | Tal Yarkoni 3 | Daniel B. Allan 4 | -------------------------------------------------------------------------------- /external/seaborn/dist/.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | env: 4 | - PYTHON=2.7 DEPS=modern 5 | - PYTHON=2.7 DEPS=minimal 6 | - PYTHON=3.4 DEPS=modern 7 | #- PYTHON=3.5 DEPS=modern 8 | 9 | install: 10 | - conda update conda --yes 11 | - conda create -n testenv --yes pip python=$PYTHON 12 | - conda update conda --yes 13 | - source activate testenv 14 | - if [ ${PYTHON:0:1} == "2" ]; 15 | then conda install --yes imaging; else 16 | pip install pillow; 17 | fi 18 | - conda install --yes --file testing/deps_${DEPS}_${PYTHON}.txt 19 | - conda install ipython-notebook=2 --yes 20 | #- pip install sphinx numpydoc sphinx_bootstrap_theme runipy 21 | #- sudo apt-get install pandoc 22 | - pip install pep8==1.5 # Later versions get stricter... 23 | - pip install https://github.com/dcramer/pyflakes/tarball/master 24 | - pip install . 25 | - cp testing/matplotlibrc . 26 | 27 | before_install: 28 | - sudo apt-get update -yq 29 | - sudo sh -c "echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections" 30 | - sudo apt-get install msttcorefonts -qq 31 | 32 | # http://conda.pydata.org/docs/travis.html#the-travis-yml-file 33 | - wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh 34 | - bash miniconda.sh -b -p $HOME/miniconda 35 | - export PATH="$HOME/miniconda/bin:$PATH" 36 | - hash -r 37 | - conda config --set always_yes yes --set changeps1 no 38 | - conda update -q conda 39 | - conda info -a 40 | 41 | before_script: 42 | - if [ ${PYTHON:0:1} == "2" ]; then 43 | make lint; 44 | fi 45 | #- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then 46 | # cd doc; 47 | # make notebooks html; 48 | # cd ..; 49 | # fi 50 | 51 | script: 52 | - if [ $DEPS == 'modern' ]; 53 | then nosetests --with-doctest; 54 | else nosetests; 55 | fi 56 | -------------------------------------------------------------------------------- /external/seaborn/dist/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to seaborn 2 | ======================= 3 | 4 | General support 5 | --------------- 6 | 7 | General support questions are most at home on [StackOverflow](http://stackoverflow.com/), where they will be seen by more people and are more easily searchable. StackOverflow has a `seaborn` tag, which will bring the question to the attention of people who might be able to answer. 8 | 9 | Reporting bugs 10 | -------------- 11 | 12 | If you think you have encountered a bug in seaborn, please report it on the [Github issue tracker](https://github.com/mwaskom/seaborn/issues/new). It will be most helpful to include a reproducible script with one of the example datasets (accessed through `load_dataset()`) or using some randomly-generated data. 13 | 14 | It is difficult debug any issues without knowing the versions of seaborn and matplotlib you are using, as well as what matplotlib backend you are using to draw the plots, so please include those in your bug report. 15 | 16 | Fixing bugs 17 | ----------- 18 | 19 | If you know how to fix a bug you have encountered or see on the issue tracker, that is very appreciated. Please submit a [pull request](https://help.github.com/articles/using-pull-requests/) on the main seaborn repository with the fix. The presence of a bug implies a lack of coverage in the tests, so when fixing a bug, it is best to add a test that fails before the fix and passes after to make sure it does not reappear. See the section on testing below. But if there is an obvious fix and you're not sure how to write a test, don't let that stop you. 20 | 21 | Documentation issues 22 | -------------------- 23 | 24 | If you see something wrong or confusing in the documentation, please report it with an issue or fix it and open a pull request. 25 | 26 | New features 27 | ------------ 28 | 29 | If you'd like to add a new feature to seaborn, it's best to open an issue to discuss it first. Given the nature of seaborn's goals and approach, it can be hard to write a substantial contribution that is consistent with the rest of the package, and I often lack the bandwidth to help. Also, every new feature represents a new commitment for support. For these reasons, I'm somewhat averse to large feature contributions. Smaller or well-targeted enhancements can be helpful and should be submitted through the normal pull-request workflow. Please include tests for any new features and make sure your changes don't break any existing tests. 30 | 31 | Testing seaborn 32 | --------------- 33 | 34 | Seaborn is primarily tested through a `nose` unit-test suite that interacts with the private objects that actually draw the plots behind the function interface. The basic approach here is to test the numeric information going into and coming out of the matplotlib functions. Currently, there is a general assumption that matplotlib is drawing things properly, and tests are run against the data that ends up in the matplotlib objects but not against the images themselves. See the existing tests for examples of how this works. 35 | 36 | To execute the test suite and doctests, run `make test` in the root source directory. You can also build a test coverage report with `make coverage`. 37 | 38 | The `make lint` command will run `pep8` and `pyflakes` over the codebase to check for style issues. Doing so requires [this](https://github.com/dcramer/pyflakes) fork of pyflakes, which can be installed with `pip install https://github.com/dcramer/pyflakes/tarball/master`. It also currently requires `pep8` 1.5 or older, as the rules got stricter and the codebase has not been updated. This is part of the Travis build, and the build will fail if there are issues, so please do this before submitting a pull request. 39 | -------------------------------------------------------------------------------- /external/seaborn/dist/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2013, Michael L. Waskom 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the {organization} nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /external/seaborn/dist/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md 2 | include CONTRIBUTING.md 3 | include LICENSE 4 | recursive-include licences * 5 | -------------------------------------------------------------------------------- /external/seaborn/dist/Makefile: -------------------------------------------------------------------------------- 1 | export SHELL := /bin/bash 2 | 3 | test: 4 | 5 | cp testing/matplotlibrc . 6 | nosetests --with-doctest 7 | rm matplotlibrc 8 | 9 | 10 | coverage: 11 | 12 | cp testing/matplotlibrc . 13 | nosetests --cover-erase --with-coverage --cover-html --cover-package seaborn 14 | rm matplotlibrc 15 | 16 | lint: 17 | 18 | pyflakes -x W seaborn 19 | pep8 --exclude external seaborn 20 | 21 | hexstrip: 22 | 23 | make -C examples hexstrip 24 | -------------------------------------------------------------------------------- /external/seaborn/dist/README.md: -------------------------------------------------------------------------------- 1 | Seaborn: statistical data visualization 2 | ======================================= 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | Seaborn is a Python visualization library based on matplotlib. It provides a high-level interface for drawing attractive statistical graphics. 28 | 29 | 30 | Documentation 31 | ------------- 32 | 33 | Online documentation is available [here](http://stanford.edu/~mwaskom/software/seaborn/). It includes a high-level tutorial, detailed API documentation, and other useful info. 34 | 35 | There are docs for the development version [here](http://stanford.edu/~mwaskom/software/seaborn-dev/). These should more or less correspond with the github master branch, but they're not built automatically and thus may fall out of sync at times. 36 | 37 | Examples 38 | -------- 39 | 40 | The documentation has an [example gallery](http://stanford.edu/~mwaskom/software/seaborn/examples/index.html) with short scripts showing how to use different parts of the package. 41 | 42 | Citing 43 | ------ 44 | 45 | Seaborn can be cited using a DOI provided through Zenodo: [![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.45133.svg)](http://dx.doi.org/10.5281/zenodo.45133) 46 | 47 | Dependencies 48 | ------------ 49 | 50 | - Python 2.7 or 3.3+ 51 | 52 | ### Mandatory 53 | 54 | - [numpy](http://www.numpy.org/) 55 | 56 | - [scipy](http://www.scipy.org/) 57 | 58 | - [matplotlib](http://matplotlib.sourceforge.net) 59 | 60 | - [pandas](http://pandas.pydata.org/) 61 | 62 | ### Recommended 63 | 64 | - [statsmodels](http://statsmodels.sourceforge.net/) 65 | 66 | 67 | Installation 68 | ------------ 69 | 70 | To install the released version, just do 71 | 72 | pip install seaborn 73 | 74 | You may instead want to use the development version from Github, by running 75 | 76 | pip install git+git://github.com/mwaskom/seaborn.git#egg=seaborn 77 | 78 | 79 | Testing 80 | ------- 81 | 82 | [![Build Status](https://travis-ci.org/mwaskom/seaborn.png?branch=master)](https://travis-ci.org/mwaskom/seaborn) 83 | 84 | To test seaborn, run `make test` in the source directory. This will run the 85 | unit-test and doctest suite (using `nose`). 86 | 87 | Development 88 | ----------- 89 | 90 | https://github.com/mwaskom/seaborn 91 | 92 | Please [submit](https://github.com/mwaskom/seaborn/issues/new) any bugs you encounter to the Github issue tracker. 93 | 94 | License 95 | ------- 96 | 97 | Released under a BSD (3-clause) license 98 | 99 | 100 | Celebrity Endorsements 101 | ---------------------- 102 | 103 | "Those are nice plots" -Hadley Wickham 104 | -------------------------------------------------------------------------------- /external/seaborn/dist/devel_requirements_py2.txt: -------------------------------------------------------------------------------- 1 | ipython>=1.0 2 | sphinx>=1.2 3 | sphinx_bootstrap_theme 4 | numpydoc 5 | PIL 6 | nose 7 | -------------------------------------------------------------------------------- /external/seaborn/dist/devel_requirements_py3.txt: -------------------------------------------------------------------------------- 1 | ipython>=1.0 2 | sphinx>=1.2 3 | sphinx_bootstrap_theme 4 | numpydoc 5 | pillow 6 | nose 7 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/.gitignore: -------------------------------------------------------------------------------- 1 | *_files/ 2 | _build/ 3 | generated/ 4 | examples/ 5 | example_thumbs/ 6 | aesthetics.rst 7 | color_palettes.rst 8 | distributions.rst 9 | regression.rst 10 | categorical.rst 11 | plotting_distributions.rst 12 | dataset_exploration.rst 13 | timeseries_plots.rst 14 | axis_grids.rst 15 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 18 | 19 | help: 20 | @echo "Please use \`make ' where is one of" 21 | @echo " html to make standalone HTML files" 22 | @echo " dirhtml to make HTML files named index.html in directories" 23 | @echo " singlehtml to make a single large HTML file" 24 | @echo " pickle to make pickle files" 25 | @echo " json to make JSON files" 26 | @echo " htmlhelp to make HTML files and a HTML help project" 27 | @echo " qthelp to make HTML files and a qthelp project" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 31 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 32 | @echo " text to make text files" 33 | @echo " man to make manual pages" 34 | @echo " texinfo to make Texinfo files" 35 | @echo " info to make Texinfo files and run them through makeinfo" 36 | @echo " gettext to make PO message catalogs" 37 | @echo " changes to make an overview of all changed/added/deprecated items" 38 | @echo " linkcheck to check all external links for integrity" 39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 40 | 41 | clean: 42 | -rm -rf $(BUILDDIR)/* 43 | -rm -rf examples/* 44 | -rm -rf example_thumbs/* 45 | -rm -rf tutorial/*_files/ 46 | -rm -rf tutorial/*.rst 47 | -rm -rf generated/* 48 | 49 | notebooks: 50 | 51 | make -C tutorial notebooks 52 | 53 | html: 54 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 55 | @echo 56 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 57 | 58 | dirhtml: 59 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 60 | @echo 61 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 62 | 63 | singlehtml: 64 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 65 | @echo 66 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 67 | 68 | pickle: 69 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 70 | @echo 71 | @echo "Build finished; now you can process the pickle files." 72 | 73 | json: 74 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 75 | @echo 76 | @echo "Build finished; now you can process the JSON files." 77 | 78 | htmlhelp: 79 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 80 | @echo 81 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 82 | ".hhp project file in $(BUILDDIR)/htmlhelp." 83 | 84 | qthelp: 85 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 86 | @echo 87 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 88 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 89 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/lyman.qhcp" 90 | @echo "To view the help file:" 91 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/lyman.qhc" 92 | 93 | devhelp: 94 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 95 | @echo 96 | @echo "Build finished." 97 | @echo "To view the help file:" 98 | @echo "# mkdir -p $$HOME/.local/share/devhelp/lyman" 99 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/lyman" 100 | @echo "# devhelp" 101 | 102 | epub: 103 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 104 | @echo 105 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 106 | 107 | latex: 108 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 109 | @echo 110 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 111 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 112 | "(use \`make latexpdf' here to do that automatically)." 113 | 114 | latexpdf: 115 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 116 | @echo "Running LaTeX files through pdflatex..." 117 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 118 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 119 | 120 | text: 121 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 122 | @echo 123 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 124 | 125 | man: 126 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 127 | @echo 128 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 129 | 130 | texinfo: 131 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 132 | @echo 133 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 134 | @echo "Run \`make' in that directory to run these through makeinfo" \ 135 | "(use \`make info' here to do that automatically)." 136 | 137 | info: 138 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 139 | @echo "Running Texinfo files through makeinfo..." 140 | make -C $(BUILDDIR)/texinfo info 141 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 142 | 143 | gettext: 144 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 145 | @echo 146 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 147 | 148 | changes: 149 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 150 | @echo 151 | @echo "The overview file is in $(BUILDDIR)/changes." 152 | 153 | linkcheck: 154 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 155 | @echo 156 | @echo "Link check complete; look for any errors in the above output " \ 157 | "or in $(BUILDDIR)/linkcheck/output.txt." 158 | 159 | doctest: 160 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 161 | @echo "Testing of doctests in the sources finished, look at the " \ 162 | "results in $(BUILDDIR)/doctest/output.txt." 163 | 164 | upload: 165 | rsync -azP $(BUILDDIR)/html/ mwaskom@cardinal.stanford.edu:WWW/software/seaborn 166 | @echo "Uploaded to Stanford webspace" 167 | 168 | upload-dev: 169 | rsync -azP $(BUILDDIR)/html/ mwaskom@cardinal.stanford.edu:WWW/software/seaborn-dev 170 | @echo "Uploaded to Stanford webspace (development page)" 171 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/_static/copybutton.js: -------------------------------------------------------------------------------- 1 | // originally taken from scikit-learn's Sphinx theme 2 | $(document).ready(function() { 3 | /* Add a [>>>] button on the top-right corner of code samples to hide 4 | * the >>> and ... prompts and the output and thus make the code 5 | * copyable. 6 | * Note: This JS snippet was taken from the official python.org 7 | * documentation site.*/ 8 | var div = $('.highlight-python .highlight,' + 9 | '.highlight-python3 .highlight,' + 10 | '.highlight-pycon .highlight') 11 | var pre = div.find('pre'); 12 | 13 | // get the styles from the current theme 14 | pre.parent().parent().css('position', 'relative'); 15 | var hide_text = 'Hide the prompts and output'; 16 | var show_text = 'Show the prompts and output'; 17 | var border_width = pre.css('border-top-width'); 18 | var border_style = pre.css('border-top-style'); 19 | var border_color = pre.css('border-top-color'); 20 | var button_styles = { 21 | 'cursor':'pointer', 'position': 'absolute', 'top': '0', 'right': '0', 22 | 'border-color': border_color, 'border-style': border_style, 23 | 'border-width': border_width, 'color': border_color, 'text-size': '75%', 24 | 'font-family': 'monospace', 'padding-left': '0.2em', 'padding-right': '0.2em' 25 | } 26 | 27 | // create and add the button to all the code blocks that contain >>> 28 | div.each(function(index) { 29 | var jthis = $(this); 30 | if (jthis.find('.gp').length > 0) { 31 | var button = $('>>>'); 32 | button.css(button_styles) 33 | button.attr('title', hide_text); 34 | jthis.prepend(button); 35 | } 36 | // tracebacks (.gt) contain bare text elements that need to be 37 | // wrapped in a span to work with .nextUntil() (see later) 38 | jthis.find('pre:has(.gt)').contents().filter(function() { 39 | return ((this.nodeType == 3) && (this.data.trim().length > 0)); 40 | }).wrap(''); 41 | }); 42 | 43 | // define the behavior of the button when it's clicked 44 | $('.copybutton').toggle( 45 | function() { 46 | var button = $(this); 47 | button.parent().find('.go, .gp, .gt').hide(); 48 | button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden'); 49 | button.css('text-decoration', 'line-through'); 50 | button.attr('title', show_text); 51 | }, 52 | function() { 53 | var button = $(this); 54 | button.parent().find('.go, .gp, .gt').show(); 55 | button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible'); 56 | button.css('text-decoration', 'none'); 57 | button.attr('title', hide_text); 58 | }); 59 | }); 60 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/_static/style.css: -------------------------------------------------------------------------------- 1 | 2 | blockquote p { 3 | font-size: 14px !important; 4 | } 5 | 6 | blockquote { 7 | margin: 0 0 4px !important; 8 | } 9 | 10 | code { 11 | color: #49759c !important; 12 | background-color: #f3f5f9 !important; 13 | } 14 | 15 | .alert-info { 16 | background-color: #adb8cb !important; 17 | border-color: #adb8cb !important; 18 | color: #2c3e50 !important; 19 | } 20 | 21 | .function dt { 22 | padding-top: 150px; 23 | margin-top: -150px; 24 | -webkit-background-clip: content-box; 25 | background-clip: content-box; 26 | } 27 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/api.rst: -------------------------------------------------------------------------------- 1 | .. _api_ref: 2 | 3 | .. currentmodule:: seaborn 4 | 5 | API reference 6 | ============= 7 | 8 | .. _distribution_api: 9 | 10 | Distribution plots 11 | ------------------ 12 | 13 | .. autosummary:: 14 | :toctree: generated/ 15 | 16 | jointplot 17 | pairplot 18 | distplot 19 | kdeplot 20 | rugplot 21 | 22 | .. _regression_api: 23 | 24 | Regression plots 25 | ---------------- 26 | 27 | .. autosummary:: 28 | :toctree: generated/ 29 | 30 | lmplot 31 | regplot 32 | residplot 33 | interactplot 34 | coefplot 35 | 36 | .. _categorical_api: 37 | 38 | Categorical plots 39 | ----------------- 40 | 41 | .. autosummary:: 42 | :toctree: generated/ 43 | 44 | factorplot 45 | boxplot 46 | violinplot 47 | stripplot 48 | swarmplot 49 | pointplot 50 | barplot 51 | countplot 52 | 53 | .. _matrix_api: 54 | 55 | Matrix plots 56 | ------------ 57 | 58 | .. autosummary:: 59 | :toctree: generated/ 60 | 61 | heatmap 62 | clustermap 63 | 64 | Timeseries plots 65 | ---------------- 66 | 67 | .. autosummary:: 68 | :toctree: generated/ 69 | 70 | tsplot 71 | 72 | Miscellaneous plots 73 | ------------------- 74 | 75 | .. autosummary:: 76 | :toctree: generated/ 77 | 78 | palplot 79 | 80 | .. _grid_api: 81 | 82 | Axis grids 83 | ---------- 84 | 85 | .. autosummary:: 86 | :toctree: generated/ 87 | 88 | FacetGrid 89 | PairGrid 90 | JointGrid 91 | 92 | .. _style_api: 93 | 94 | Style frontend 95 | -------------- 96 | 97 | .. autosummary:: 98 | :toctree: generated/ 99 | 100 | set 101 | axes_style 102 | set_style 103 | plotting_context 104 | set_context 105 | set_color_codes 106 | reset_defaults 107 | reset_orig 108 | 109 | .. _palette_api: 110 | 111 | Color palettes 112 | -------------- 113 | 114 | .. autosummary:: 115 | :toctree: generated/ 116 | 117 | set_palette 118 | color_palette 119 | husl_palette 120 | hls_palette 121 | cubehelix_palette 122 | dark_palette 123 | light_palette 124 | diverging_palette 125 | blend_palette 126 | xkcd_palette 127 | crayon_palette 128 | mpl_palette 129 | 130 | Palette widgets 131 | --------------- 132 | 133 | .. autosummary:: 134 | :toctree: generated/ 135 | 136 | choose_colorbrewer_palette 137 | choose_cubehelix_palette 138 | choose_light_palette 139 | choose_dark_palette 140 | choose_diverging_palette 141 | 142 | 143 | Utility functions 144 | ----------------- 145 | 146 | .. autosummary:: 147 | :toctree: generated/ 148 | 149 | despine 150 | desaturate 151 | saturate 152 | set_hls_values 153 | ci_to_errsize 154 | axlabel 155 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/index.rst: -------------------------------------------------------------------------------- 1 | .. raw:: html 2 | 3 | 21 | 22 | Seaborn: statistical data visualization 23 | ======================================= 24 | 25 | .. raw:: html 26 | 27 | 28 |
29 | 63 |
64 | 65 |
66 |
67 |
68 |
69 | 70 | Seaborn is a Python visualization library based on matplotlib. It provides a 71 | high-level interface for drawing attractive statistical graphics. 72 | 73 | For a brief introduction to the ideas behind the package, you can read the 74 | :ref:`introductory notes `. More practical information is on the 75 | :ref:`installation page `. You may also want to browse the 76 | :ref:`example gallery ` to get a sense for what you can do with seaborn and then check out the :ref:`tutorial ` and :ref:`API reference ` to find out how. 77 | 78 | To see the code or report a bug, please visit the `github repository 79 | `_. General support issues are most at home on `stackoverflow `_, where there is a seaborn tag. 80 | 81 | 82 | .. raw:: html 83 | 84 |
85 |
86 |

Documentation

87 | 88 | .. toctree:: 89 | :maxdepth: 1 90 | 91 | introduction 92 | whatsnew 93 | installing 94 | examples/index 95 | api 96 | tutorial 97 | 98 | .. raw:: html 99 | 100 |
101 |
102 |

Features

103 | 104 | * Style functions: :ref:`API ` | :ref:`Tutorial ` 105 | * Color palettes: :ref:`API ` | :ref:`Tutorial ` 106 | * Distribution plots: :ref:`API ` | :ref:`Tutorial ` 107 | * Regression plots: :ref:`API ` | :ref:`Tutorial ` 108 | * Categorical plots: :ref:`API ` | :ref:`Tutorial ` 109 | * Axis grid objects: :ref:`API ` | :ref:`Tutorial ` 110 | 111 | .. raw:: html 112 | 113 |
114 |
115 |
116 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/installing.rst: -------------------------------------------------------------------------------- 1 | .. _installing: 2 | 3 | Installing and getting started 4 | ------------------------------ 5 | 6 | To install the released version of seaborn, you can use ``pip`` (i.e. ``pip 7 | install seaborn``). It's also possible to install the released version using 8 | ``conda`` (i.e. ``conda install seaborn``), although this may lag behind the 9 | version availible from PyPI. 10 | 11 | Alternatively, you can use ``pip`` to install the development version, with the 12 | command ``pip install git+git://github.com/mwaskom/seaborn.git#egg=seaborn``. 13 | Another option would be to to clone the `github repository 14 | `_ and install with ``pip install .`` from 15 | the source directory. Seaborn itself is pure Python, so installation should be 16 | reasonably straightforward. 17 | 18 | When using the development version, you may want to refer to the `development 19 | docs `_. Note that these 20 | are not built automatically and may at times fall out of sync with the actual 21 | master branch on github. 22 | 23 | 24 | Dependencies 25 | ~~~~~~~~~~~~ 26 | 27 | - Python 2.7 or 3.3+ 28 | 29 | Mandatory dependencies 30 | ^^^^^^^^^^^^^^^^^^^^^^ 31 | 32 | - `numpy `__ 33 | 34 | - `scipy `__ 35 | 36 | - `matplotlib `__ 37 | 38 | - `pandas `__ 39 | 40 | Recommended dependencies 41 | ^^^^^^^^^^^^^^^^^^^^^^^^ 42 | 43 | - `statsmodels `__ 44 | 45 | The `pip` installation script will attempt to download the mandatory 46 | dependencies if they do not exist at install-time. 47 | 48 | I recommend using seaborn with the `Anaconda distribution 49 | `_, as this makes it easy to manage 50 | the main dependencies, which otherwise can be difficult to install. 51 | 52 | I attempt to keep seaborn importable and generally functional on the versions 53 | available through the stable Debian channels. There may be cases where some 54 | more advanced features only work with newer versions of these dependencies, 55 | although these should be relatively rare. 56 | 57 | There are also some known bugs on older versions of matplotlib, so you should 58 | in general try to use a modern version. For many use cases, though, older 59 | matplotlibs will work fine. 60 | 61 | Seaborn is tested on the most recent versions offered through ``conda``. 62 | 63 | 64 | Importing seaborn 65 | ~~~~~~~~~~~~~~~~~ 66 | 67 | Seaborn will apply its default style parameters to the global matplotlib style 68 | dictionary when you import it. This will change the look of all plots, 69 | including those created by using matplotlib functions directly. To avoid this 70 | behavior and use the default matplotlib aesthetics (along with any 71 | customization in your ``matplotlibrc``), you can import the ``seaborn.apionly`` 72 | namespace. 73 | 74 | Seaborn has several other pre-packaged styles along with high-level :ref:`tools 75 | ` for managing them, so you should not limit yourself to the 76 | default aesthetics. 77 | 78 | By convention, ``seaborn`` is abbreviated to ``sns`` on import. 79 | 80 | 81 | Testing 82 | ~~~~~~~ 83 | 84 | To test seaborn, run ``make test`` in the root directory of the source 85 | distribution. This runs the unit test suite (which can also be exercised 86 | separately by running ``nosetests``). It also runs the code in the example 87 | notebooks to smoke-test a broader and more realistic range of example usage. 88 | 89 | The full set of tests requires an internet connection to download the example 90 | datasets, but the unit tests should be able to run offline. 91 | 92 | 93 | Bugs 94 | ~~~~ 95 | 96 | Please report any bugs you encounter through the github `issue tracker 97 | `_. It will be most helpful to 98 | include a reproducible example on one of the example datasets (accessed through 99 | :func:`load_dataset`). It is difficult debug any issues without knowing the 100 | versions of seaborn and matplotlib you are using, as well as what matplotlib 101 | backend you are using to draw the plots, so please include those in your bug 102 | report. 103 | 104 | 105 | Known issues 106 | ~~~~~~~~~~~~ 107 | 108 | There is a `bug `_ in the 109 | matplotlib OSX backend that causes unavoidable problems with some of the 110 | seaborn functions (particularly those that draw multi-panel figures). If you 111 | encounter this, you will want to try a `different backend 112 | `_. In particular, this bug affects any multi-panel figure that internally calls the matplotlib ``tight_layout`` function. 113 | 114 | An unfortunate consequence of how the matplotlib marker styles work is that 115 | line-art markers (e.g. ``"+"``) or markers with ``facecolor`` set to ``"none"`` 116 | will be invisible when the default seaborn style is in effect. This can be 117 | changed by using a different ``markeredgewidth`` (aliased to ``mew``) either in 118 | the function call or globally in the `rcParams`. 119 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/introduction.rst: -------------------------------------------------------------------------------- 1 | .. _introduction: 2 | 3 | An introduction to seaborn 4 | ========================== 5 | 6 | Seaborn is a library for making attractive and informative statistical graphics 7 | in Python. It is built on top of `matplotlib `_ and 8 | tightly integrated with the `PyData `_ stack, including 9 | support for `numpy `_ and `pandas 10 | `_ data structures and statistical routines from 11 | `scipy `_ and `statsmodels 12 | `_. 13 | 14 | Some of the features that seaborn offers are 15 | 16 | - Several :ref:`built-in themes ` that improve on the default matplotlib aesthetics 17 | - Tools for choosing :ref:`color palettes ` to make beautiful plots that reveal patterns in your data 18 | - Functions for visualizing :ref:`univariate ` and :ref:`bivariate ` distributions or for :ref:`comparing ` them between subsets of data 19 | - Tools that fit and visualize :ref:`linear regression ` models for different kinds of :ref:`independent ` and :ref:`dependent ` variables 20 | - Functions that visualize :ref:`matrices of data ` and use clustering algorithms to :ref:`discover structure ` in those matrices 21 | - A function to plot :ref:`statistical timeseries ` data with flexible estimation and :ref:`representation ` of uncertainty around the estimate 22 | - High-level abstractions for structuring :ref:`grids of plots ` that let you easily build :ref:`complex ` visualizations 23 | 24 | Seaborn aims to make visualization a central part of exploring and 25 | understanding data. The plotting functions operate on dataframes and arrays 26 | containing a whole dataset and internally perform the necessary aggregation and 27 | statistical model-fitting to produce informative plots. If matplotlib "tries to 28 | make easy things easy and hard things possible", seaborn tries to make a 29 | well-defined set of hard things easy too. 30 | 31 | The plotting functions try to do something useful when called with a minimal 32 | set of arguments, and they expose a number of customizable options through 33 | additional parameters. Some of the functions plot directly into a matplotlib 34 | axes object, while others operate on an entire figure and produce plots with 35 | several panels. In the latter case, the plot is drawn using a Grid object that 36 | links the structure of the figure to the structure of the dataset in an 37 | abstract way. 38 | 39 | Because seaborn uses matplotlib, the graphics can be further tweaked using 40 | matplotlib tools and rendered with any of the matplotlib backends to generate 41 | publication-quality figures. Seaborn can also be used to target web-based 42 | graphics through the `mpld3 `_ and `Bokeh 43 | `_ libraries. 44 | 45 | Seaborn should be thought of as a complement to matplotlib, not a replacement 46 | for it. When using seaborn, it is likely that you will often invoke matplotlib 47 | functions directly to draw simpler plots already available through the 48 | ``pyplot`` namespace. Further, while the seaborn functions aim to make plots 49 | that are reasonably "production ready" (including extracting semantic 50 | information from Pandas objects to add informative labels), full customization 51 | of the figures will require a sophisticated understanding of matplotlib objects. 52 | 53 | For more detailed information and copious examples of the syntax and resulting 54 | plots, you can check out the :ref:`example gallery `, 55 | :ref:`tutorial ` or :ref:`API reference `. 56 | 57 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/releases/v0.2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | v0.2.0 (December 2013) 3 | ---------------------- 4 | 5 | This is a major release from 0.1 with a number of API changes, enhancements, 6 | and bug fixes. 7 | 8 | Highlights include an overhaul of timeseries plotting to work intelligently 9 | with dataframes, the new function ``interactplot()`` for visualizing continuous 10 | interactions, bivariate kernel density estimates in ``kdeplot()``, and 11 | significant improvements to color palette handling. 12 | 13 | Version 0.2 also introduces experimental support for Python 3. 14 | 15 | In addition to the library enhancements, the documentation has been 16 | substantially rewritten to reflect the new features and improve the 17 | presentation of the ideas behind the package. 18 | 19 | API changes 20 | ~~~~~~~~~~~ 21 | 22 | - The ``tsplot()`` function was rewritten to accept data in a long-form 23 | ``DataFrame`` and to plot different traces by condition. This introduced a 24 | relatively minor but unavoidable API change, where instead of doing 25 | ``sns.tsplot(time, heights)``, you now must do ``sns.tsplot(heights, 26 | time=time)`` (the ``time`` parameter is now optional, for quicker 27 | specification of simple plots). Additionally, the ``"obs_traces"`` and 28 | ``"obs_points"`` error styles in ``tsplot()`` have been renamed to 29 | ``"unit_traces"`` and ``"unit_points"``, respectively. 30 | 31 | - Functions that fit kernel density estimates (``kdeplot()`` and 32 | ``violinplot()``) now use ``statsmodels`` instead of ``scipy``, and the 33 | parameters that influence the density estimate have changed accordingly. This 34 | allows for increased flexibility in specifying the bandwidth and kernel, and 35 | smarter choices for defining the range of the support. Default options should 36 | produce plots that are very close to the old defaults. 37 | 38 | - The ``kdeplot()`` function now takes a second positional argument of data for 39 | drawing bivariate densities. 40 | 41 | - The ``violin()`` function has been changed to ``violinplot()``, for consistency. 42 | In 0.2, ``violin`` will still work, but it will fire a ``UserWarning``. 43 | 44 | New plotting functions 45 | ~~~~~~~~~~~~~~~~~~~~~~ 46 | 47 | - The ``interactplot()`` function draws a contour plot for an interactive 48 | linear model (i.e., the contour shows ``y-hat`` from the model ``y ~ x1 * 49 | x2``) over a scatterplot between the two predictor variables. This plot 50 | should aid the understanding of an interaction between two continuous 51 | variables. 52 | 53 | - The ``kdeplot()`` function can now draw a bivariate density estimate as a 54 | contour plot if provided with two-dimensional input data. 55 | 56 | - The ``palplot()`` function provides a simple grid-based visualization of a 57 | color palette. 58 | 59 | Other changes 60 | ~~~~~~~~~~~~~ 61 | 62 | Plotting functions 63 | ^^^^^^^^^^^^^^^^^^ 64 | 65 | - The ``corrplot()`` function can be drawn without the correlation coefficient 66 | annotation and with variable names on the side of the plot to work with large 67 | datasets. 68 | 69 | - Additionally, ``corrplot()`` sets the color palette intelligently based on 70 | the direction of the specified test. 71 | 72 | - The ``distplot()`` histogram uses a reference rule to choose the bin size if it 73 | is not provided. 74 | 75 | - Added the ``x_bins`` option in ``lmplot()`` for binning a continuous 76 | predictor variable, allowing for clearer trends with many datapoints. 77 | 78 | - Enhanced support for labeling plot elements and axes based on ``name`` 79 | attributes in several distribution plot functions and ``tsplot()`` for 80 | smarter Pandas integration. 81 | 82 | - Scatter points in ``lmplot()`` are slightly transparent so it is easy to see 83 | where observations overlap. 84 | 85 | - Added the ``order`` parameter to ``boxplot()`` and ``violinplot()`` to 86 | control the order of the bins when using a Pandas object. 87 | 88 | - When an ``ax`` argument is not provided to a plotting function, it grabs the 89 | currently active axis instead of drawing a new one. 90 | 91 | Color palettes 92 | ^^^^^^^^^^^^^^ 93 | 94 | - Added the ``dark_palette()`` and ``blend_palette()`` for on-the-fly creation 95 | of blended color palettes. 96 | 97 | - The color palette machinery is now intelligent about qualitative ColorBrewer 98 | palettes (``Set1``, ``Paired``, etc.), which are properly treated as discrete. 99 | 100 | - Seaborn color palettes (``deep``, ``muted``, etc.) have been standardized in 101 | terms of basic hue sequence, and all palettes now have 6 colors. 102 | 103 | - Introduced ``{mpl_palette}_d`` palettes, which make a palette with the basic 104 | color scheme of the source palette, but with a sequential blend from dark 105 | instead of light colors for use with line/scatter/contour plots. 106 | 107 | - Added the ``palette_context()`` function for blockwise color palettes 108 | controlled by a ``with`` statement. 109 | 110 | Plot styling 111 | ^^^^^^^^^^^^ 112 | 113 | - Added the ``despine()`` function for easily removing plot spines. 114 | 115 | - A new plot style, ``"ticks"`` has been added. 116 | 117 | - Tick labels are padded a bit farther from the axis in all styles, avoiding 118 | collisions at (0, 0). 119 | 120 | General package issues 121 | ^^^^^^^^^^^^^^^^^^^^^^ 122 | 123 | - Reorganized the package by breaking up the monolithic ``plotobjs`` module 124 | into smaller modules grouped by general objective of the constituent plots. 125 | 126 | - Removed the ``scikits-learn`` dependency in ``moss``. 127 | 128 | - Installing with ``pip`` should automatically install most missing dependencies. 129 | 130 | - The example notebooks are now used as an automated test suite. 131 | 132 | Bug fixes 133 | ~~~~~~~~~ 134 | 135 | - Fixed a bug where labels did not match data for ``boxplot()`` and ``violinplot()`` 136 | when using a groupby. 137 | 138 | - Fixed a bug in the ``desaturate()`` function. 139 | 140 | - Fixed a bug in the ``coefplot()`` figure size calculation. 141 | 142 | - Fixed a bug where ``regplot()`` choked on list input. 143 | 144 | - Fixed buggy behavior when drawing horizontal boxplots. 145 | 146 | - Specifying bins for the ``distplot()`` histogram now works. 147 | 148 | - Fixed a bug where ``kdeplot()`` would reset the axis height and cut off 149 | existing data. 150 | 151 | - All axis styling has been moved out of the top-level ``seaborn.set()`` 152 | function, so context or color palette can be cleanly changed. 153 | 154 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/releases/v0.2.1.txt: -------------------------------------------------------------------------------- 1 | 2 | v0.2.1 (December 2013) 3 | ---------------------- 4 | 5 | This is a bugfix release, with no new features. 6 | 7 | Bug fixes 8 | ~~~~~~~~~ 9 | 10 | - Changed the mechanics of ``violinplot()`` and ``boxplot()`` when using a 11 | ``Series`` object as data and performing a ``groupby`` to assign data to 12 | bins to address a problem that arises in Pandas 0.13. 13 | 14 | - Additionally fixed the ``groupby`` code to work with all styles of group 15 | specification (specifically, using a dictionary or a function now works). 16 | 17 | - Fixed a bug where artifacts from the kde fitting could undershoot and create 18 | a plot where the density axis starts below 0. 19 | 20 | - Ensured that data used for kde fitting is double-typed to avoid a low-level 21 | statsmodels error. 22 | 23 | - Changed the implementation of the histogram bin-width reference rule to 24 | take a ceiling of the estimated number of bins. 25 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/releases/v0.3.0.txt: -------------------------------------------------------------------------------- 1 | 2 | v0.3.0 (March 2014) 3 | ------------------- 4 | 5 | This is a major release from 0.2 with a number of enhancements to the plotting capabilities and styles. Highlights include :class:`FacetGrid`, :func:`factorplot`, :func:`jointplot`, and an overhaul to :ref:`style management `. There is also lots of new documentation, including an :ref:`example gallery ` and reorganized :ref:`tutorial `. 6 | 7 | New plotting functions 8 | ~~~~~~~~~~~~~~~~~~~~~~ 9 | 10 | - The :class:`FacetGrid` class adds a new form of functionality to seaborn, providing a way to abstractly structure a grid of plots corresponding to subsets of a dataset. It can be used with a wide variety of plotting functions (including most of the matplotlib and seaborn APIs. See the :ref:`tutorial ` for more information. 11 | 12 | - Version 0.3 introduces the :func:`factorplot` function, which is similar in spirit to :func:`lmplot` but intended for use when the main independent variable is categorical instead of quantitative. :func:`factorplot` can draw a plot in either a point or bar representation using the corresponding Axes-level functions :func:`pointplot` and :func:`barplot` (which are also new). Additionally, the :func:`factorplot` function can be used to draw box plots on a faceted grid. For examples of how to use these functions, you can refer to the :ref:`tutorial `. 13 | 14 | - Another new function is :func:`jointplot`, which is built using the new :class:`JointGrid` object. :func:`jointplot` generalizes the behavior of :func:`regplot` in previous versions of seaborn (:func:`regplot` has changed somewhat in 0.3; see below for details) by drawing a bivariate plot of the relationship between two variables with their marginal distributions drawn on the side of the plot. With :func:`jointplot`, you can draw a scatterplot or :ref:`regression plot ` as before, but you can now also draw bivariate kernel densities or hexbin plots with appropriate univariate graphs for the marginal distributions. Additionally, it's easy to use :class:`JointGrid` directly to build up more complex plots when the default methods offered by :func:`jointplot` are not suitable for your visualization problem. The :ref:`tutorial ` for :class:`JointGrid` has more examples of how this object can be useful. 15 | 16 | - The :func:`residplot` function complements :func:`regplot` and can be quickly used to diagnose problems with a linear model by calculating and plotting the residuals of a simple regression. There is also a ``"resid"`` kind for :func:`jointplot`. 17 | 18 | API changes 19 | ~~~~~~~~~~~ 20 | 21 | - The most noticeable change will be that :func:`regplot` no longer produces a multi-component plot with distributions in marginal axes. Instead. :func:`regplot` is now an "Axes-level" function that can be plotted into any existing figure on a specific set of axes. :func:`regplot` and :func:`lmplot` have also been unified (the latter uses the former behind the scenes), so all options for how to fit and represent the regression model can be used for both functions. To :ref:`get the old behavior ` of :func:`regplot`, use :func:`jointplot` with ``kind="reg"``. 22 | 23 | - As noted above, :func:`lmplot` has been rewritten to exploit the :class:`FacetGrid` machinery. This involves a few changes. The ``color`` keyword argument has been replaced with ``hue``, for better consistency across the package. The ``hue`` parameter will always take a variable *name*, while ``color`` will take a color name or (in some cases) a palette. The :func:`lmplot` function now returns the :class:`FacetGrid` used to draw the plot instance. 24 | 25 | - The functions that interact with matplotlib rc parameters have been updated and standardized. There are now three pairs of functions, :func:`axes_style` and :func:`set_style`, :func:`plotting_context` and :func:`set_context`, and :func:`color_palette` and :func:`set_palette`. In each case, the pairs take the exact same arguments. The first function defines and returns the parameters, and the second sets the matplotlib defaults. Additionally, the first function in each pair can be used in a ``with`` statement to temporarily change the defaults. Both the style and context functions also now accept a dictionary of matplotlib rc parameters to override the seaborn defaults, and :func:`set` now also takes a dictionary to update any of the matplotlib defaults. See the :ref:`tutorial ` for more information. 26 | 27 | - The ``nogrid`` style has been deprecated and changed to ``white`` for more uniformity (i.e. there are now ``darkgrid``, ``dark``, ``whitegrid``, and ``white`` styles). 28 | 29 | 30 | Other changes 31 | ~~~~~~~~~~~~~ 32 | 33 | Using the package 34 | ^^^^^^^^^^^^^^^^^ 35 | 36 | - If you want to use plotting functions provided by the package without setting the matplotlib style to a seaborn theme, you can now do ``import seaborn.apionly as sns`` or ``from seaborn.apionly import lmplot``, etc. This is using the (also new) :func:`reset_orig` function, which returns the rc parameters to what they are at matplotlib import time — i.e. they will respect any custom `matplotlibrc` settings on top of the matplotlib defaults. 37 | 38 | - The dependency load of the package has been reduced. It can now be installed and used with only ``numpy``, ``scipy``, ``matplotlib``, and ``pandas``. Although ``statsmodels`` is still recommended for full functionality, it is not required. 39 | 40 | Plotting functions 41 | ^^^^^^^^^^^^^^^^^^ 42 | 43 | - :func:`lmplot` (and :func:`regplot`) have two new options for fitting regression models: ``lowess`` and ``robust``. The former fits a nonparametric smoother, while the latter fits a regression using methods that are less sensitive to outliers. 44 | 45 | - The regression uncertainty in :func:`lmplot` and :func:`regplot` is now estimated with fewer bootstrap iterations, so plotting should be faster. 46 | 47 | - The univariate :func:`kdeplot` can now be drawn as a *cumulative* density plot. 48 | 49 | - Changed :func:`interactplot` to use a robust calculation of the data range when finding default limits for the contour colormap to work better when there are outliers in the data. 50 | 51 | Style 52 | ^^^^^ 53 | 54 | - There is a new style, ``dark``, which shares most features with ``darkgrid`` but does not draw a grid by default. 55 | 56 | - There is a new function, :func:`offset_spines`, and a corresponding option in :func:`despine` called ``trim``. Together, these can be used to make plots where the axis spines are offset from the main part of the figure and limited within the range of the ticks. This is recommended for use with the ``ticks`` style. 57 | 58 | - Other aspects of the seaborn styles have been tweaked for more attractive plots. 59 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/releases/v0.3.1.txt: -------------------------------------------------------------------------------- 1 | 2 | v0.3.1 (April 2014) 3 | ------------------- 4 | 5 | This is a minor release from 0.3 with fixes for several bugs. 6 | 7 | Plotting functions 8 | ~~~~~~~~~~~~~~~~~~ 9 | 10 | - The size of the points in :func:`pointplot` and :func:`factorplot` are now scaled with the linewidth for better aesthetics across different plotting contexts. 11 | 12 | - The :func:`pointplot` glyphs for different levels of the hue variable are drawn at different z-orders so that they appear uniform. 13 | 14 | Bug Fixes 15 | ~~~~~~~~~ 16 | 17 | - Fixed a bug in :class:`FacetGrid` (and thus affecting lmplot and factorplot) that appeared when ``col_wrap`` was used with a number of facets that did not evenly divide into the column width. 18 | 19 | - Fixed an issue where the support for kernel density estimates was sometimes computed incorrectly. 20 | 21 | - Fixed a problem where ``hue`` variable levels that were not strings were missing in :class:`FacetGrid` legends. 22 | 23 | - When passing a color palette list in a ``with`` statement, the entire palette is now used instead of the first six colors. 24 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/releases/v0.4.0.txt: -------------------------------------------------------------------------------- 1 | 2 | v0.4.0 (September 2014) 3 | ----------------------- 4 | 5 | This is a major release from 0.3. Highlights include new approaches for :ref:`quick, high-level dataset exploration ` (along with a more :ref:`flexible interface `) and easy creation of :ref:`perceptually-appropriate color palettes ` using the cubehelix system. Along with these additions, there are a number of smaller changes that make visualizing data with seaborn easier and more powerful. 6 | 7 | Plotting functions 8 | ~~~~~~~~~~~~~~~~~~ 9 | 10 | - A new object, :class:`PairGrid`, and a corresponding function :func:`pairplot`, for drawing grids of pairwise relationships in a dataset. This style of plot is sometimes called a "scatterplot matrix", but the representation of the data in :class:`PairGrid` is flexible and many styles other than scatterplots can be used. See the :ref:`docs ` for more information. **Note:** due to a bug in older versions of matplotlib, you will have best results if you use these functions with matplotlib 1.4 or later. 11 | 12 | - The rules for choosing default color palettes when variables are mapped to different colors have been unified (and thus changed in some cases). Now when no specific palette is requested, the current global color palette will be used, unless the number of variables to be mapped exceeds the number of unique colors in the palette, in which case the ``"husl"`` palette will be used to avoid cycling. 13 | 14 | - Added a keyword argument ``hist_norm`` to :func:`distplot`. When a :func:`distplot` is now drawn without a KDE or parametric density, the histogram is drawn as counts instead of a density. This can be overridden by by setting ``hist_norm`` to ``True``. 15 | 16 | - When using :class:`FacetGrid` with a ``hue`` variable, the legend is no longer drawn by default when you call :meth:`FacetGrid.map`. Instead, you have to call :meth:`FacetGrid.add_legend` manually. This should make it easier to layer multiple plots onto the grid without having duplicated legends. 17 | 18 | - Made some changes to :func:`factorplot` so that it behaves better when not all levels of the ``x`` variable are represented in each facet. 19 | 20 | - Added the ``logx`` option to :func:`regplot` for fitting the regression in log space. 21 | 22 | - When :func:`violinplot` encounters a bin with only a single observation, it will now plot a horizontal line at that value instead of erroring out. 23 | 24 | Style and color palettes 25 | ~~~~~~~~~~~~~~~~~~~~~~~~ 26 | 27 | - Added the :func:`cubehelix_palette` function for generating sequential palettes from the cubehelix system. See the :ref:`palette docs ` for more information on how these palettes can be used. There is also the :func:`choose_cubehelix` which will launch an interactive app to select cubehelix parameters in the notebook. 28 | 29 | - Added the :func:`xkcd_palette` and the ``xkcd_rgb`` dictionary so that colors :ref:`can be specified ` with names from the `xkcd color survey `_. 30 | 31 | - Added the ``font_scale`` option to :func:`plotting_context`, :func:`set_context`, and :func:`set`. ``font_scale`` can independently increase or decrease the size of the font elements in the plot. 32 | 33 | - Font-handling should work better on systems without Arial installed. This is accomplished by adding the ``font.sans-serif`` field to the ``axes_style`` definition with Arial and Liberation Sans prepended to matplotlib defaults. The font family can also be set through the ``font`` keyword argument in :func:`set`. Due to matplotlib bugs, this might not work as expected on matplotlib 1.3. 34 | 35 | - The :func:`despine` function gets a new keyword argument ``offset``, which replaces the deprecated :func:`offset_spines` function. You no longer need to offset the spines before plotting data. 36 | 37 | - Added a default value for ``pdf.fonttype`` so that text in PDFs is editable in Adobe Illustrator. 38 | 39 | 40 | Other API Changes 41 | ~~~~~~~~~~~~~~~~~ 42 | 43 | - Removed the deprecated ``set_color_palette`` and ``palette_context`` functions. These were replaced in version 0.3 by the :func:`set_palette` function and ability to use :func:`color_palette` directly in a ``with`` statement. 44 | 45 | - Removed the ability to specify a ``nogrid`` style, which was renamed to ``white`` in 0.3. 46 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/releases/v0.5.0.txt: -------------------------------------------------------------------------------- 1 | 2 | v0.5.0 (November 2014) 3 | -------------------------- 4 | 5 | This is a major release from 0.4. Highlights include new functions for :ref:`plotting heatmaps `, possibly while :ref:`applying clustering algorithms ` to discover structured relationships. These functions are complemented by new custom colormap functions and a full set of IPython widgets that allow interactive selection of colormap parameters. The :ref:`palette tutorial ` has been rewritten to cover these new tools and more generally provide guidance on how to use color in visualizations. There are also a number of smaller changes and bugfixes. 6 | 7 | Plotting functions 8 | ~~~~~~~~~~~~~~~~~~ 9 | 10 | - Added the :func:`heatmap` function for visualizing a matrix of data by color-encoding the values. See the :ref:`docs ` for more information. 11 | 12 | - Added the :func:`clustermap` function for clustering and visualizing a matrix of data, with options to label individual rows and columns by colors. See the :ref:`docs ` for more information. This work was lead by Olga Botvinnik. 13 | 14 | - :func:`lmplot` and :func:`pairplot` get a new keyword argument, ``markers``. This can be a single kind of marker or a list of different markers for each level of the ``hue`` variable. Using different markers for different hues should let plots be more comprehensible when reproduced to black-and-white (i.e. when printed). See the `github pull request `_ for examples. 15 | 16 | - More generally, there is a new keyword argument in :class:`FacetGrid` and :class:`PairGrid`, ``hue_kws``. This similarly lets plot aesthetics vary across the levels of the hue variable, but more flexibily. ``hue_kws`` should be a dictionary that maps the name of keyword arguments to lists of values that are as long as the number of levels of the hue variable. 17 | 18 | - The argument ``subplot_kws`` has been added to ``FacetGrid``. This allows for faceted plots with custom projections, including `maps with Cartopy `_. 19 | 20 | Color palettes 21 | ~~~~~~~~~~~~~~ 22 | 23 | - Added two new functions to create custom color palettes. For sequential palettes, you can use the :func:`light_palette` function, which takes a seed color and creates a ramp from a very light, desaturated variant of it. For diverging palettes, you can use the :func:`diverging_palette` function to create a balanced ramp between two endpoints to a light or dark midpoint. See the :ref:`palette tutorial ` for more information. 24 | 25 | - Added the ability to specify the seed color for :func:`light_palette` and :func:`dark_palette` as a tuple of ``husl`` or ``hls`` space values or as a named ``xkcd`` color. The interpretation of the seed color is now provided by the new ``input`` parameter to these functions. 26 | 27 | - Added several new interactive palette widgets: :func:`choose_colorbrewer_palette`, :func:`choose_light_palette`, :func:`choose_dark_palette`, and :func:`choose_diverging_palette`. For consistency, renamed the cubehelix widget to :func:`choose_cubehelix_palette` (and fixed a bug where the cubehelix palette was reversed). These functions also now return either a color palette list or a matplotlib colormap when called, and that object will be live-updated as you play with the widget. This should make it easy to iterate over a plot until you find a good representation for the data. See the `Github pull request `_ or `this notebook (download it to use the widgets) `_ for more information. 28 | 29 | - Overhauled the color :ref:`palette tutorial ` to organize the discussion by class of color palette and provide more motivation behind the various choices one might make when choosing colors for their data. 30 | 31 | Bug fixes 32 | ~~~~~~~~~ 33 | - Fixed a bug in :class:`PairGrid` that gave incorrect results (or a crash) when the input DataFrame has a non-default index. 34 | 35 | - Fixed a bug in :class:`PairGrid` where passing columns with a date-like datatype raised an exception. 36 | 37 | - Fixed a bug where :func:`lmplot` would show a legend when the hue variable was also used on either the rows or columns (making the legend redundant). 38 | 39 | - Worked around a matplotlib bug that was forcing outliers in :func:`boxplot` to appear as blue. 40 | 41 | - :func:`kdeplot` now accepts pandas Series for the ``data`` and ``data2`` arguments. 42 | 43 | - Using a non-default correlation method in :func:`corrplot` now implies ``sig_stars=False`` as the permutation test used to significance values for the correlations uses a pearson metric. 44 | 45 | - Removed ``pdf.fonttype`` from the style definitions, as the value used in version 0.4 resulted in very large PDF files. 46 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/releases/v0.5.1.txt: -------------------------------------------------------------------------------- 1 | 2 | v0.5.1 (November 2014) 3 | ---------------------- 4 | 5 | This is a bugfix release that includes a workaround for an issue in matplotlib 1.4.2 and fixes for two bugs in functions that were new in 0.5.0. 6 | 7 | - Implemented a workaround for a bug in matplotlib 1.4.2 that prevented point markers from being drawn when the seaborn styles had been set. See this `github issue `_ for more information. 8 | 9 | - Fixed a bug in :func:`heatmap` where the mask was vertically reversed relative to the data. 10 | 11 | - Fixed a bug in :func:`clustermap` when using nested lists of side colors. 12 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/releases/v0.7.0.txt: -------------------------------------------------------------------------------- 1 | 2 | v0.7.0 (January 2016) 3 | --------------------- 4 | 5 | This is a major release from 0.6. The main new feature is :func:`swarmplot` which implements the beeswarm approach for drawing categorical scatterplots. There are also some performance improvements, bug fixes, and updates for compatibility with new versions of dependencies. 6 | 7 | - Added the :func:`swarmplot` function, which draws beeswarm plots. These are categorical scatterplots, similar to those produced by :func:`stripplot`, but position of the points on the categorical axis is chosen to avoid overlapping points. See the :ref:`categorical plot tutorial ` for more information. 8 | 9 | - Changed some of the :func:`stripplot` defaults to be closer to :func:`swarmplot`. Points are now somewhat smaller, have no outlines, and are not split by default when using ``hue``. These settings remain customizable through function parameters. 10 | 11 | - Added an additional rule when determining category order in categorical plots. Now, when numeric variables are used in a categorical role, the default behavior is to sort the unique levels of the variable (i.e they will be in proper numerical order). This can still be overridden by the appropriate ``{*_}order`` parameter, and variables with a ``category`` datatype will still follow the category order even if the levels are strictly numerical. 12 | 13 | - Changed how :func:`stripplot` draws points when using ``hue`` nesting with ``split=False`` so that the different ``hue`` levels are not drawn strictly on top of each other. 14 | 15 | - Improve performance for large dendrograms in :func:`clustermap`. 16 | 17 | - Added ``font.size`` to the plotting context definition so that the default output from ``plt.text`` will be scaled appropriately. 18 | 19 | - Fixed a bug in :func:`clustermap` when ``fastcluster`` is not installed. 20 | 21 | - Fixed a bug in the zscore calculation in :func:`clustermap`. 22 | 23 | - Fixed a bug in :func:`distplot` where sometimes the default number of bins would not be an integer. 24 | 25 | - Fixed a bug in :func:`stripplot` where a legend item would not appear for a ``hue`` level if there were no observations in the first group of points. 26 | 27 | - Heatmap colorbars are now rasterized for better performance in vector plots. 28 | 29 | - Added workarounds for some matplotlib boxplot issues, such as strange colors of outlier points. 30 | 31 | - Added workarounds for an issue where violinplot edges would be missing or have random colors. 32 | 33 | - Added a workaround for an issue where only one :func:`heatmap` cell would be annotated on some matplotlib backends. 34 | 35 | - Fixed a bug on newer versions of matplotlib where a colormap would be erroneously applied to scatterplots with only three observations. 36 | 37 | - Updated seaborn for compatibility with matplotlib 1.5. 38 | 39 | - Added compatibility for various IPython (and Jupyter) versions in functions that use widgets. 40 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/releases/v0.7.1.txt: -------------------------------------------------------------------------------- 1 | 2 | v0.7.1 (June 2016) 3 | ------------------- 4 | 5 | - Added the ability to put "caps" on the error bars that are drawn by :func:`barplot` or :func:`pointplot` (and, by extension, :func:`factorplot`). Additionally, the line width of the error bars can now be controlled. These changes involve the new parameters ``capsize`` and ``errwidth``. See the `github pull request `_ for examples of usage. 6 | 7 | - Improved the row and column colors display in :func:`clustermap`. It is now possible to pass Pandas objects for these elements and, when possible, the semantic information in the Pandas objects will be used to add labels to the plot. When Pandas objects are used, the color data is matched against the main heatmap based on the index, not on position. This is more accurate, but it may lead to different results if current code assumed positional matching. 8 | 9 | - Improved the luminance calculation that determines the annotation color in :func:`heatmap`. 10 | 11 | - The ``annot`` parameter of :func:`heatmap` now accepts a rectangular dataset in addition to a boolean value. If a dataset is passed, its values will be used for the annotations, while the main dataset will be used for the heatmap cell colors. 12 | 13 | - Fixed a bug in :class:`FacetGrid` that appeared when using ``col_wrap`` with missing ``col`` levels. 14 | 15 | - Made it possible to pass a tick locator object to the :func:`heatmap` colorbar. 16 | 17 | - Made it possible to use different styles (e.g., step) for :class:`PairGrid` histograms when there are multiple hue levels. 18 | 19 | - Fixed a bug in scipy-based univariate kernel density bandwidth calculation. 20 | 21 | - The :func:`reset_orig` function (and, by extension, importing ``seaborn.apionly``) resets matplotlib rcParams to their values at the time seaborn itself was imported, which should work better with rcParams changed by the jupyter notebook backend. 22 | 23 | - Removed some objects from the top-level ``seaborn`` namespace. 24 | 25 | - Improved unicode compatibility in :class:`FacetGrid`. 26 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/sphinxext/ipython_console_highlighting.py: -------------------------------------------------------------------------------- 1 | """reST directive for syntax-highlighting ipython interactive sessions. 2 | 3 | XXX - See what improvements can be made based on the new (as of Sept 2009) 4 | 'pycon' lexer for the python console. At the very least it will give better 5 | highlighted tracebacks. 6 | """ 7 | 8 | #----------------------------------------------------------------------------- 9 | # Needed modules 10 | 11 | # Standard library 12 | import re 13 | 14 | # Third party 15 | from pygments.lexer import Lexer, do_insertions 16 | from pygments.lexers.agile import (PythonConsoleLexer, PythonLexer, 17 | PythonTracebackLexer) 18 | from pygments.token import Comment, Generic 19 | 20 | from sphinx import highlighting 21 | 22 | #----------------------------------------------------------------------------- 23 | # Global constants 24 | line_re = re.compile('.*?\n') 25 | 26 | #----------------------------------------------------------------------------- 27 | # Code begins - classes and functions 28 | 29 | 30 | class IPythonConsoleLexer(Lexer): 31 | 32 | """ 33 | For IPython console output or doctests, such as: 34 | 35 | .. sourcecode:: ipython 36 | 37 | In [1]: a = 'foo' 38 | 39 | In [2]: a 40 | Out[2]: 'foo' 41 | 42 | In [3]: print(a) 43 | foo 44 | 45 | In [4]: 1 / 0 46 | 47 | Notes: 48 | 49 | - Tracebacks are not currently supported. 50 | 51 | - It assumes the default IPython prompts, not customized ones. 52 | """ 53 | 54 | name = 'IPython console session' 55 | aliases = ['ipython'] 56 | mimetypes = ['text/x-ipython-console'] 57 | input_prompt = re.compile("(In \[[0-9]+\]: )|( \.\.\.+:)") 58 | output_prompt = re.compile("(Out\[[0-9]+\]: )|( \.\.\.+:)") 59 | continue_prompt = re.compile(" \.\.\.+:") 60 | tb_start = re.compile("\-+") 61 | 62 | def get_tokens_unprocessed(self, text): 63 | pylexer = PythonLexer(**self.options) 64 | tblexer = PythonTracebackLexer(**self.options) 65 | 66 | curcode = '' 67 | insertions = [] 68 | for match in line_re.finditer(text): 69 | line = match.group() 70 | input_prompt = self.input_prompt.match(line) 71 | continue_prompt = self.continue_prompt.match(line.rstrip()) 72 | output_prompt = self.output_prompt.match(line) 73 | if line.startswith("#"): 74 | insertions.append((len(curcode), 75 | [(0, Comment, line)])) 76 | elif input_prompt is not None: 77 | insertions.append((len(curcode), 78 | [(0, Generic.Prompt, input_prompt.group())])) 79 | curcode += line[input_prompt.end():] 80 | elif continue_prompt is not None: 81 | insertions.append((len(curcode), 82 | [(0, Generic.Prompt, continue_prompt.group())])) 83 | curcode += line[continue_prompt.end():] 84 | elif output_prompt is not None: 85 | # Use the 'error' token for output. We should probably make 86 | # our own token, but error is typicaly in a bright color like 87 | # red, so it works fine for our output prompts. 88 | insertions.append((len(curcode), 89 | [(0, Generic.Error, output_prompt.group())])) 90 | curcode += line[output_prompt.end():] 91 | else: 92 | if curcode: 93 | for item in do_insertions(insertions, 94 | pylexer.get_tokens_unprocessed(curcode)): 95 | yield item 96 | curcode = '' 97 | insertions = [] 98 | yield match.start(), Generic.Output, line 99 | if curcode: 100 | for item in do_insertions(insertions, 101 | pylexer.get_tokens_unprocessed(curcode)): 102 | yield item 103 | 104 | 105 | def setup(app): 106 | """Setup as a sphinx extension.""" 107 | 108 | # This is only a lexer, so adding it below to pygments appears sufficient. 109 | # But if somebody knows that the right API usage should be to do that via 110 | # sphinx, by all means fix it here. At least having this setup.py 111 | # suppresses the sphinx warning we'd get without it. 112 | pass 113 | 114 | #----------------------------------------------------------------------------- 115 | # Register the extension as a valid pygments lexer 116 | highlighting.lexers['ipython'] = IPythonConsoleLexer() 117 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/tutorial.rst: -------------------------------------------------------------------------------- 1 | .. _tutorial: 2 | 3 | Seaborn tutorial 4 | ================ 5 | 6 | Style management 7 | ---------------- 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | 12 | tutorial/aesthetics 13 | tutorial/color_palettes 14 | 15 | Plotting functions 16 | ------------------ 17 | 18 | .. toctree:: 19 | :maxdepth: 2 20 | 21 | tutorial/distributions 22 | tutorial/regression 23 | tutorial/categorical 24 | 25 | Structured grids 26 | ---------------- 27 | 28 | .. toctree:: 29 | :maxdepth: 2 30 | 31 | tutorial/axis_grids 32 | 33 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/tutorial/Makefile: -------------------------------------------------------------------------------- 1 | notebooks: 2 | 3 | tools/nb_to_doc.py aesthetics 4 | tools/nb_to_doc.py color_palettes 5 | tools/nb_to_doc.py distributions 6 | tools/nb_to_doc.py regression 7 | tools/nb_to_doc.py categorical 8 | tools/nb_to_doc.py axis_grids 9 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/tutorial/tools/nb_to_doc.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | """ 3 | Convert empty IPython notebook to a sphinx doc page. 4 | 5 | """ 6 | import sys 7 | from subprocess import check_call as sh 8 | 9 | 10 | def convert_nb(nbname): 11 | 12 | # Execute the notebook 13 | sh(["ipython", "nbconvert", "--to", "notebook", 14 | "--execute", "--inplace", nbname + ".ipynb"]) 15 | 16 | # Convert to .rst for Sphinx 17 | sh(["ipython", "nbconvert", "--to", "rst", nbname + ".ipynb"]) 18 | 19 | # Clear notebook output 20 | sh(["ipython", "nbconvert", "--to", "notebook", "--inplace", 21 | "--ClearOutputPreprocessor.enabled=True", nbname + ".ipynb"]) 22 | 23 | 24 | if __name__ == "__main__": 25 | 26 | for nbname in sys.argv[1:]: 27 | convert_nb(nbname) 28 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/tutorial/tools/nbstripout: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """strip outputs from an IPython Notebook 3 | 4 | Opens a notebook, strips its output, and writes the outputless version to the original file. 5 | 6 | Useful mainly as a git pre-commit hook for users who don't want to track output in VCS. 7 | 8 | This does mostly the same thing as the `Clear All Output` command in the notebook UI. 9 | """ 10 | 11 | import io 12 | import sys 13 | 14 | from IPython.nbformat import current 15 | 16 | def strip_output(nb): 17 | """strip the outputs from a notebook object""" 18 | for cell in nb.worksheets[0].cells: 19 | if 'outputs' in cell: 20 | cell['outputs'] = [] 21 | if 'prompt_number' in cell: 22 | cell['prompt_number'] = None 23 | return nb 24 | 25 | if __name__ == '__main__': 26 | filename = sys.argv[1] 27 | with io.open(filename, 'r', encoding='utf8') as f: 28 | nb = current.read(f, 'json') 29 | nb = strip_output(nb) 30 | with io.open(filename, 'w', encoding='utf8') as f: 31 | current.write(nb, f, 'json') 32 | -------------------------------------------------------------------------------- /external/seaborn/dist/doc/whatsnew.rst: -------------------------------------------------------------------------------- 1 | .. _whatsnew: 2 | 3 | .. currentmodule:: seaborn 4 | 5 | What's new in the package 6 | ========================= 7 | 8 | A catalog of new features, improvements, and bug-fixes in each release. 9 | 10 | .. include:: releases/v0.7.1.txt 11 | 12 | .. include:: releases/v0.7.0.txt 13 | 14 | .. include:: releases/v0.6.0.txt 15 | 16 | .. include:: releases/v0.5.1.txt 17 | 18 | .. include:: releases/v0.5.0.txt 19 | 20 | .. include:: releases/v0.4.0.txt 21 | 22 | .. include:: releases/v0.3.1.txt 23 | 24 | .. include:: releases/v0.3.0.txt 25 | 26 | .. include:: releases/v0.2.1.txt 27 | 28 | .. include:: releases/v0.2.0.txt 29 | 30 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *_files/ 3 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/anscombes_quartet.py: -------------------------------------------------------------------------------- 1 | """ 2 | Anscombe's quartet 3 | ================== 4 | 5 | _thumb: .4, .4 6 | """ 7 | import seaborn as sns 8 | sns.set(style="ticks") 9 | 10 | # Load the example dataset for Anscombe's quartet 11 | df = sns.load_dataset("anscombe") 12 | 13 | # Show the results of a linear regression within each dataset 14 | sns.lmplot(x="x", y="y", col="dataset", hue="dataset", data=df, 15 | col_wrap=2, ci=None, palette="muted", size=4, 16 | scatter_kws={"s": 50, "alpha": 1}) 17 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/color_palettes.py: -------------------------------------------------------------------------------- 1 | """ 2 | Color palette choices 3 | ===================== 4 | 5 | """ 6 | import numpy as np 7 | import seaborn as sns 8 | import matplotlib.pyplot as plt 9 | sns.set(style="white", context="talk") 10 | rs = np.random.RandomState(7) 11 | 12 | 13 | # Set up the matplotlib figure 14 | f, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(8, 6), sharex=True) 15 | 16 | # Generate some sequential data 17 | x = np.array(list("ABCDEFGHI")) 18 | y1 = np.arange(1, 10) 19 | sns.barplot(x, y1, palette="BuGn_d", ax=ax1) 20 | ax1.set_ylabel("Sequential") 21 | 22 | # Center the data to make it diverging 23 | y2 = y1 - 5 24 | sns.barplot(x, y2, palette="RdBu_r", ax=ax2) 25 | ax2.set_ylabel("Diverging") 26 | 27 | # Randomly reorder the data to make it qualitative 28 | y3 = rs.choice(y1, 9, replace=False) 29 | sns.barplot(x, y3, palette="Set3", ax=ax3) 30 | ax3.set_ylabel("Qualitative") 31 | 32 | # Finalize the plot 33 | sns.despine(bottom=True) 34 | plt.setp(f.axes, yticks=[]) 35 | plt.tight_layout(h_pad=3) 36 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/cubehelix_palette.py: -------------------------------------------------------------------------------- 1 | """ 2 | Different cubehelix palettes 3 | ============================ 4 | 5 | _thumb: .4, .65 6 | """ 7 | import numpy as np 8 | import seaborn as sns 9 | import matplotlib.pyplot as plt 10 | 11 | sns.set(style="dark") 12 | rs = np.random.RandomState(50) 13 | 14 | # Set up the matplotlib figure 15 | f, axes = plt.subplots(3, 3, figsize=(9, 9), sharex=True, sharey=True) 16 | 17 | # Rotate the starting point around the cubehelix hue circle 18 | for ax, s in zip(axes.flat, np.linspace(0, 3, 10)): 19 | 20 | # Create a cubehelix colormap to use with kdeplot 21 | cmap = sns.cubehelix_palette(start=s, light=1, as_cmap=True) 22 | 23 | # Generate and plot a random bivariate dataset 24 | x, y = rs.randn(2, 50) 25 | sns.kdeplot(x, y, cmap=cmap, shade=True, cut=5, ax=ax) 26 | ax.set(xlim=(-3, 3), ylim=(-3, 3)) 27 | 28 | f.tight_layout() 29 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/distplot_options.py: -------------------------------------------------------------------------------- 1 | """ 2 | Distribution plot options 3 | ========================= 4 | 5 | """ 6 | import numpy as np 7 | import seaborn as sns 8 | import matplotlib.pyplot as plt 9 | 10 | sns.set(style="white", palette="muted", color_codes=True) 11 | rs = np.random.RandomState(10) 12 | 13 | # Set up the matplotlib figure 14 | f, axes = plt.subplots(2, 2, figsize=(7, 7), sharex=True) 15 | sns.despine(left=True) 16 | 17 | # Generate a random univariate dataset 18 | d = rs.normal(size=100) 19 | 20 | # Plot a simple histogram with binsize determined automatically 21 | sns.distplot(d, kde=False, color="b", ax=axes[0, 0]) 22 | 23 | # Plot a kernel density estimate and rug plot 24 | sns.distplot(d, hist=False, rug=True, color="r", ax=axes[0, 1]) 25 | 26 | # Plot a filled kernel density estimate 27 | sns.distplot(d, hist=False, color="g", kde_kws={"shade": True}, ax=axes[1, 0]) 28 | 29 | # Plot a historgram and kernel density estimate 30 | sns.distplot(d, color="m", ax=axes[1, 1]) 31 | 32 | plt.setp(axes, yticks=[]) 33 | plt.tight_layout() 34 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/elaborate_violinplot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Violinplot from a wide-form dataset 3 | =================================== 4 | 5 | _thumb: .6, .45 6 | """ 7 | import seaborn as sns 8 | import matplotlib.pyplot as plt 9 | sns.set(style="whitegrid") 10 | 11 | # Load the example dataset of brain network correlations 12 | df = sns.load_dataset("brain_networks", header=[0, 1, 2], index_col=0) 13 | 14 | # Pull out a specific subset of networks 15 | used_networks = [1, 3, 4, 5, 6, 7, 8, 11, 12, 13, 16, 17] 16 | used_columns = (df.columns.get_level_values("network") 17 | .astype(int) 18 | .isin(used_networks)) 19 | df = df.loc[:, used_columns] 20 | 21 | # Compute the correlation matrix and average over networks 22 | corr_df = df.corr().groupby(level="network").mean() 23 | corr_df.index = corr_df.index.astype(int) 24 | corr_df = corr_df.sort_index().T 25 | 26 | # Set up the matplotlib figure 27 | f, ax = plt.subplots(figsize=(11, 6)) 28 | 29 | # Draw a violinplot with a narrower bandwidth than the default 30 | sns.violinplot(data=corr_df, palette="Set3", bw=.2, cut=1, linewidth=1) 31 | 32 | # Finalize the figure 33 | ax.set(ylim=(-.7, 1.05)) 34 | sns.despine(left=True, bottom=True) 35 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/faceted_histogram.py: -------------------------------------------------------------------------------- 1 | """ 2 | Facetting histograms by subsets of data 3 | ======================================= 4 | 5 | _thumb: .42, .57 6 | """ 7 | import numpy as np 8 | import seaborn as sns 9 | import matplotlib.pyplot as plt 10 | sns.set(style="darkgrid") 11 | 12 | tips = sns.load_dataset("tips") 13 | g = sns.FacetGrid(tips, row="sex", col="time", margin_titles=True) 14 | bins = np.linspace(0, 60, 13) 15 | g.map(plt.hist, "total_bill", color="steelblue", bins=bins, lw=0) 16 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/facets_with_custom_projection.py: -------------------------------------------------------------------------------- 1 | """ 2 | FacetGrid with custom projection 3 | ================================ 4 | 5 | _thumb: .33, .5 6 | 7 | """ 8 | import matplotlib.pyplot as plt 9 | import numpy as np 10 | import pandas as pd 11 | import seaborn as sns 12 | 13 | sns.set() 14 | 15 | # Generate an example radial datast 16 | r = np.linspace(0, 10, num=100) 17 | df = pd.DataFrame({'r': r, 'slow': r, 'medium': 2 * r, 'fast': 4 * r}) 18 | 19 | # Convert the dataframe to long-form or "tidy" format 20 | df = pd.melt(df, id_vars=['r'], var_name='speed', value_name='theta') 21 | 22 | # Set up a grid of axes with a polar projection 23 | g = sns.FacetGrid(df, col="speed", hue="speed", 24 | subplot_kws=dict(projection='polar'), size=4.5, 25 | sharex=False, sharey=False, despine=False) 26 | 27 | # Draw a scatterplot onto each axes in the grid 28 | g.map(plt.scatter, "theta", "r") 29 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/factorplot_bars.py: -------------------------------------------------------------------------------- 1 | """ 2 | Grouped barplots 3 | ================ 4 | 5 | _thumb: .45, .5 6 | """ 7 | import seaborn as sns 8 | sns.set(style="whitegrid") 9 | 10 | # Load the example Titanic dataset 11 | titanic = sns.load_dataset("titanic") 12 | 13 | # Draw a nested barplot to show survival for class and sex 14 | g = sns.factorplot(x="class", y="survived", hue="sex", data=titanic, 15 | size=6, kind="bar", palette="muted") 16 | g.despine(left=True) 17 | g.set_ylabels("survival probability") 18 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/grouped_boxplot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Grouped boxplots 3 | ================ 4 | 5 | """ 6 | import seaborn as sns 7 | sns.set(style="ticks") 8 | 9 | # Load the example tips dataset 10 | tips = sns.load_dataset("tips") 11 | 12 | # Draw a nested boxplot to show bills by day and sex 13 | sns.boxplot(x="day", y="total_bill", hue="sex", data=tips, palette="PRGn") 14 | sns.despine(offset=10, trim=True) 15 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/grouped_violinplots.py: -------------------------------------------------------------------------------- 1 | """ 2 | Grouped violinplots with split violins 3 | ====================================== 4 | 5 | _thumb: .5, .47 6 | """ 7 | import seaborn as sns 8 | sns.set(style="whitegrid", palette="pastel", color_codes=True) 9 | 10 | # Load the example tips dataset 11 | tips = sns.load_dataset("tips") 12 | 13 | # Draw a nested violinplot and split the violins for easier comparison 14 | sns.violinplot(x="day", y="total_bill", hue="sex", data=tips, split=True, 15 | inner="quart", palette={"Male": "b", "Female": "y"}) 16 | sns.despine(left=True) 17 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/heatmap_annotation.py: -------------------------------------------------------------------------------- 1 | """ 2 | Annotated heatmaps 3 | ================== 4 | 5 | """ 6 | import seaborn as sns 7 | sns.set() 8 | 9 | # Load the example flights dataset and conver to long-form 10 | flights_long = sns.load_dataset("flights") 11 | flights = flights_long.pivot("month", "year", "passengers") 12 | 13 | # Draw a heatmap with the numeric values in each cell 14 | sns.heatmap(flights, annot=True, fmt="d", linewidths=.5) 15 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/hexbin_marginals.py: -------------------------------------------------------------------------------- 1 | """ 2 | Hexbin plot with marginal distributions 3 | ======================================= 4 | 5 | _thumb: .45, .4 6 | """ 7 | import numpy as np 8 | from scipy.stats import kendalltau 9 | import seaborn as sns 10 | sns.set(style="ticks") 11 | 12 | rs = np.random.RandomState(11) 13 | x = rs.gamma(2, size=1000) 14 | y = -.5 * x + rs.normal(size=1000) 15 | 16 | sns.jointplot(x, y, kind="hex", stat_func=kendalltau, color="#4CB391") 17 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/horizontal_barplot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Horizontal bar plots 3 | ==================== 4 | 5 | """ 6 | import seaborn as sns 7 | import matplotlib.pyplot as plt 8 | sns.set(style="whitegrid") 9 | 10 | # Initialize the matplotlib figure 11 | f, ax = plt.subplots(figsize=(6, 15)) 12 | 13 | # Load the example car crash dataset 14 | crashes = sns.load_dataset("car_crashes").sort_values("total", ascending=False) 15 | 16 | # Plot the total crashes 17 | sns.set_color_codes("pastel") 18 | sns.barplot(x="total", y="abbrev", data=crashes, 19 | label="Total", color="b") 20 | 21 | # Plot the crashes where alcohol was involved 22 | sns.set_color_codes("muted") 23 | sns.barplot(x="alcohol", y="abbrev", data=crashes, 24 | label="Alcohol-involved", color="b") 25 | 26 | # Add a legend and informative axis label 27 | ax.legend(ncol=2, loc="lower right", frameon=True) 28 | ax.set(xlim=(0, 24), ylabel="", 29 | xlabel="Automobile collisions per billion miles") 30 | sns.despine(left=True, bottom=True) 31 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/horizontal_boxplot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Horizontal boxplot with observations 3 | ==================================== 4 | 5 | _thumb: .7, .45 6 | """ 7 | import numpy as np 8 | import seaborn as sns 9 | sns.set(style="ticks", palette="muted", color_codes=True) 10 | 11 | # Load the example planets dataset 12 | planets = sns.load_dataset("planets") 13 | 14 | # Plot the orbital period with horizontal boxes 15 | ax = sns.boxplot(x="distance", y="method", data=planets, 16 | whis=np.inf, color="c") 17 | 18 | # Add in points to show each observation 19 | sns.stripplot(x="distance", y="method", data=planets, 20 | jitter=True, size=3, color=".3", linewidth=0) 21 | 22 | 23 | # Make the quantitative axis logarithmic 24 | ax.set_xscale("log") 25 | sns.despine(trim=True) 26 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/interactplot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Continuous interactions 3 | ======================= 4 | 5 | """ 6 | import numpy as np 7 | import pandas as pd 8 | import seaborn as sns 9 | sns.set(style="darkgrid") 10 | 11 | # Generate a random dataset with strong simple effects and an interaction 12 | n = 80 13 | rs = np.random.RandomState(11) 14 | x1 = rs.randn(n) 15 | x2 = x1 / 5 + rs.randn(n) 16 | b0, b1, b2, b3 = .5, .25, -1, 2 17 | y = b0 + b1 * x1 + b2 * x2 + b3 * x1 * x2 + rs.randn(n) 18 | df = pd.DataFrame(np.c_[x1, x2, y], columns=["x1", "x2", "y"]) 19 | 20 | # Show a scatterplot of the predictors with the estimated model surface 21 | sns.interactplot("x1", "x2", "y", df) 22 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/joint_kde.py: -------------------------------------------------------------------------------- 1 | """ 2 | Joint kernel density estimate 3 | ============================= 4 | 5 | _thumb: .6, .4 6 | """ 7 | import numpy as np 8 | import pandas as pd 9 | import seaborn as sns 10 | sns.set(style="white") 11 | 12 | # Generate a random correlated bivariate dataset 13 | rs = np.random.RandomState(5) 14 | mean = [0, 0] 15 | cov = [(1, .5), (.5, 1)] 16 | x1, x2 = rs.multivariate_normal(mean, cov, 500).T 17 | x1 = pd.Series(x1, name="$X_1$") 18 | x2 = pd.Series(x2, name="$X_2$") 19 | 20 | # Show the joint distribution using kernel density estimation 21 | g = sns.jointplot(x1, x2, kind="kde", size=7, space=0) 22 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/logistic_regression.py: -------------------------------------------------------------------------------- 1 | """ 2 | Faceted logistic regression 3 | =========================== 4 | 5 | _thumb: .58, .5 6 | """ 7 | import seaborn as sns 8 | sns.set(style="darkgrid") 9 | 10 | # Load the example titanic dataset 11 | df = sns.load_dataset("titanic") 12 | 13 | # Make a custom palette with gendered colors 14 | pal = dict(male="#6495ED", female="#F08080") 15 | 16 | # Show the survival proability as a function of age and sex 17 | g = sns.lmplot(x="age", y="survived", col="sex", hue="sex", data=df, 18 | palette=pal, y_jitter=.02, logistic=True) 19 | g.set(xlim=(0, 80), ylim=(-.05, 1.05)) 20 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/many_facets.py: -------------------------------------------------------------------------------- 1 | """ 2 | Plotting on a large number of facets 3 | ==================================== 4 | 5 | """ 6 | import numpy as np 7 | import pandas as pd 8 | import seaborn as sns 9 | import matplotlib.pyplot as plt 10 | sns.set(style="ticks") 11 | 12 | # Create a dataset with many short random walks 13 | rs = np.random.RandomState(4) 14 | pos = rs.randint(-1, 2, (20, 5)).cumsum(axis=1) 15 | pos -= pos[:, 0, np.newaxis] 16 | step = np.tile(range(5), 20) 17 | walk = np.repeat(range(20), 5) 18 | df = pd.DataFrame(np.c_[pos.flat, step, walk], 19 | columns=["position", "step", "walk"]) 20 | 21 | # Initialize a grid of plots with an Axes for each walk 22 | grid = sns.FacetGrid(df, col="walk", hue="walk", col_wrap=5, size=1.5) 23 | 24 | # Draw a horizontal line to show the starting point 25 | grid.map(plt.axhline, y=0, ls=":", c=".5") 26 | 27 | # Draw a line plot to show the trajectory of each random walk 28 | grid.map(plt.plot, "step", "position", marker="o", ms=4) 29 | 30 | # Adjust the tick positions and labels 31 | grid.set(xticks=np.arange(5), yticks=[-3, 3], 32 | xlim=(-.5, 4.5), ylim=(-3.5, 3.5)) 33 | 34 | # Adjust the arrangement of the plots 35 | grid.fig.tight_layout(w_pad=1) 36 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/many_pairwise_correlations.py: -------------------------------------------------------------------------------- 1 | """ 2 | Plotting a diagonal correlation matrix 3 | ====================================== 4 | 5 | _thumb: .3, .6 6 | """ 7 | from string import letters 8 | import numpy as np 9 | import pandas as pd 10 | import seaborn as sns 11 | import matplotlib.pyplot as plt 12 | 13 | sns.set(style="white") 14 | 15 | # Generate a large random dataset 16 | rs = np.random.RandomState(33) 17 | d = pd.DataFrame(data=rs.normal(size=(100, 26)), 18 | columns=list(letters[:26])) 19 | 20 | # Compute the correlation matrix 21 | corr = d.corr() 22 | 23 | # Generate a mask for the upper triangle 24 | mask = np.zeros_like(corr, dtype=np.bool) 25 | mask[np.triu_indices_from(mask)] = True 26 | 27 | # Set up the matplotlib figure 28 | f, ax = plt.subplots(figsize=(11, 9)) 29 | 30 | # Generate a custom diverging colormap 31 | cmap = sns.diverging_palette(220, 10, as_cmap=True) 32 | 33 | # Draw the heatmap with the mask and correct aspect ratio 34 | sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3, 35 | square=True, xticklabels=5, yticklabels=5, 36 | linewidths=.5, cbar_kws={"shrink": .5}, ax=ax) 37 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/marginal_ticks.py: -------------------------------------------------------------------------------- 1 | """ 2 | Scatterplot with marginal ticks 3 | =============================== 4 | 5 | _thumb: .65, .35 6 | """ 7 | import numpy as np 8 | import seaborn as sns 9 | import matplotlib.pyplot as plt 10 | sns.set(style="white", color_codes=True) 11 | 12 | # Generate a random bivariate dataset 13 | rs = np.random.RandomState(9) 14 | mean = [0, 0] 15 | cov = [(1, 0), (0, 2)] 16 | x, y = rs.multivariate_normal(mean, cov, 100).T 17 | 18 | # Use JointGrid directly to draw a custom plot 19 | grid = sns.JointGrid(x, y, space=0, size=6, ratio=50) 20 | grid.plot_joint(plt.scatter, color="g") 21 | grid.plot_marginals(sns.rugplot, height=1, color="g") 22 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/multiple_joint_kde.py: -------------------------------------------------------------------------------- 1 | """ 2 | Multiple bivariate KDE plots 3 | ============================ 4 | 5 | _thumb: .6, .4 6 | """ 7 | import seaborn as sns 8 | import matplotlib.pyplot as plt 9 | 10 | sns.set(style="darkgrid") 11 | iris = sns.load_dataset("iris") 12 | 13 | # Subset the iris dataset by species 14 | setosa = iris.query("species == 'setosa'") 15 | virginica = iris.query("species == 'virginica'") 16 | 17 | # Set up the figure 18 | f, ax = plt.subplots(figsize=(8, 8)) 19 | ax.set_aspect("equal") 20 | 21 | # Draw the two density plots 22 | ax = sns.kdeplot(setosa.sepal_width, setosa.sepal_length, 23 | cmap="Reds", shade=True, shade_lowest=False) 24 | ax = sns.kdeplot(virginica.sepal_width, virginica.sepal_length, 25 | cmap="Blues", shade=True, shade_lowest=False) 26 | 27 | # Add labels to the plot 28 | red = sns.color_palette("Reds")[-2] 29 | blue = sns.color_palette("Blues")[-2] 30 | ax.text(2.5, 8.2, "virginica", size=16, color=blue) 31 | ax.text(3.8, 4.5, "setosa", size=16, color=red) 32 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/multiple_regression.py: -------------------------------------------------------------------------------- 1 | """ 2 | Multiple linear regression 3 | ========================== 4 | 5 | """ 6 | import seaborn as sns 7 | sns.set(style="ticks", context="talk") 8 | 9 | # Load the example tips dataset 10 | tips = sns.load_dataset("tips") 11 | 12 | # Make a custom sequential palette using the cubehelix system 13 | pal = sns.cubehelix_palette(4, 1.5, .75, light=.6, dark=.2) 14 | 15 | # Plot tip as a function of toal bill across days 16 | g = sns.lmplot(x="total_bill", y="tip", hue="day", data=tips, 17 | palette=pal, size=7) 18 | 19 | # Use more informative axis labels than are provided by default 20 | g.set_axis_labels("Total bill ($)", "Tip ($)") 21 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/network_correlations.py: -------------------------------------------------------------------------------- 1 | """ 2 | Correlation matrix heatmap 3 | ========================== 4 | 5 | """ 6 | import seaborn as sns 7 | import matplotlib.pyplot as plt 8 | sns.set(context="paper", font="monospace") 9 | 10 | # Load the datset of correlations between cortical brain networks 11 | df = sns.load_dataset("brain_networks", header=[0, 1, 2], index_col=0) 12 | corrmat = df.corr() 13 | 14 | # Set up the matplotlib figure 15 | f, ax = plt.subplots(figsize=(12, 9)) 16 | 17 | # Draw the heatmap using seaborn 18 | sns.heatmap(corrmat, vmax=.8, square=True) 19 | 20 | # Use matplotlib directly to emphasize known networks 21 | networks = corrmat.columns.get_level_values("network") 22 | for i, network in enumerate(networks): 23 | if i and network != networks[i - 1]: 24 | ax.axhline(len(networks) - i, c="w") 25 | ax.axvline(i, c="w") 26 | f.tight_layout() 27 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/pair_grid_with_kde.py: -------------------------------------------------------------------------------- 1 | """ 2 | Paired Density and Scatterplot Matrix 3 | ===================================== 4 | 5 | _thumb: .5, .5 6 | """ 7 | import seaborn as sns 8 | import matplotlib.pyplot as plt 9 | sns.set(style="white") 10 | 11 | df = sns.load_dataset("iris") 12 | 13 | g = sns.PairGrid(df, diag_sharey=False) 14 | g.map_lower(sns.kdeplot, cmap="Blues_d") 15 | g.map_upper(plt.scatter) 16 | g.map_diag(sns.kdeplot, lw=3) 17 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/paired_pointplots.py: -------------------------------------------------------------------------------- 1 | """ 2 | Paired discrete plots 3 | ===================== 4 | 5 | """ 6 | import seaborn as sns 7 | sns.set(style="whitegrid") 8 | 9 | # Load the example Titanic dataset 10 | titanic = sns.load_dataset("titanic") 11 | 12 | # Set up a grid to plot survival probability against several variables 13 | g = sns.PairGrid(titanic, y_vars="survived", 14 | x_vars=["class", "sex", "who", "alone"], 15 | size=5, aspect=.5) 16 | 17 | # Draw a seaborn pointplot onto each Axes 18 | g.map(sns.pointplot, color=sns.xkcd_rgb["plum"]) 19 | g.set(ylim=(0, 1)) 20 | sns.despine(fig=g.fig, left=True) 21 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/pairgrid_dotplot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Dot plot with several variables 3 | =============================== 4 | 5 | _thumb: .3, .3 6 | """ 7 | import seaborn as sns 8 | sns.set(style="whitegrid") 9 | 10 | # Load the dataset 11 | crashes = sns.load_dataset("car_crashes") 12 | 13 | # Make the PairGrid 14 | g = sns.PairGrid(crashes.sort_values("total", ascending=False), 15 | x_vars=crashes.columns[:-3], y_vars=["abbrev"], 16 | size=10, aspect=.25) 17 | 18 | # Draw a dot plot using the stripplot function 19 | g.map(sns.stripplot, size=10, orient="h", 20 | palette="Reds_r", edgecolor="gray") 21 | 22 | # Use the same x axis limits on all columns and add better labels 23 | g.set(xlim=(0, 25), xlabel="Crashes", ylabel="") 24 | 25 | # Use semantically meaningful titles for the columns 26 | titles = ["Total crashes", "Speeding crashes", "Alcohol crashes", 27 | "Not distracted crashes", "No previous crashes"] 28 | 29 | for ax, title in zip(g.axes.flat, titles): 30 | 31 | # Set a different title for each axes 32 | ax.set(title=title) 33 | 34 | # Make the grid horizontal instead of vertical 35 | ax.xaxis.grid(False) 36 | ax.yaxis.grid(True) 37 | 38 | sns.despine(left=True, bottom=True) 39 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/pointplot_anova.py: -------------------------------------------------------------------------------- 1 | """ 2 | Plotting a three-way ANOVA 3 | ========================== 4 | 5 | _thumb: .42, .5 6 | """ 7 | import seaborn as sns 8 | sns.set(style="whitegrid") 9 | 10 | # Load the example exercise dataset 11 | df = sns.load_dataset("exercise") 12 | 13 | # Draw a pointplot to show pulse as a function of three categorical factors 14 | g = sns.factorplot(x="time", y="pulse", hue="kind", col="diet", data=df, 15 | capsize=.2, palette="YlGnBu_d", size=6, aspect=.75) 16 | g.despine(left=True) 17 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/regression_marginals.py: -------------------------------------------------------------------------------- 1 | """ 2 | Linear regression with marginal distributions 3 | ============================================= 4 | 5 | _thumb: .5, .6 6 | """ 7 | import seaborn as sns 8 | sns.set(style="darkgrid", color_codes=True) 9 | 10 | tips = sns.load_dataset("tips") 11 | g = sns.jointplot("total_bill", "tip", data=tips, kind="reg", 12 | xlim=(0, 60), ylim=(0, 12), color="r", size=7) 13 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/residplot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Plotting model residuals 3 | ======================== 4 | 5 | """ 6 | import numpy as np 7 | import seaborn as sns 8 | sns.set(style="whitegrid") 9 | 10 | # Make an example dataset with y ~ x 11 | rs = np.random.RandomState(7) 12 | x = rs.normal(2, 1, 75) 13 | y = 2 + 1.5 * x + rs.normal(0, 2, 75) 14 | 15 | # Plot the residuals after fitting a linear model 16 | sns.residplot(x, y, lowess=True, color="g") 17 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/scatterplot_categorical.py: -------------------------------------------------------------------------------- 1 | """ 2 | Scatterplot with categorical variables 3 | ====================================== 4 | 5 | """ 6 | import pandas as pd 7 | import seaborn as sns 8 | sns.set(style="whitegrid", palette="muted") 9 | 10 | # Load the example iris dataset 11 | iris = sns.load_dataset("iris") 12 | 13 | # "Melt" the dataset to "long-form" or "tidy" representation 14 | iris = pd.melt(iris, "species", var_name="measurement") 15 | 16 | # Draw a categorical scatterplot to show each observation 17 | sns.swarmplot(x="measurement", y="value", hue="species", data=iris) 18 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/scatterplot_matrix.py: -------------------------------------------------------------------------------- 1 | """ 2 | Scatterplot Matrix 3 | ================== 4 | 5 | _thumb: .5, .4 6 | """ 7 | import seaborn as sns 8 | sns.set() 9 | 10 | df = sns.load_dataset("iris") 11 | sns.pairplot(df, hue="species") 12 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/simple_violinplots.py: -------------------------------------------------------------------------------- 1 | """ 2 | Violinplots with observations 3 | ============================= 4 | 5 | """ 6 | import numpy as np 7 | import seaborn as sns 8 | 9 | sns.set() 10 | 11 | # Create a random dataset across several variables 12 | rs = np.random.RandomState(0) 13 | n, p = 40, 8 14 | d = rs.normal(0, 2, (n, p)) 15 | d += np.log(np.arange(1, p + 1)) * -5 + 10 16 | 17 | # Use cubehelix to get a custom sequential palette 18 | pal = sns.cubehelix_palette(p, rot=-.5, dark=.3) 19 | 20 | # Show each distribution with both violins and points 21 | sns.violinplot(data=d, palette=pal, inner="points") 22 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/structured_heatmap.py: -------------------------------------------------------------------------------- 1 | """ 2 | Discovering structure in heatmap data 3 | ===================================== 4 | 5 | _thumb: .4, .2 6 | """ 7 | import pandas as pd 8 | import seaborn as sns 9 | sns.set(font="monospace") 10 | 11 | # Load the brain networks example dataset 12 | df = sns.load_dataset("brain_networks", header=[0, 1, 2], index_col=0) 13 | 14 | # Select a subset of the networks 15 | used_networks = [1, 5, 6, 7, 8, 11, 12, 13, 16, 17] 16 | used_columns = (df.columns.get_level_values("network") 17 | .astype(int) 18 | .isin(used_networks)) 19 | df = df.loc[:, used_columns] 20 | 21 | # Create a custom palette to identify the networks 22 | network_pal = sns.cubehelix_palette(len(used_networks), 23 | light=.9, dark=.1, reverse=True, 24 | start=1, rot=-2) 25 | network_lut = dict(zip(map(str, used_networks), network_pal)) 26 | 27 | # Convert the palette to vectors that will be drawn on the side of the matrix 28 | networks = df.columns.get_level_values("network") 29 | network_colors = pd.Series(networks, index=df.columns).map(network_lut) 30 | 31 | # Create a custom colormap for the heatmap values 32 | cmap = sns.diverging_palette(h_neg=210, h_pos=350, s=90, l=30, as_cmap=True) 33 | 34 | # Draw the full plot 35 | sns.clustermap(df.corr(), row_colors=network_colors, linewidths=.5, 36 | col_colors=network_colors, figsize=(13, 13), cmap=cmap) 37 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/timeseries_bootstrapped.py: -------------------------------------------------------------------------------- 1 | """ 2 | Plotting timeseries data with bootstrap resampling 3 | ================================================== 4 | 5 | """ 6 | import numpy as np 7 | import seaborn as sns 8 | sns.set(style="darkgrid", palette="Set2") 9 | 10 | # Create a noisy periodic dataset 11 | sines = [] 12 | rs = np.random.RandomState(8) 13 | for _ in range(15): 14 | x = np.linspace(0, 30 / 2, 30) 15 | y = np.sin(x) + rs.normal(0, 1.5) + rs.normal(0, .3, 30) 16 | sines.append(y) 17 | 18 | # Plot the average over replicates with bootstrap resamples 19 | sns.tsplot(sines, err_style="boot_traces", n_boot=500) 20 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/timeseries_from_dataframe.py: -------------------------------------------------------------------------------- 1 | """ 2 | Timeseries from DataFrame 3 | ========================= 4 | 5 | """ 6 | 7 | import seaborn as sns 8 | sns.set(style="darkgrid") 9 | 10 | # Load the long-form example gammas dataset 11 | gammas = sns.load_dataset("gammas") 12 | 13 | # Plot the response with standard error 14 | sns.tsplot(data=gammas, time="timepoint", unit="subject", 15 | condition="ROI", value="BOLD signal") 16 | -------------------------------------------------------------------------------- /external/seaborn/dist/examples/timeseries_of_barplots.py: -------------------------------------------------------------------------------- 1 | """ 2 | Barplot timeseries 3 | ================== 4 | 5 | _thumb: .6, .4 6 | """ 7 | import numpy as np 8 | import seaborn as sns 9 | sns.set(style="white") 10 | 11 | # Load the example planets dataset 12 | planets = sns.load_dataset("planets") 13 | 14 | # Make a range of years to show categories with no observations 15 | years = np.arange(2000, 2015) 16 | 17 | # Draw a count plot to show the number of planets discovered each year 18 | g = sns.factorplot(x="year", data=planets, kind="count", 19 | palette="BuPu", size=6, aspect=1.5, order=years) 20 | g.set_xticklabels(step=2) 21 | -------------------------------------------------------------------------------- /external/seaborn/dist/licences/HUSL_LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2012 Alexei Boronine 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /external/seaborn/dist/licences/SIX_LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2014 Benjamin Peterson 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /external/seaborn/dist/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | scipy 3 | matplotlib 4 | pandas 5 | statsmodels 6 | patsy 7 | -------------------------------------------------------------------------------- /external/seaborn/dist/seaborn/__init__.py: -------------------------------------------------------------------------------- 1 | # Capture the original matplotlib rcParams 2 | import matplotlib as mpl 3 | _orig_rc_params = mpl.rcParams.copy() 4 | 5 | # Import seaborn objects 6 | from .rcmod import * 7 | from .utils import * 8 | from .palettes import * 9 | from .linearmodels import * 10 | from .categorical import * 11 | from .distributions import * 12 | from .timeseries import * 13 | from .matrix import * 14 | from .miscplot import * 15 | from .axisgrid import * 16 | from .widgets import * 17 | from .xkcd_rgb import xkcd_rgb 18 | from .crayons import crayons 19 | 20 | # Set default aesthetics 21 | set() 22 | 23 | __version__ = "0.7.1" 24 | -------------------------------------------------------------------------------- /external/seaborn/dist/seaborn/apionly.py: -------------------------------------------------------------------------------- 1 | from . import * 2 | reset_orig() 3 | -------------------------------------------------------------------------------- /external/seaborn/dist/seaborn/crayons.py: -------------------------------------------------------------------------------- 1 | crayons = {'Almond': '#EFDECD', 2 | 'Antique Brass': '#CD9575', 3 | 'Apricot': '#FDD9B5', 4 | 'Aquamarine': '#78DBE2', 5 | 'Asparagus': '#87A96B', 6 | 'Atomic Tangerine': '#FFA474', 7 | 'Banana Mania': '#FAE7B5', 8 | 'Beaver': '#9F8170', 9 | 'Bittersweet': '#FD7C6E', 10 | 'Black': '#000000', 11 | 'Blue': '#1F75FE', 12 | 'Blue Bell': '#A2A2D0', 13 | 'Blue Green': '#0D98BA', 14 | 'Blue Violet': '#7366BD', 15 | 'Blush': '#DE5D83', 16 | 'Brick Red': '#CB4154', 17 | 'Brown': '#B4674D', 18 | 'Burnt Orange': '#FF7F49', 19 | 'Burnt Sienna': '#EA7E5D', 20 | 'Cadet Blue': '#B0B7C6', 21 | 'Canary': '#FFFF99', 22 | 'Caribbean Green': '#00CC99', 23 | 'Carnation Pink': '#FFAACC', 24 | 'Cerise': '#DD4492', 25 | 'Cerulean': '#1DACD6', 26 | 'Chestnut': '#BC5D58', 27 | 'Copper': '#DD9475', 28 | 'Cornflower': '#9ACEEB', 29 | 'Cotton Candy': '#FFBCD9', 30 | 'Dandelion': '#FDDB6D', 31 | 'Denim': '#2B6CC4', 32 | 'Desert Sand': '#EFCDB8', 33 | 'Eggplant': '#6E5160', 34 | 'Electric Lime': '#CEFF1D', 35 | 'Fern': '#71BC78', 36 | 'Forest Green': '#6DAE81', 37 | 'Fuchsia': '#C364C5', 38 | 'Fuzzy Wuzzy': '#CC6666', 39 | 'Gold': '#E7C697', 40 | 'Goldenrod': '#FCD975', 41 | 'Granny Smith Apple': '#A8E4A0', 42 | 'Gray': '#95918C', 43 | 'Green': '#1CAC78', 44 | 'Green Yellow': '#F0E891', 45 | 'Hot Magenta': '#FF1DCE', 46 | 'Inchworm': '#B2EC5D', 47 | 'Indigo': '#5D76CB', 48 | 'Jazzberry Jam': '#CA3767', 49 | 'Jungle Green': '#3BB08F', 50 | 'Laser Lemon': '#FEFE22', 51 | 'Lavender': '#FCB4D5', 52 | 'Macaroni and Cheese': '#FFBD88', 53 | 'Magenta': '#F664AF', 54 | 'Mahogany': '#CD4A4C', 55 | 'Manatee': '#979AAA', 56 | 'Mango Tango': '#FF8243', 57 | 'Maroon': '#C8385A', 58 | 'Mauvelous': '#EF98AA', 59 | 'Melon': '#FDBCB4', 60 | 'Midnight Blue': '#1A4876', 61 | 'Mountain Meadow': '#30BA8F', 62 | 'Navy Blue': '#1974D2', 63 | 'Neon Carrot': '#FFA343', 64 | 'Olive Green': '#BAB86C', 65 | 'Orange': '#FF7538', 66 | 'Orchid': '#E6A8D7', 67 | 'Outer Space': '#414A4C', 68 | 'Outrageous Orange': '#FF6E4A', 69 | 'Pacific Blue': '#1CA9C9', 70 | 'Peach': '#FFCFAB', 71 | 'Periwinkle': '#C5D0E6', 72 | 'Piggy Pink': '#FDDDE6', 73 | 'Pine Green': '#158078', 74 | 'Pink Flamingo': '#FC74FD', 75 | 'Pink Sherbert': '#F78FA7', 76 | 'Plum': '#8E4585', 77 | 'Purple Heart': '#7442C8', 78 | "Purple Mountains' Majesty": '#9D81BA', 79 | 'Purple Pizzazz': '#FE4EDA', 80 | 'Radical Red': '#FF496C', 81 | 'Raw Sienna': '#D68A59', 82 | 'Razzle Dazzle Rose': '#FF48D0', 83 | 'Razzmatazz': '#E3256B', 84 | 'Red': '#EE204D', 85 | 'Red Orange': '#FF5349', 86 | 'Red Violet': '#C0448F', 87 | "Robin's Egg Blue": '#1FCECB', 88 | 'Royal Purple': '#7851A9', 89 | 'Salmon': '#FF9BAA', 90 | 'Scarlet': '#FC2847', 91 | "Screamin' Green": '#76FF7A', 92 | 'Sea Green': '#93DFB8', 93 | 'Sepia': '#A5694F', 94 | 'Shadow': '#8A795D', 95 | 'Shamrock': '#45CEA2', 96 | 'Shocking Pink': '#FB7EFD', 97 | 'Silver': '#CDC5C2', 98 | 'Sky Blue': '#80DAEB', 99 | 'Spring Green': '#ECEABE', 100 | 'Sunglow': '#FFCF48', 101 | 'Sunset Orange': '#FD5E53', 102 | 'Tan': '#FAA76C', 103 | 'Tickle Me Pink': '#FC89AC', 104 | 'Timberwolf': '#DBD7D2', 105 | 'Tropical Rain Forest': '#17806D', 106 | 'Tumbleweed': '#DEAA88', 107 | 'Turquoise Blue': '#77DDE7', 108 | 'Unmellow Yellow': '#FFFF66', 109 | 'Violet (Purple)': '#926EAE', 110 | 'Violet Red': '#F75394', 111 | 'Vivid Tangerine': '#FFA089', 112 | 'Vivid Violet': '#8F509D', 113 | 'White': '#FFFFFF', 114 | 'Wild Blue Yonder': '#A2ADD0', 115 | 'Wild Strawberry': '#FF43A4', 116 | 'Wild Watermelon': '#FC6C85', 117 | 'Wisteria': '#CDA4DE', 118 | 'Yellow': '#FCE883', 119 | 'Yellow Green': '#C5E384', 120 | 'Yellow Orange': '#FFAE42'} 121 | -------------------------------------------------------------------------------- /external/seaborn/dist/seaborn/external/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probcomp/iventure/5c0818f82ae2e20d7657e4ab96f42dc59f4ff60b/external/seaborn/dist/seaborn/external/__init__.py -------------------------------------------------------------------------------- /external/seaborn/dist/seaborn/miscplot.py: -------------------------------------------------------------------------------- 1 | from __future__ import division 2 | import numpy as np 3 | import matplotlib as mpl 4 | import matplotlib.pyplot as plt 5 | 6 | 7 | __call__ = ["palplot", "puppyplot"] 8 | 9 | 10 | def palplot(pal, size=1): 11 | """Plot the values in a color palette as a horizontal array. 12 | 13 | Parameters 14 | ---------- 15 | pal : sequence of matplotlib colors 16 | colors, i.e. as returned by seaborn.color_palette() 17 | size : 18 | scaling factor for size of plot 19 | 20 | """ 21 | n = len(pal) 22 | f, ax = plt.subplots(1, 1, figsize=(n * size, size)) 23 | ax.imshow(np.arange(n).reshape(1, n), 24 | cmap=mpl.colors.ListedColormap(list(pal)), 25 | interpolation="nearest", aspect="auto") 26 | ax.set_xticks(np.arange(n) - .5) 27 | ax.set_yticks([-.5, .5]) 28 | ax.set_xticklabels([]) 29 | ax.set_yticklabels([]) 30 | 31 | 32 | def puppyplot(grown_up=False): 33 | """Plot today's daily puppy. Only works in the IPython notebook.""" 34 | from .external.six.moves.urllib.request import urlopen 35 | from IPython.display import HTML 36 | try: 37 | from bs4 import BeautifulSoup 38 | url = "http://www.dailypuppy.com" 39 | if grown_up: 40 | url += "/dogs" 41 | html_doc = urlopen(url) 42 | soup = BeautifulSoup(html_doc) 43 | puppy = soup.find("div", {"class": "daily_puppy"}) 44 | return HTML(str(puppy.img)) 45 | except ImportError: 46 | html = ('') 49 | return HTML(html) 50 | -------------------------------------------------------------------------------- /external/seaborn/dist/seaborn/tests/__init__.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from matplotlib.pyplot import close 3 | 4 | 5 | class PlotTestCase(object): 6 | 7 | def setUp(self): 8 | np.random.seed(49) 9 | 10 | def tearDown(self): 11 | close('all') 12 | -------------------------------------------------------------------------------- /external/seaborn/dist/seaborn/tests/test_miscplot.py: -------------------------------------------------------------------------------- 1 | import nose.tools as nt 2 | import numpy.testing as npt 3 | import matplotlib.pyplot as plt 4 | 5 | from . import PlotTestCase 6 | from .. import miscplot as misc 7 | from .. import color_palette 8 | 9 | 10 | class TestPalPlot(PlotTestCase): 11 | """Test the function that visualizes a color palette.""" 12 | def test_palplot_size(self): 13 | 14 | pal4 = color_palette("husl", 4) 15 | misc.palplot(pal4) 16 | size4 = plt.gcf().get_size_inches() 17 | nt.assert_equal(tuple(size4), (4, 1)) 18 | 19 | pal5 = color_palette("husl", 5) 20 | misc.palplot(pal5) 21 | size5 = plt.gcf().get_size_inches() 22 | nt.assert_equal(tuple(size5), (5, 1)) 23 | 24 | palbig = color_palette("husl", 3) 25 | misc.palplot(palbig, 2) 26 | sizebig = plt.gcf().get_size_inches() 27 | nt.assert_equal(tuple(sizebig), (6, 2)) 28 | -------------------------------------------------------------------------------- /external/seaborn/dist/setup.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # 3 | # Copyright (C) 2012-2014 Michael Waskom 4 | import os 5 | # temporarily redirect config directory to prevent matplotlib importing 6 | # testing that for writeable directory which results in sandbox error in 7 | # certain easy_install versions 8 | os.environ["MPLCONFIGDIR"] = "." 9 | 10 | DESCRIPTION = "Seaborn: statistical data visualization" 11 | LONG_DESCRIPTION = """\ 12 | Seaborn is a library for making attractive and informative statistical graphics in Python. It is built on top of matplotlib and tightly integrated with the PyData stack, including support for numpy and pandas data structures and statistical routines from scipy and statsmodels. 13 | 14 | Some of the features that seaborn offers are 15 | 16 | - Several built-in themes that improve on the default matplotlib aesthetics 17 | - Tools for choosing color palettes to make beautiful plots that reveal patterns in your data 18 | - Functions for visualizing univariate and bivariate distributions or for comparing them between subsets of data 19 | - Tools that fit and visualize linear regression models for different kinds of independent and dependent variables 20 | - Functions that visualize matrices of data and use clustering algorithms to discover structure in those matrices 21 | - A function to plot statistical timeseries data with flexible estimation and representation of uncertainty around the estimate 22 | - High-level abstractions for structuring grids of plots that let you easily build complex visualizations 23 | """ 24 | 25 | DISTNAME = 'seaborn' 26 | MAINTAINER = 'Michael Waskom' 27 | MAINTAINER_EMAIL = 'mwaskom@stanford.edu' 28 | URL = 'http://stanford.edu/~mwaskom/software/seaborn/' 29 | LICENSE = 'BSD (3-clause)' 30 | DOWNLOAD_URL = 'https://github.com/mwaskom/seaborn/' 31 | VERSION = '0.7.1' 32 | 33 | try: 34 | from setuptools import setup 35 | _has_setuptools = True 36 | except ImportError: 37 | from distutils.core import setup 38 | 39 | def check_dependencies(): 40 | install_requires = [] 41 | 42 | # Just make sure dependencies exist, I haven't rigorously 43 | # tested what the minimal versions that will work are 44 | # (help on that would be awesome) 45 | try: 46 | import numpy 47 | except ImportError: 48 | install_requires.append('numpy') 49 | try: 50 | import scipy 51 | except ImportError: 52 | install_requires.append('scipy') 53 | try: 54 | import matplotlib 55 | except ImportError: 56 | install_requires.append('matplotlib') 57 | try: 58 | import pandas 59 | except ImportError: 60 | install_requires.append('pandas') 61 | 62 | return install_requires 63 | 64 | if __name__ == "__main__": 65 | 66 | install_requires = check_dependencies() 67 | 68 | setup(name=DISTNAME, 69 | author=MAINTAINER, 70 | author_email=MAINTAINER_EMAIL, 71 | maintainer=MAINTAINER, 72 | maintainer_email=MAINTAINER_EMAIL, 73 | description=DESCRIPTION, 74 | long_description=LONG_DESCRIPTION, 75 | license=LICENSE, 76 | url=URL, 77 | version=VERSION, 78 | download_url=DOWNLOAD_URL, 79 | install_requires=install_requires, 80 | packages=['seaborn', 'seaborn.external', 'seaborn.tests'], 81 | classifiers=[ 82 | 'Intended Audience :: Science/Research', 83 | 'Programming Language :: Python :: 2.7', 84 | 'Programming Language :: Python :: 3.3', 85 | 'Programming Language :: Python :: 3.4', 86 | 'License :: OSI Approved :: BSD License', 87 | 'Topic :: Scientific/Engineering :: Visualization', 88 | 'Topic :: Multimedia :: Graphics', 89 | 'Operating System :: POSIX', 90 | 'Operating System :: Unix', 91 | 'Operating System :: MacOS'], 92 | ) 93 | -------------------------------------------------------------------------------- /external/seaborn/dist/testing/deps_minimal_2.7.txt: -------------------------------------------------------------------------------- 1 | ipython-notebook 2 | nose 3 | numpy=1.6.2 4 | scipy=0.11.0 5 | matplotlib=1.1.1 6 | pandas=0.12.0 7 | statsmodels=0.5.0 8 | patsy=0.2.1 9 | -------------------------------------------------------------------------------- /external/seaborn/dist/testing/deps_modern_2.7.txt: -------------------------------------------------------------------------------- 1 | ipython-notebook 2 | nose 3 | numpy 4 | scipy 5 | matplotlib 6 | pandas 7 | statsmodels 8 | patsy 9 | -------------------------------------------------------------------------------- /external/seaborn/dist/testing/deps_modern_3.4.txt: -------------------------------------------------------------------------------- 1 | ipython-notebook 2 | nose 3 | numpy 4 | scipy 5 | matplotlib 6 | pandas 7 | statsmodels 8 | -------------------------------------------------------------------------------- /external/seaborn/dist/testing/deps_modern_3.5.txt: -------------------------------------------------------------------------------- 1 | ipython-notebook 2 | nose 3 | numpy 4 | scipy 5 | matplotlib 6 | pandas 7 | statsmodels 8 | patsy 9 | -------------------------------------------------------------------------------- /external/seaborn/dist/testing/matplotlibrc: -------------------------------------------------------------------------------- 1 | backend : Agg 2 | -------------------------------------------------------------------------------- /pythenv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -Ceu 4 | 5 | : ${PYTHON:=python} 6 | root=`cd -- "$(dirname -- "$0")" && pwd` 7 | platform=`"${PYTHON}" -c 'import distutils.util as u; print u.get_platform()'` 8 | version=`"${PYTHON}" -c 'import sys; print sys.version[0:3]'` 9 | 10 | # The lib directory varies depending on 11 | # 12 | # (a) whether there are extension modules (here, no); and 13 | # (b) whether some Debian maintainer decided to patch the local Python 14 | # to behave as though there were. 15 | # 16 | # But there's no obvious way to just ask distutils what the name will 17 | # be. There's no harm in naming a pathname that doesn't exist, other 18 | # than a handful of microseconds of runtime, so we'll add both. 19 | libdir="${root}/build/lib" 20 | plat_libdir="${libdir}.${platform}-${version}" 21 | export PYTHONPATH="${libdir}:${plat_libdir}${PYTHONPATH:+:${PYTHONPATH}}" 22 | 23 | bindir="${root}/build/scripts-${version}" 24 | export PATH="${bindir}${PATH:+:${PATH}}" 25 | 26 | exec "$@" 27 | -------------------------------------------------------------------------------- /script/tex_header.tex: -------------------------------------------------------------------------------- 1 | % Copyright (c) 2010-2016, MIT Probabilistic Computing Project 2 | % 3 | % Licensed under the Apache License, Version 2.0 (the "License"); 4 | % you may not use this file except in compliance with the License. 5 | % You may obtain a copy of the License at 6 | % 7 | % http://www.apache.org/licenses/LICENSE-2.0 8 | % 9 | % Unless required by applicable law or agreed to in writing, software 10 | % distributed under the License is distributed on an "AS IS" BASIS, 11 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | % See the License for the specific language governing permissions and 13 | % limitations under the License. 14 | 15 | \documentclass[preview,border={0.3in 1bp 0.5bp 1bp}]{standalone} 16 | 17 | \usepackage{xcolor} 18 | \usepackage{listings} 19 | \usepackage{tikz} 20 | 21 | % Implement red highlighting 22 | % This mumbo-jumbo (until \makeatother) is from 23 | % http://tex.stackexchange.com/questions/15237/highlight-text-in-code-listing-while-also-keeping-syntax-highlighting/49309#49309 24 | % for working around a limitation in listings. 25 | \colorlet{highlight}{red!30} 26 | 27 | \makeatletter 28 | \newenvironment{btHighlight}[1][] 29 | {\begingroup\tikzset{bt@Highlight@par/.style={#1}}\begin{lrbox}{\@tempboxa}} 30 | {\end{lrbox}\bt@HL@box[bt@Highlight@par]{\@tempboxa}\endgroup} 31 | 32 | \newcommand\btHL[1][]{% 33 | \begin{btHighlight}[#1]\bgroup\aftergroup\bt@HL@endenv% 34 | } 35 | \def\bt@HL@endenv{% 36 | \end{btHighlight}% 37 | \egroup 38 | } 39 | \newcommand{\bt@HL@box}[2][]{% 40 | \tikz[#1]{% 41 | \pgfpathrectangle{\pgfpoint{1pt}{0pt}}{\pgfpoint{\wd #2}{\ht #2}}% 42 | \pgfusepath{use as bounding box}% 43 | \node[anchor=base west, fill=highlight,outer sep=0pt,inner xsep=1pt, inner ysep=0pt, rounded corners=3pt, minimum height=\ht\strutbox+1pt,#1]{\raisebox{1pt}{\strut}\strut\usebox{#2}}; 44 | }% 45 | } 46 | \makeatother 47 | 48 | \definecolor{model-red}{rgb}{0.4,0,0} 49 | \definecolor{comment-green}{rgb}{0,0.4,0} 50 | \definecolor{string-brown}{rgb}{0.4,0.2,0} 51 | \definecolor{predef-purple}{rgb}{0.38,0,0.83} 52 | \definecolor{quasi-blue}{rgb}{0,0.2,0.6} 53 | \definecolor{special-orange}{rgb}{0.75,0.3,0} 54 | 55 | \lstdefinelanguage{VentureScript}{ 56 | morecomment=[l]{//}, 57 | commentstyle=\color{comment-green}, 58 | morestring=[b]", 59 | morestring=[b]', 60 | moredelim=**[is][\btHL]{/*\{*/}{/*\}*/}, % Highlight inside funny inline comments 61 | moredelim=**[is][keywordstyle4]{/|}{|/}, 62 | stringstyle=\color{string-brown}, 63 | moredelim=[s][\color{quasi-blue}]{[|}{|]}, 64 | keywordstyle=[2]\color{model-red}, 65 | keywords=[2]{assume,generate,observe,define,assume_list,sample,call_back}, 66 | keywordstyle=[3]\color{special-orange}, 67 | keywords=[3]{if,then,else,lambda,proc,tag,do,repeat,return,run,with,true,false, 68 | begin,let,letrec,make_sp,make_elementary_sp,quote}, 69 | keywordstyle=[4]\color{predef-purple}, 70 | keywords=[4]{pass,for_each,all,uniform_continuous,normal,gamma,beta, 71 | categorical,flip,log_flip,assess,reverse,dot,mem,length,lookup,list,pair, 72 | first,rest,second,keys,values,sum,logsumexp,sqrt,log,cos,pow, 73 | matrix_times_vector,fill,size,is_pair,hadamard,to_array, 74 | log_gamma_function,log_beta_function,apply_sp,log_density_of_sp, 75 | invoke_metaprogram_of_sp,next_base_address,global_env,eval_request, 76 | value_at,bind_global,find_symbol,register_observation,get_observations, 77 | set_value_at,clone_trace,single_site_subproblem,weight_bound,extract, 78 | regen,restore,run_in,eval_in,exec_in,infer,blank_trace,flat_trace,graph_trace, 79 | request_address,address_of,extend_environment,get_current_environment, 80 | uneval_request,restore_request,proposal_kernel_of_sp_at, 81 | constraint_kernel_of_sp_at,extract_kernel,regen_kernel,restore_kernel, 82 | global_log_likelihood,gibbs,minimal_subproblem,mapv,sorted,arange,make_nig_normal,make_crp,mapM, 83 | mh,integer,log_odds_beta,log_odds_flip,log_odds_bernoulli,tag_exclude}, 84 | escapeinside={(*@}{@*)} 85 | } 86 | \lstset{ 87 | basicstyle=\ttfamily, 88 | numbers=left 89 | } 90 | 91 | \definecolor{modelblock}{RGB}{238,235,245} 92 | \definecolor{observationblock}{RGB}{226,239,220} 93 | \definecolor{inferenceblock}{RGB}{230,240,249} 94 | \definecolor{queryblock}{RGB}{230,249,248} 95 | 96 | \usepackage[margin=0in,left=0.3in,right=1bp]{geometry} 97 | 98 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright (c) 2015-2016 MIT Probabilistic Computing Project 4 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | try: 18 | from setuptools import setup 19 | from setuptools.command.build_py import build_py 20 | from setuptools.command.sdist import sdist 21 | from setuptools.command.test import test 22 | except ImportError: 23 | from distutils.core import setup 24 | from distutils.cmd import Command 25 | from distutils.command.build_py import build_py 26 | from distutils.command.sdist import sdist 27 | 28 | def get_version(): 29 | import re 30 | import subprocess 31 | # git describe a commit using the most recent tag reachable from it. 32 | # Release tags start with v* (XXX what about other tags starting with v?) 33 | # and are of the form `v1.1.2`. 34 | # 35 | # The output `desc` will be of the form v1.1.2-2-gb92bef6[-dirty]: 36 | # - verpart v1.1.2 37 | # - revpart 2 38 | # - localpart gb92bef6[-dirty] 39 | desc = subprocess.check_output([ 40 | 'git', 'describe', '--dirty', '--long', '--match', 'v*', 41 | ]) 42 | match = re.match(r'^v([^-]*)-([0-9]+)-(.*)$', desc) 43 | assert match is not None 44 | verpart, revpart, localpart = match.groups() 45 | # Create a post version. 46 | if revpart > '0' or 'dirty' in localpart: 47 | # Local part may be g0123abcd or g0123abcd-dirty. 48 | # Hyphens not kosher here, so replace by dots. 49 | localpart = localpart.replace('-', '.') 50 | full_version = '%s.post%s+%s' % (verpart, revpart, localpart) 51 | # Create a release version. 52 | else: 53 | full_version = verpart 54 | 55 | # Strip the local part if there is one, to appease pkg_resources, 56 | # which handles only PEP 386, not PEP 440. 57 | if '+' in full_version: 58 | pkg_version = full_version[:full_version.find('+')] 59 | else: 60 | pkg_version = full_version 61 | 62 | # Sanity-check the result. XXX Consider checking the full PEP 386 63 | # and PEP 440 regular expressions here? 64 | assert '-' not in full_version, '%r' % (full_version,) 65 | assert '-' not in pkg_version, '%r' % (pkg_version,) 66 | assert '+' not in pkg_version, '%r' % (pkg_version,) 67 | 68 | return pkg_version, full_version 69 | 70 | pkg_version, full_version = get_version() 71 | 72 | def write_version_py(path): 73 | try: 74 | with open(path, 'rb') as f: 75 | version_old = f.read() 76 | except IOError: 77 | version_old = None 78 | version_new = '__version__ = %r\n' % (full_version,) 79 | if version_old != version_new: 80 | print 'writing %s' % (path,) 81 | with open(path, 'wb') as f: 82 | f.write(version_new) 83 | 84 | def readme_contents(): 85 | import os.path 86 | readme_path = os.path.join( 87 | os.path.abspath(os.path.dirname(__file__)), 88 | 'README.md') 89 | with open(readme_path) as readme_file: 90 | return unicode(readme_file.read(), 'UTF-8') 91 | 92 | class local_build_py(build_py): 93 | def run(self): 94 | write_version_py(version_py) 95 | build_py.run(self) 96 | 97 | # Make sure the VERSION file in the sdist is exactly specified, even 98 | # if it is a development version, so that we do not need to run git to 99 | # discover it -- which won't work because there's no .git directory in 100 | # the sdist. 101 | class local_sdist(sdist): 102 | def make_release_tree(self, base_dir, files): 103 | import os 104 | sdist.make_release_tree(self, base_dir, files) 105 | version_file = os.path.join(base_dir, 'VERSION') 106 | print('updating %s' % (version_file,)) 107 | # Write to temporary file first and rename over permanent not 108 | # just to avoid atomicity issues (not likely an issue since if 109 | # interrupted the whole sdist directory is only partially 110 | # written) but because the upstream sdist may have made a hard 111 | # link, so overwriting in place will edit the source tree. 112 | with open(version_file + '.tmp', 'wb') as f: 113 | f.write('%s\n' % (pkg_version,)) 114 | os.rename(version_file + '.tmp', version_file) 115 | 116 | # XXX These should be attributes of `setup', but helpful distutils 117 | # doesn't pass them through when it doesn't know about them a priori. 118 | version_py = 'src/version.py' 119 | 120 | setup( 121 | name='iventure', 122 | version=pkg_version, 123 | description='iVenture Interactive Probabilistic Programming Environment', 124 | long_description=readme_contents(), 125 | url='https://github.com/probcomp/iventure', 126 | license='Apache-2.0', 127 | maintainer='Feras Saad', 128 | maintainer_email='fsaad@remove-this-component.mit.edu', 129 | classifiers=[ 130 | 'Development Status :: 2 - Pre-Alpha', 131 | 'Intended Audience :: Science/Research', 132 | 'License :: OSI Approved :: Apache Software License', 133 | 'Programming Language :: Python :: 2.7', 134 | 'Topic :: Scientific/Engineering :: Information Analysis', 135 | ], 136 | packages=[ 137 | 'iventure', 138 | 'iventure.jsviz', 139 | 'iventure.seaborn', 140 | 'iventure.seaborn.external', 141 | #'iventure.seaborn.tests', 142 | 'iventure.tests', 143 | 'jupyter_probcomp', 144 | ], 145 | package_dir={ 146 | 'iventure': 'src', 147 | 'iventure.jsviz': 'src/jsviz', 148 | 'iventure.seaborn': 'external/seaborn/dist/seaborn', 149 | 'iventure.tests': 'tests', 150 | 'jupyter_probcomp': 'src/jupyter', 151 | }, 152 | package_data={ 153 | 'iventure.jsviz': ['*.js'] 154 | }, 155 | cmdclass={ 156 | 'build_py': local_build_py, 157 | 'sdist': local_sdist, 158 | }, 159 | ) 160 | -------------------------------------------------------------------------------- /src/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright (c) 2015-2016 MIT Probabilistic Computing Project 4 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | -------------------------------------------------------------------------------- /src/jsviz/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright (c) 2015-2016 MIT Probabilistic Computing Project 4 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | -------------------------------------------------------------------------------- /src/jsviz/bar.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2016, MIT Probabilistic Computing Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | function bar(df) { 16 | var myCell = element.is('.output_subarea') ? element : element.next(); 17 | 18 | // Validate input format. It should be a pandas dataframe in "split" format: 19 | // df.to_json(orient="split") 20 | 21 | if (!(df.columns && df.index && df.data)) { 22 | throw new Error("Incorrect data format"); 23 | } 24 | 25 | if (df.columns.length !== 2) { 26 | throw new Error("There must be exactly two columns"); 27 | } 28 | 29 | // restrict data to only numeric data 30 | const rows = df.data.filter( ([,number]) => typeof number === 'number' ); 31 | 32 | if (!rows.length) { 33 | throw new Error("No rows contain numbers in the second column"); 34 | } 35 | 36 | const [ xName, yName ] = df.columns; 37 | 38 | const container = $("
").css({ display: 'flex', flexDiection: 'row' }).appendTo(myCell.empty()); 39 | 40 | function $s(elem) { 41 | return $(document.createElementNS('http://www.w3.org/2000/svg', elem)); 42 | } 43 | const svg = $s('svg').attr({ width: 15, height: 500 }) 44 | .append($s('text').attr({transform: "rotate(270) translate(-250 12)", size:"12", style: "fill: #000000", 'text-anchor': "middle", 'font-weight': 'bold'}).text(yName)); 45 | 46 | $('
').append(svg).appendTo(container); 47 | 48 | const middleContainer = $('
').appendTo(container); 49 | middleContainer.append($('
').text(xName)); 50 | 51 | VizGPMReady 52 | .then(VizGPM => { 53 | const _ = VizGPM._; 54 | const root = $("
").prependTo(middleContainer)[0]; 55 | 56 | const xValue = d => d[0]; 57 | const yValue = d => d[1]; 58 | 59 | class CustomBarChart extends VizGPM.Charts.Histogram { 60 | _calculateData() { 61 | if (!this._.aesthetics) return; 62 | if (this.hasChanged('rows', 'scales')) { 63 | const { 64 | rows, 65 | scales: {x: xScale, y: yScale}, 66 | aesthetics: [ 67 | {value, name: axisName, bins}, 68 | {value: yValue} = {}, 69 | ], 70 | width, 71 | } = this._; 72 | 73 | // the histogram chart works as a bar, but it's internal represntation 74 | // has "x" and "value" so needs a little customization 75 | this._.chartData = rows.map(row => ({ 76 | x: value(row), 77 | value: yValue(row), 78 | rows: new Set([ row ]), 79 | query: { [axisName]: { $in: [value(row)] } }, 80 | })) 81 | 82 | xScale.domain(this._.chartData.map( d => d.x )); 83 | yScale.domain([0, _.max(this._.chartData.map(d => d.value))]).nice(); 84 | } 85 | } 86 | } 87 | 88 | const size = 500; 89 | 90 | var bar = new CustomBarChart({ 91 | root, 92 | rows, 93 | size, 94 | margin: { 95 | bottom: Math.max(size/6, 35), 96 | left: Math.max(size/12, 35), 97 | top: 0, 98 | right: 0, 99 | }, 100 | aesthetics: [{ 101 | name: xName, 102 | value: xValue, 103 | }, { 104 | name: yName, 105 | value: yValue, 106 | }], 107 | scales: { 108 | x: VizGPM.Charts.Scales.SCALE_METHOD.band(), 109 | y: VizGPM.Charts.Scales.SCALE_METHOD.linear(), 110 | }, 111 | }); 112 | 113 | bar.render(); 114 | }) 115 | .catch(e => { 116 | const stack = $("") 117 | .css({ whiteSpace: "pre", display: "block", color: "red", overflow: "auto" }) 118 | .text(e.stack); 119 | debugger; 120 | myCell.append("Error initializing chart:", stack); 121 | }) 122 | } 123 | -------------------------------------------------------------------------------- /src/jsviz/heatmap.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2016, MIT Probabilistic Computing Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | function heatmap(df, labels) { 17 | var myCell = element.is('.output_subarea') ? element : element.next(); 18 | if (typeof VizGPMReady === 'undefined') { 19 | throw new Error('VizGPM Display Library not loaded') 20 | } 21 | 22 | if (df.columns.length !== 3) { 23 | throw new Error('Must be 3 columns of data'); 24 | } 25 | 26 | const toggleClass = (element, className, state) => { 27 | element.classList[state ? 'add' : 'remove'](className) 28 | } 29 | 30 | // convert the data to an MI object for VizGPM 31 | var associations = {} 32 | const columns = new Set(); 33 | for (const [col0, col1, value] of df.data) { 34 | columns.add(col0); 35 | columns.add(col1); 36 | if (!associations[col0]) { 37 | associations[col0] = {} 38 | } 39 | associations[col0][col1] = value 40 | } 41 | 42 | function between(col1, col2) { 43 | return associations[col1][col2] 44 | } 45 | 46 | // This is what VizGPM expects for the mutual info charts 47 | var mi = { target: labels || [...columns], between: between } 48 | 49 | var container = $('
') 50 | .appendTo(myCell); 51 | 52 | var depProbContainer = $('
').appendTo(container); 53 | var columnListContainer = $('
').appendTo(container); 54 | 55 | $("").appendTo(container); 56 | 57 | VizGPMReady.then(function(VizGPM) { 58 | const _ = VizGPM._; 59 | 60 | const SP = VizGPM.StateProperty 61 | 62 | const schema = [...columns].map(name => ({name})); 63 | 64 | var stateManager = new VizGPM.StateManager({ 65 | [SP.SCHEMA]: {columns: schema}, 66 | columns: [...columns], 67 | [SP.SELECTED_COLUMN_NAMES]: [], 68 | [SP.GET_COLUMN_FUNCTION]: col => 69 | VizGPM.GpmHandler.prototype._getColumn.call(stateManager, col), 70 | }); 71 | 72 | // var debug = $('
').appendTo(element);
 73 |     // stateManager.subscribe(function(newState) {
 74 |     //   const showState = Object.assign({}, newState.state);
 75 |     //   delete showState.schema;
 76 |     //   delete showState.rows;
 77 |     //   debug.text(JSON.stringify(showState, false, '  '))
 78 |     // })
 79 | 
 80 |     const chart = new VizGPM.ZoomableColumnAssociation({
 81 |       root: depProbContainer[0],
 82 |       stateManager: stateManager,
 83 |       // subgridClass: SingleSelectSubgrid,
 84 |       associationFn: function() {
 85 |         return mi
 86 |       },
 87 |       // subgridConfig: {
 88 |         // cellSelectedFn: ({ xColumn, yColumn, selectedColumns: [x, y = x] = [] }) =>
 89 |           // xColumn === x && yColumn === y,
 90 |       // },
 91 |       // miniMapConfig: {
 92 |         // cellSelectedFn: ({ xColumn, yColumn, selectedColumns: [x, y = x] = [] }) =>
 93 |           // xColumn === x || yColumn === y,
 94 |       // },
 95 |     })
 96 | 
 97 |     const columnList = new VizGPM.UI.ColumnList({
 98 |       root: columnListContainer[0],
 99 |       stateManager,
100 |     })
101 |   })
102 | }
103 | 


--------------------------------------------------------------------------------
/src/jsviz/inline.js:
--------------------------------------------------------------------------------
 1 | //   Copyright (c) 2010-2016, MIT Probabilistic Computing Project
 2 | //
 3 | //   Licensed under the Apache License, Version 2.0 (the "License");
 4 | //   you may not use this file except in compliance with the License.
 5 | //   You may obtain a copy of the License at
 6 | //
 7 | //       http://www.apache.org/licenses/LICENSE-2.0
 8 | //
 9 | //   Unless required by applicable law or agreed to in writing, software
10 | //   distributed under the License is distributed on an "AS IS" BASIS,
11 | //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | //   See the License for the specific language governing permissions and
13 | //   limitations under the License.
14 | 
15 | var myCell = element
16 | window.VizGPMReady = new Promise(resolve => {
17 |   $.getScript('https://probcomp-2.csail.mit.edu/vizgpm/vizgpm.js', function() {
18 |     myCell.append('Loaded VizGPM v' + VizGPM.version);
19 |     $.getScript('https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js', function() {
20 |       myCell.append('Loaded lodash v' + _.VERSION);
21 |       VizGPM._ = _.noConflict();
22 |       resolve(VizGPM)
23 |     });
24 |   })
25 | })
26 | 


--------------------------------------------------------------------------------
/src/jsviz/jsviz.py:
--------------------------------------------------------------------------------
  1 | # -*- coding: utf-8 -*-
  2 | 
  3 | #   Copyright (c) 2010-2016, MIT Probabilistic Computing Project
  4 | #
  5 | #   Licensed under the Apache License, Version 2.0 (the "License");
  6 | #   you may not use this file except in compliance with the License.
  7 | #   You may obtain a copy of the License at
  8 | #
  9 | #       http://www.apache.org/licenses/LICENSE-2.0
 10 | #
 11 | #   Unless required by applicable law or agreed to in writing, software
 12 | #   distributed under the License is distributed on an "AS IS" BASIS,
 13 | #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14 | #   See the License for the specific language governing permissions and
 15 | #   limitations under the License.
 16 | 
 17 | 
 18 | import json
 19 | 
 20 | from pkg_resources import resource_string
 21 | 
 22 | import numpy as np
 23 | 
 24 | from IPython.display import Javascript
 25 | 
 26 | from iventure import utils_plot
 27 | 
 28 | 
 29 | def enable_inline():
 30 |     """Enable inline JavaScript code to execute in an iventure notebook."""
 31 |     js_src = resource_string('iventure.jsviz', 'inline.js')
 32 |     return Javascript(js_src)
 33 | 
 34 | def interactive_bar(df):
 35 |     """Create an interactive barplot visualization."""
 36 |     js_src = resource_string('iventure.jsviz', 'bar.js')
 37 |     return Javascript(
 38 |         js_src \
 39 |         + ';bar(' \
 40 |         + df.to_json(orient='split') \
 41 |         + ')'
 42 |     )
 43 | 
 44 | def interactive_depprob(df_dep, df_data=None, schema=None):
 45 |     """Create an interactive dependence probability visualization."""
 46 |     js_src = resource_string('iventure.jsviz', 'depprob.js')
 47 |     assert len(df_dep.columns) == 3
 48 |     df_dep.columns = ['name0', 'name1', 'value']
 49 |     if df_data is not None and schema is not None:
 50 |         return Javascript(
 51 |             js_src \
 52 |             + 'depprob_demo(' \
 53 |             + df_dep.to_json()
 54 |             + ', ' \
 55 |             + df_data.to_json(orient='records') \
 56 |             + ', ' \
 57 |             + schema \
 58 |             + ')'
 59 |         )
 60 |     else:
 61 |         return Javascript(
 62 |             js_src \
 63 |             + 'depprob_demo(' \
 64 |             + df_dep.to_json() \
 65 |             + ')'
 66 |         )
 67 | 
 68 | def interactive_heatmap(df):
 69 |     """Create an interactive heatmap visualization."""
 70 |     js_src = resource_string('iventure.jsviz', 'heatmap.js')
 71 | 
 72 |     pivot = df.pivot(
 73 |         index=df.columns[-3],
 74 |         columns=df.columns[-2],
 75 |         values=df.columns[-1],
 76 |     )
 77 |     pivot.fillna(0, inplace=True)
 78 |     D = pivot.as_matrix()
 79 |     ordering = utils_plot._clustermap_ordering(D)
 80 |     labels = list(np.asarray(pivot.columns)[ordering[0]])
 81 |     return Javascript(
 82 |         js_src \
 83 |         + 'heatmap(' \
 84 |         + df.to_json(orient='split') \
 85 |         + ',' \
 86 |         + json.dumps(labels) \
 87 |         + ')'
 88 |     )
 89 | 
 90 | def interactive_pairplot(df, schema):
 91 |     """Create an interactive pairplot visualization."""
 92 |     js_src = resource_string('iventure.jsviz', 'pairplot.js')
 93 |     return Javascript(
 94 |         js_src \
 95 |         + ';pairplot(' \
 96 |         + df.to_json(orient='split') \
 97 |         + ',' \
 98 |         + json.dumps(schema) \
 99 |         + ')'
100 |     )
101 | 
102 | def interactive_scatter(df):
103 |     """Create an interactive scatter plot visualization."""
104 |     df.dropna(inplace=True)
105 |     js_src = resource_string('iventure.jsviz', 'scatter.js')
106 |     return Javascript(
107 |         js_src \
108 |         + ';scatter(' \
109 |         + df.to_json(orient='split') \
110 |         + ')'
111 |     )
112 | 


--------------------------------------------------------------------------------
/src/jsviz/pairplot.js:
--------------------------------------------------------------------------------
 1 | function pairplot(df, schema) {
 2 |   var myCell = element.is('.output_subarea') ? element : element.next();
 3 |   if (typeof VizGPMReady === 'undefined') {
 4 |     throw new Error('VizGPM Display Library not loaded')
 5 |   }
 6 | 
 7 |   var container = $('
') 8 | .appendTo(myCell); 9 | 10 | VizGPMReady.then(function(VizGPM) { 11 | const _ = VizGPM._; 12 | 13 | const SP = VizGPM.StateProperty 14 | 15 | for (const col of schema) { 16 | if (col.stat_type == 'numerical') { 17 | col.stat_type = 'realAdditive'; 18 | } 19 | 20 | if (col.stat_type == 'nominal') { 21 | col.stat_type = 'categorical'; 22 | } 23 | } 24 | 25 | function rowProxy(__key) { 26 | const obj = {__key}; 27 | for (const column of df.columns) { 28 | obj[column] = df.data[__key].shift(); 29 | } 30 | return obj; 31 | } 32 | 33 | const rows = []; 34 | for(let index = 0; index < df.data.length; index++) { 35 | rows.push(rowProxy(index)); 36 | } 37 | 38 | var stateManager = new VizGPM.StateManager({ 39 | [SP.SCHEMA]: {columns: schema}, 40 | [SP.SELECTED_COLUMN_NAMES]: df.columns, 41 | [SP.GET_COLUMN_FUNCTION]: col => 42 | VizGPM.GpmHandler.prototype._getColumn.call(stateManager, col), 43 | [SP.DISPLAYED_ROWS]: rows, 44 | }); 45 | 46 | const plot = new VizGPM.PairPlot({ 47 | root: container[0], 48 | stateManager: stateManager, 49 | }); 50 | }) 51 | } 52 | -------------------------------------------------------------------------------- /src/jsviz/scatter.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2016, MIT Probabilistic Computing Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | function scatter(df) { 16 | var myCell = element.is('.output_subarea') ? element : element.next(); 17 | 18 | // Validate input format. It should be a pandas dataframe in "split" format: 19 | // df.to_json(orient="split") 20 | 21 | if (!(df.columns && df.index && df.data)) { 22 | throw new Error("Incorrect data format"); 23 | } 24 | 25 | if (df.columns.length < 2 || df.columns.length > 3) { 26 | debugger; 27 | throw new Error("There must be two or three columns"); 28 | } 29 | 30 | if (!df.data.length) { 31 | throw new Error("No data in the table"); 32 | } 33 | 34 | if (typeof df.data[0][1] !== 'number') { 35 | throw new Error("Expected second column to contain a number"); 36 | } 37 | 38 | const [ xName, yName, colorName ] = df.columns; 39 | const container = $("
").css({ display: 'flex', flexDiection: 'row' }).appendTo(myCell.empty()); 40 | 41 | 42 | function $s(elem) { 43 | return $(document.createElementNS('http://www.w3.org/2000/svg', elem)); 44 | } 45 | const svg = $s('svg').attr({ width: 15, height: 500 }) 46 | .append($s('text').attr({transform: "rotate(270) translate(-250 12)", size:"12", style: "fill: #000000", 'text-anchor': "middle", 'font-weight': 'bold'}).text(yName)); 47 | 48 | $('
').append(svg).appendTo(container); 49 | 50 | const middleContainer = $('
').appendTo(container); 51 | middleContainer.append($('
').text(xName)); 52 | 53 | VizGPMReady 54 | .then(VizGPM => { 55 | const _ = VizGPM._; 56 | const root = $("
").css({ display: 'inline-block', width: 500, verticalAlign: 'top' }).prependTo(middleContainer)[0]; 57 | 58 | const xValue = d => d[0]; 59 | const yValue = d => d[1]; 60 | 61 | const colorValue = d => d[2]; 62 | 63 | const rows = df.data 64 | 65 | const size = 500; 66 | 67 | // TODO: when we are compiling this, we should be able to use d3 here... 68 | const categories = new Set(rows.map(colorValue)); 69 | const isCategory = Boolean(colorName); 70 | // http://colorbrewer2.org/?type=qualitative&scheme=Set3&n=12 71 | const colors = [ 72 | 'rgba(141,211,199,0.9)', 73 | 'rgba(251,128,114,0.9)', 74 | 'rgba(128,177,211,0.9)', 75 | 'rgba(253,180,98,0.9)', 76 | 'rgba(179,222,105,0.9)', 77 | 'rgba(252,205,229,0.9)', 78 | 'rgba(217,217,217,0.9)', 79 | 'rgba(188,128,189,0.9)', 80 | 'rgba(204,235,197,0.9)', 81 | 'rgba(255,237,111,0.9)', 82 | 'rgba(190,186,218,0.9)', 83 | 'rgba(255,255,179,0.9)', 84 | ]; 85 | 86 | const colorMap = new Map([...categories].map((value, index) => [value, colors[index]])); 87 | 88 | if (isCategory) { 89 | const legend = $("
    ").css({ margin: 0, padding: 0, listStyle: 'none' }).appendTo(container); 90 | $("").text(df.columns[2]).wrap("
  • ").parent().appendTo(legend); 91 | for(const [category, color] of colorMap.entries()) { 92 | const item = $("
  • ").appendTo(legend); 93 | $("
    ") 94 | .css({ width: '20px', height: '20px', display: 'inline-block', background: color, border: '1px solid #000', verticalAlign: 'middle', margin: '0.25em 0.75em'}) 95 | .appendTo(item); 96 | $("").text(category).appendTo(item); 97 | } 98 | 99 | } 100 | const colorBy = isCategory ? 101 | d => colorMap.get(colorValue(d)) || '#000000' : 102 | undefined; 103 | 104 | var scatter = new VizGPM.Charts.ScatterPlot({ 105 | root, 106 | rows, 107 | size, 108 | pointRadius: 3, 109 | margin: { 110 | bottom: Math.floor(Math.max(size/6, 35)), 111 | left: Math.floor(Math.max(size/12, 35)), 112 | top: 0, 113 | right: 0, 114 | }, 115 | aesthetics: [{ 116 | name: xName, 117 | value: xValue, 118 | }, { 119 | name: yName, 120 | value: yValue, 121 | }], 122 | // This is currently a custom-hack in the built vizgpm we are using 123 | colorBy, 124 | scales: { 125 | x: VizGPM.Charts.Scales.SCALE_METHOD.linear(), 126 | y: VizGPM.Charts.Scales.SCALE_METHOD.linear(), 127 | }, 128 | }); 129 | 130 | scatter.render(); 131 | }) 132 | .catch(e => { 133 | const stack = $("") 134 | .css({ whiteSpace: "pre", display: "block", color: "red", overflow: "auto" }) 135 | .text(e.stack); 136 | debugger; 137 | myCell.append("Error initializing chart:", stack); 138 | }) 139 | } 140 | -------------------------------------------------------------------------------- /src/jupyter/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probcomp/iventure/5c0818f82ae2e20d7657e4ab96f42dc59f4ff60b/src/jupyter/__init__.py -------------------------------------------------------------------------------- /src/jupyter/magics.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright (c) 2010-2016, MIT Probabilistic Computing Project 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | from iventure.magics import * 18 | -------------------------------------------------------------------------------- /src/sessions.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright (c) 2010-2016, MIT Probabilistic Computing Project 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import datetime 18 | import os 19 | import random 20 | 21 | from collections import namedtuple 22 | 23 | 24 | # `output` is either `None` or a `pandas.DataFrame`. 25 | # `exception` is the currently traceback string. 26 | LogEntry = namedtuple('LogEntry', ['type', 'input', 'output', 'exception']) 27 | 28 | class TextLogger(object): 29 | 30 | def new_session(self, username, session_id, root): 31 | # XXX Is username being used? 32 | home = os.path.expanduser('~') 33 | if not os.path.exists(os.path.join(home, root)): 34 | os.mkdir(os.path.join(home, root)) 35 | self.filename = os.path.join(home, root, session_id + '.txt') 36 | 37 | def log(self, time, counter, entry): 38 | with open(self.filename, 'a') as f: 39 | f.write('---\n') 40 | self._write_entry(f, 'TIME', time) 41 | self._write_entry(f, 'COUNTER', str(counter)) 42 | self._write_entry(f, 'TYPE', entry.type) 43 | self._write_entry(f, 'INPUT', entry.input) 44 | self._write_entry( 45 | f, 'OUTPUT', self._convert_output(entry.output)) 46 | self._write_entry( 47 | f, 'EXCEPTION', self._convert_exception(entry.exception)) 48 | 49 | def _write_entry(self, f, label, entry): 50 | f.write(':' + label + ':' + entry + '\n') 51 | 52 | def _convert_output(self, output): 53 | # For pandas objects (series/dataframes) use the pretty-print method. 54 | # Otherwise convert output to a string using it __str__ and return it. 55 | try: 56 | return output.to_string().encode('utf-8') 57 | except AttributeError: 58 | return str(output) 59 | 60 | def _convert_exception(self, exception): 61 | return '' if exception is None else exception 62 | 63 | # TODO implement DBLogger which takes a .db file as input 64 | 65 | class Session(object): 66 | 67 | def __init__(self, username, loggers, root): 68 | self.loggers = loggers 69 | self.counter = 0 70 | # XXX Global random state! 71 | rand = str(random.choice('0123456789ABCDEF')) 72 | session_id = \ 73 | username + '_' + datetime.datetime.now().isoformat() + '_' + rand 74 | for logger in self.loggers: 75 | logger.new_session(username, session_id, root) 76 | print 'session_id: %s' % (session_id,) 77 | 78 | def log(self, entry): 79 | self.counter += 1 80 | time = datetime.datetime.now().isoformat() 81 | for logger in self.loggers: 82 | logger.log(time, self.counter, entry) 83 | -------------------------------------------------------------------------------- /src/utils_bql.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright (c) 2010-2016, MIT Probabilistic Computing Project 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import itertools 18 | 19 | import pandas as pd 20 | import numpy as np 21 | 22 | from bayeslite import bql_quote_name 23 | 24 | from bayeslite.core import bayesdb_has_table 25 | from bayeslite.core import bayesdb_table_column_names 26 | from bayeslite.core import bayesdb_table_has_column 27 | 28 | from bayeslite.util import cursor_value 29 | from bayeslite.util import casefold 30 | 31 | 32 | def nullify(bdb, table, value): 33 | """Replace specified values in a SQL table with ``NULL``.""" 34 | qtable = bql_quote_name(table) 35 | cursor = bdb.sql_execute('pragma table_info(%s)' % (qtable,)) 36 | columns = [row[1] for row in cursor] 37 | if value == '\'\'': 38 | sql = 'UPDATE %s SET {0} = NULL WHERE {0} = \'\'' % (qtable,) 39 | else: 40 | sql = 'UPDATE %s SET {0} = NULL WHERE {0} = ?' % (qtable,) 41 | cells_changed = 0 42 | for col in columns: 43 | qcol = bql_quote_name(col) 44 | old_changes = bdb._sqlite3.totalchanges() 45 | bdb.sql_execute(sql.format(qcol), (value,)) 46 | rows_changed = bdb._sqlite3.totalchanges() - old_changes 47 | cells_changed += rows_changed 48 | return cells_changed 49 | 50 | 51 | def cardinality(bdb, table, columns=None): 52 | """Compute the number of unique values in the columns of a table.""" 53 | qtable = bql_quote_name(table) 54 | # If no columns specified then use all. 55 | if not columns: 56 | cursor = bdb.sql_execute('PRAGMA table_info(%s)' % (qtable,)) 57 | columns = [row[1] for row in cursor] 58 | names = [] 59 | counts = [] 60 | for column in columns: 61 | qcolumn = bql_quote_name(column) 62 | cursor = bdb.sql_execute(''' 63 | SELECT COUNT (DISTINCT %s) FROM %s 64 | ''' % (qcolumn, qtable)) 65 | names.append(column) 66 | counts.append(cursor_value(cursor)) 67 | return pd.DataFrame({'name': names, 'distinct_count': counts}) 68 | 69 | 70 | def cursor_to_df(cursor): 71 | """Converts SQLite3 cursor to a pandas DataFrame.""" 72 | # Perform in savepoint to enable caching from row to row in BQL queries. 73 | with cursor.connection.savepoint(): 74 | df = pd.DataFrame.from_records(cursor, coerce_float=True) 75 | if not df.empty: 76 | df.columns = [desc[0] for desc in cursor.description] 77 | for col in df.columns: 78 | try: 79 | df[col] = df[col].astype(float) 80 | except ValueError: 81 | pass 82 | return df 83 | 84 | 85 | def query(bdb, bql, bindings=None, logger=None): 86 | """Execute the `bql` query on the `bdb` instance.""" 87 | if bindings is None: 88 | bindings = () 89 | if logger: 90 | logger.info("BQL [%s] %s", bql, bindings) 91 | cursor = bdb.execute(bql, bindings) 92 | return cursor_to_df(cursor) 93 | 94 | 95 | def subsample_table_columns(bdb, table, new_table, limit, keep, drop, seed): 96 | """Return a subsample of the columns in the table.""" 97 | if not bayesdb_has_table(bdb, table): 98 | raise ValueError('No such table: %s' % (table,)) 99 | if bayesdb_has_table(bdb, new_table): 100 | raise ValueError('Table already exists: %s' % (new_table,)) 101 | keep = map(casefold, keep) 102 | drop = map(casefold, drop) 103 | skip = keep + drop 104 | unknown = [ 105 | column for column in skip 106 | if not bayesdb_table_has_column(bdb, table, column) 107 | ] 108 | if unknown: 109 | raise ValueError('No such columns: %s' % (unknown,)) 110 | overlap = [column for column in drop if column in keep] 111 | if overlap: 112 | raise ValueError('Cannot both drop and keep columns: %s' % (overlap,)) 113 | num_sample = limit - len(keep) 114 | if num_sample < 0: 115 | raise ValueError('Must sample at least as many columns to keep.') 116 | subselect_columns = [ 117 | column for column in bayesdb_table_column_names(bdb, table) 118 | if casefold(column) not in skip 119 | ] 120 | rng = np.random.RandomState(seed) 121 | subsample_columns = rng.choice( 122 | subselect_columns, 123 | replace=False, 124 | size=min(len(subselect_columns), num_sample) 125 | ) 126 | qt = bql_quote_name(table) 127 | qnt = bql_quote_name(new_table) 128 | qc = ','.join(map(bql_quote_name, itertools.chain(keep, subsample_columns))) 129 | cursor = bdb.execute(''' 130 | CREATE TABLE %s AS SELECT %s FROM %s 131 | ''' % (qnt, qc, qt)) 132 | return cursor_to_df(cursor) 133 | -------------------------------------------------------------------------------- /src/utils_mml.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright (c) 2010-2016, MIT Probabilistic Computing Project 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import StringIO 18 | 19 | from bayeslite import bql_quote_name 20 | from bayeslite.core import bayesdb_get_population 21 | from bayeslite.core import bayesdb_population_table 22 | from bayeslite.core import bayesdb_variable_names 23 | from bayeslite.core import bayesdb_variable_number 24 | from bayeslite.core import bayesdb_variable_stattype 25 | from bayeslite.exception import BQLError 26 | 27 | from iventure import utils_bql 28 | 29 | 30 | def guess_schema(bdb, table, reasons): 31 | """Returns a guessed MML schema for a population derived from `table`.""" 32 | df = utils_bql.query(bdb, 'GUESS SCHEMA FOR %s' % (table,)) 33 | columns = df['column'].tolist() 34 | stattypes = df['stattype'].tolist() 35 | reasons = df['reason'].tolist() if reasons else [''] * len(columns) 36 | 37 | guesses = { 38 | c: [stattypes[i], reasons[i]] 39 | for i, c in enumerate(columns) 40 | } 41 | 42 | schema = StringIO.StringIO() 43 | nominal = [] 44 | numerical = [] 45 | ignore = [] 46 | unknown = [] 47 | 48 | for col in guesses.keys(): 49 | if len(col) == 0: 50 | raise BQLError(bdb, 51 | 'Empty column name(s) in table %s' % (table,)) 52 | guessed_type_reason = guesses[col] 53 | stattype = guessed_type_reason[0].lower() 54 | reason = guessed_type_reason[1] 55 | if stattype == 'nominal': 56 | nominal.append([col, reason]) 57 | elif stattype == 'numerical': 58 | numerical.append([col, reason]) 59 | elif stattype == 'ignore': 60 | ignore.append([col, reason]) 61 | elif stattype == 'key': 62 | ignore.append([col, reason]) 63 | else: 64 | unknown.append([col, reason]) 65 | 66 | if unknown: 67 | raise ValueError('Unknown guessed stattypes: %s' % (repr(unknown),)) 68 | 69 | stattype_columns_pairs = [ 70 | ['NOMINAL', nominal], 71 | ['NUMERICAL', numerical], 72 | ['IGNORE', ignore] 73 | ] 74 | 75 | for i, [stattype, columns] in enumerate(stattype_columns_pairs): 76 | if not columns: 77 | continue 78 | schema.write('IGNORE' if stattype == 'IGNORE' else 'MODEL \n') 79 | for j in xrange(len(columns)): 80 | [col, reason] = columns[j] 81 | schema.write('\t %s' % (bql_quote_name(col),)) 82 | # Do not append a comma for last item in list. 83 | if j < len(columns) - 1: 84 | schema.write(',') 85 | # Add space between the last variable and 'AS' for proper parsing. 86 | else: 87 | schema.write(' ') 88 | if len(reason) > 0: 89 | schema.write(" # %s" % (reason,)) 90 | schema.write('\n') 91 | if stattype != 'IGNORE': 92 | schema.write('AS \n\t%s' %(stattype,)) 93 | if i < len(stattype_columns_pairs) - 1: 94 | schema.write(';\n') 95 | 96 | result = schema.getvalue() 97 | schema.close() 98 | return result 99 | 100 | def get_schema_as_list(bdb, population_name): 101 | population_id = bayesdb_get_population(bdb, population_name) 102 | table_name = bayesdb_population_table(bdb, population_id) 103 | qt = bql_quote_name(table_name) 104 | variable_names = bayesdb_variable_names(bdb, population_id, None) 105 | schema = [] 106 | for variable_name in variable_names: 107 | colno = bayesdb_variable_number( 108 | bdb, population_id, None, variable_name) 109 | stattype = bayesdb_variable_stattype(bdb, population_id, None, colno) 110 | stattype_lookup = { 111 | 'numerical' : 'realAdditive', 112 | 'nominal' : 'categorical', 113 | 'categorical' : 'categorical', 114 | } 115 | schema_entry = { 116 | 'name' : variable_name, 117 | 'stat_type' : stattype_lookup[stattype] 118 | } 119 | if stattype == 'nominal': 120 | qv = bql_quote_name(variable_name) 121 | values = utils_bql.query(bdb, ''' 122 | SELECT DISTINCT(%s) FROM %s 123 | WHERE %s IS NOT NULL 124 | ''' % (qv, qt, qv,)) 125 | schema_entry['unique_values'] = \ 126 | values[values.columns[0]].unique().tolist() 127 | schema.append(schema_entry) 128 | return schema 129 | -------------------------------------------------------------------------------- /src/utils_sql.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright (c) 2010-2016, MIT Probabilistic Computing Project 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | from StringIO import StringIO 18 | 19 | from bayeslite import bql_quote_name 20 | 21 | 22 | def regression_to_sql(df, table=None): 23 | """Convert df output of BQL REGRESS to a SQL SELECT query.""" 24 | if df.shape[1] != 2: 25 | raise ValueError('Exactly two columns required.') 26 | variables = df[df.columns[0]] 27 | coefficients = df[df.columns[1]] 28 | 29 | intercept = coefficients[variables=='intercept'].iloc[0] 30 | 31 | numericals = { 32 | var: coefficients[variables==var].iloc[0] 33 | for var in variables 34 | if '_dum_' not in var and var != 'intercept' 35 | } 36 | 37 | nominals = set([c.split('_dum_')[0] for c in variables if '_dum_' in c]) 38 | categories = { 39 | var : { 40 | v.split('_dum_')[1]: coefficients[variables==v].iloc[0] 41 | for v in variables if '%s_dum_' % (var,) in v 42 | } 43 | for var in nominals 44 | } 45 | 46 | def compile_numerical(variable, coefficient): 47 | return '%1.4f * %s' % (coefficient, bql_quote_name(variable)) 48 | def compile_nominal_case(variable, categories): 49 | cases = str.join('\n', [ 50 | '\t\t\tWHEN \'%s\' THEN %1.4f' % (category, coefficient) 51 | for category, coefficient in categories.iteritems() 52 | ]) 53 | return 'CASE %s\n%s\n\t\t\tELSE NULL\n\t\tEND'\ 54 | % (bql_quote_name(variable), cases,) 55 | 56 | # Write query to the buffer. 57 | out = StringIO() 58 | # SELECT 59 | out.write('SELECT\n\t\t') 60 | # Intercept. 61 | out.write('%1.4f\n\t' % (intercept,)) 62 | # Numerical variables. 63 | out.writelines([ 64 | '+\t%s\n\t' % (compile_numerical(var, coef)) 65 | for var, coef in numericals.iteritems() 66 | ]) 67 | # Nominal variables. 68 | for i, variable in enumerate(categories): 69 | out.write('+\t%s'% compile_nominal_case(variable, categories[variable])) 70 | out.write('\n') 71 | if i < len(categories) - 1: 72 | out.write('\t') 73 | # FROM table. 74 | if table: 75 | out.write('\rFROM %s' % (bql_quote_name(table),)) 76 | return out.getvalue() 77 | -------------------------------------------------------------------------------- /src/utils_unix.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright (c) 2010-2016, MIT Probabilistic Computing Project 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import os 18 | import sqlite3 19 | import subprocess 20 | 21 | import notebook.auth 22 | 23 | 24 | FNULL = open(os.devnull, 'w') 25 | 26 | 27 | def unix_group_exists(groupname): 28 | retcode = subprocess.call([ 29 | 'egrep', 30 | '-i', 31 | '^%s' % (groupname,), 32 | '/etc/group' 33 | ], stdout=FNULL, stderr=FNULL) 34 | return True if retcode == 0 else False 35 | 36 | 37 | def unix_port_active(port): 38 | result = subprocess.check_output( 39 | 'nc -s0 127.0.0.1 %d >/dev/null