Skip to content

Commit

Permalink
Merge pull request #13 from phobson/diy-plotting-positions
Browse files Browse the repository at this point in the history
DIY plotting positions
  • Loading branch information
phobson committed Apr 20, 2016
2 parents d49619d + 078b87b commit d625a70
Show file tree
Hide file tree
Showing 27 changed files with 561 additions and 110 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ matrix:
- python: 3.4
env:
- COVERAGE=false
- python: 3.5
env:
- COVERAGE=false
- python: 3.5
env:
- COVERAGE=true
Expand All @@ -29,7 +32,8 @@ install:

- conda create --yes -n test python=$TRAVIS_PYTHON_VERSION
- source activate test
- conda install --yes numpy nose scipy matplotlib coverage docopt requests pyyaml
- conda install --yes numpy nose matplotlib coverage docopt requests pyyaml
- if [ ${COVERAGE} = true ]; then conda install scipy --yes; fi
- pip install coveralls
- pip install .

Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ seaborn.despine(fig=fig)
```

![Alt text](docs/img/example.png "Example axes")

## Testing

Testing is generally done via the ``nose`` and ``numpy.testing`` modules.
The best way to run the tests is in an interactive python session:

```python
import matplotlib
matplotib.use('agg')
import probscale
probscale.test()
```
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions conda.recipe/dev/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package:
name: mpl-probscale
version: 0.1.1

source:
path: ../../
# patches:
# List any patch files here
# - fix.patch

build:
number: 1

requirements:
build:
- python
- numpy
- matplotlib

run:
- python
- numpy
- matplotlib
- nose

test:
imports:
- probscale

commands:
- python -c "import matplotlib; matplotlib.use('agg'); import probscale; probscale.test()"

requires:
- nose
- scipy

about:
home: http://phobson.github.io/mpl-probscale/
license: BSD License
summary: 'Probability scales for matplotlib.'

# See
# http://docs.continuum.io/conda/build.html for
# more information about meta.yaml/configure
8 changes: 8 additions & 0 deletions conda.recipe/release/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"%PYTHON%" setup.py install
if errorlevel 1 exit 1

:: Add more build steps here, if they are necessary.

:: See
:: http://docs.continuum.io/conda/build.html
:: for a list of environment variables that are set during the build process.
9 changes: 9 additions & 0 deletions conda.recipe/release/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

$PYTHON setup.py install

# Add more build steps here, if they are necessary.

# See
# http://docs.continuum.io/conda/build.html
# for a list of environment variables that are set during the build process.
12 changes: 4 additions & 8 deletions conda.recipe/meta.yaml → conda.recipe/release/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package:
name: mpl-probscale
version: v0.1.0
version: 0.1.1

source:
git_url: https://github.com/phobson/mpl-probscale.git
git_tag: v0.1.0
git_tag: v0.1.1
# patches:
# List any patch files here
# - fix.patch
Expand All @@ -17,23 +17,19 @@ requirements:
- python
- numpy
- matplotlib
- scipy

run:
- python
- numpy
- matplotlib
- scipy
- nose

test:
imports:
- probscale

commands:
- nosetests

requires:
- nose
- python -c "import matplotlib; matplotlib.use('agg'); import probscale; probscale.test()"

about:
home: http://phobson.github.io/mpl-probscale/
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
# built documents.
#
# The short X.Y version.
version = '0.1.0'
version = '0.1.1'
# The full version, including alpha/beta/rc tags.
release = '0.1.0'
release = '0.1.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
19 changes: 14 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,31 @@ Tutorial

tutorial/getting_started.rst

Testing
-------

It's easiest to run the tests from an interactive python session:

.. code-block:: python
import matplotlib
matplotlib.use('agg')
import probscale
probscale.test()
API References
--------------

.. toctree::
:maxdepth: 2

probscale.rst
viz.rst



probscale.rst

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

66 changes: 49 additions & 17 deletions docs/tutorial/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Getting started with `mpl-probscale`.\n",
"# Getting started with `mpl-probscale`\n",
"\n",
"## Installation\n",
"\n",
Expand All @@ -21,7 +21,7 @@
"pip install .\n",
"```\n",
"\n",
"I recommend `pip install .` over `python setup.py install` for [reasons I don't fully understand](https://github.com/numpy/numpy/issues/6551)."
"I recommend `pip install .` over `python setup.py install` for [reasons I don't fully understand](https://github.com/numpy/numpy/issues/6551#issuecomment-150392865cd)."
]
},
{
Expand Down Expand Up @@ -118,7 +118,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"`mpl-probscale` let's you use probability scales. All you need to do is import it.\n",
"`mpl-probscale` lets you use probability scales. All you need to do is import it.\n",
"\n",
"Before importing:"
]
Expand All @@ -143,7 +143,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To access probability scales, simply import :py:mod:`probscale`."
"To access probability scales, simply import `probscale`."
]
},
{
Expand All @@ -167,11 +167,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Probability scales default to the standard normal distribution (ote that the formatting is a percentage-based probability)\n",
"Probability scales default to the standard normal distribution (note that the formatting is a percentage-based probability)\n",
"\n",
"You can even use different probability distributions, though it can be tricky. You have to pass a frozen distribution to the `dist` kwarg in `ax.set_[x|y]scale`.\n",
"You can even use different probability distributions, though it can be tricky. You have to pass a frozen distribution from either [scipy.stats](http://docs.scipy.org/doc/scipy/reference/stats.html#continuous-distributions) or [paramnormal](http://phobson.github.io/paramnormal/) to the `dist` kwarg in `ax.set_[x|y]scale`.\n",
"\n",
"Here's a standard normal scale right next to two different beta scales for comparison"
"Here's a standard normal scale with two different beta scales and a linear scale for comparison."
]
},
{
Expand All @@ -182,23 +182,20 @@
},
"outputs": [],
"source": [
"import paramnormal\n",
"seaborn.set(style='ticks', context='notebook', rc=clear_bkgd)\n",
"\n",
"fig, (ax1, ax2, ax3, ax4) = pyplot.subplots(figsize=(8, 6), nrows=4)\n",
"fig, (ax1, ax2, ax3, ax4) = pyplot.subplots(figsize=(8, 4), nrows=4)\n",
"\n",
"ax1.set_xscale('prob')\n",
"ax1.set_xlim(left=2, right=98)\n",
"ax1.set_xlabel('Normal probability scale, as percents')\n",
"ax1.set_yticks([])\n",
"\n",
"beta1 = paramnormal.beta(α=3, β=2)\n",
"beta1 = stats.beta(a=3, b=2)\n",
"ax2.set_xscale('prob', dist=beta1)\n",
"ax2.set_xlim(left=2, right=98)\n",
"ax2.set_xlabel('Beta probability scale (α=3, β=2)')\n",
"ax2.set_yticks([])\n",
"\n",
"beta2 = paramnormal.beta(α=2, β=7)\n",
"beta2 = stats.beta(a=2, b=7)\n",
"ax3.set_xscale('prob', dist=beta2)\n",
"ax3.set_xlim(left=2, right=98)\n",
"ax3.set_xlabel('Beta probability scale (α=2, β=7)')\n",
Expand Down Expand Up @@ -231,7 +228,7 @@
"outputs": [],
"source": [
"numpy.random.seed(0)\n",
"sample = paramnormal.normal(μ=4, σ=2).rvs(size=37)\n",
"sample = numpy.random.normal(loc=4, scale=2, size=37)\n",
"\n",
"fig = probscale.probplot(sample)\n",
"seaborn.despine(fig=fig)"
Expand Down Expand Up @@ -281,7 +278,7 @@
"fig, ax = pyplot.subplots(figsize=(3, 7))\n",
"\n",
"numpy.random.seed(0)\n",
"new_sample = paramnormal.lognormal(μ=2.0, σ=0.75).rvs(size=37)\n",
"new_sample = numpy.random.lognormal(mean=2.0, sigma=0.75, size=37)\n",
"\n",
"probscale.probplot(\n",
" new_sample,\n",
Expand Down Expand Up @@ -325,11 +322,46 @@
},
"outputs": [],
"source": [
"fig, (ax1, ax2) = pyplot.subplots(ncols=2, figsize=(7, 2))\n",
"fig, (ax1, ax2, ax3) = pyplot.subplots(nrows=3, figsize=(5.5, 7))\n",
"\n",
"probscale.probplot(sample, ax=ax1, axtype='pp', xlabel='Percentiles')\n",
"probscale.probplot(sample, ax=ax2, axtype='qq', xlabel='Quantiles')\n",
"probscale.probplot(sample, ax=ax3, axtype='prob', xlabel='Probabilities')\n",
"\n",
"ax2.set_xlim(left=-2.5, right=2.5)\n",
"ax3.set_xlim(left=0.5, right=99.5)\n",
"fig.tight_layout()\n",
"seaborn.despine(fig=fig)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Working with seaborn `FacetGrids`\n",
"\n",
"Good news, everyone. The ``probplot`` function generally works as expected with [FacetGrids](http://stanford.edu/~mwaskom/software/seaborn/tutorial/axis_grids.html#subsetting-data-with-facetgrid)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [],
"source": [
"plot = (\n",
" seaborn.load_dataset(\"tips\")\n",
" .assign(pct=lambda df: 100 * df['tip'] / df['total_bill'])\n",
" .pipe(seaborn.FacetGrid, hue='time', col='sex', row='smoker', margin_titles=True, aspect=1.75)\n",
" .map(probscale.probplot, 'pct', bestfit=True, otherscale='log', scatter_kws=dict(alpha=0.75))\n",
" .add_legend()\n",
" .set_xlabels('Non-Exceedance Probabilty')\n",
" .set_ylabels('Tips as percent of total bill')\n",
")"
]
}
],
"metadata": {
Expand All @@ -353,4 +385,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
3 changes: 3 additions & 0 deletions probscale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
from .probscale import ProbScale

scale.register_scale(ProbScale)

from numpy.testing import Tester
test = Tester().test
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified probscale/tests/baseline_images/test_viz/test_probplot_prob.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion probscale/tests/test_probscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

import numpy as np
import matplotlib.pyplot as plt
from scipy import stats

try:
from scipy import stats
except:
stats = None

from matplotlib.testing.decorators import image_comparison, cleanup
import nose.tools as nt
Expand Down Expand Up @@ -91,6 +95,7 @@ def test_the_scale_not_as_pct():


@image_comparison(baseline_images=['test_the_scale_beta'], extensions=['png'])
@nptest.dec.skipif(stats is None)
def test_the_scale_beta():
fig, ax = plt.subplots(figsize=(4, 8))
ax.set_yscale('prob', as_pct=True, dist=stats.beta(3, 2))
Expand Down
Loading

0 comments on commit d625a70

Please sign in to comment.