Skip to content

Commit d625a70

Browse files
committed
Merge pull request #13 from phobson/diy-plotting-positions
DIY plotting positions
2 parents d49619d + 078b87b commit d625a70

27 files changed

+561
-110
lines changed

.travis.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ matrix:
88
- python: 3.4
99
env:
1010
- COVERAGE=false
11+
- python: 3.5
12+
env:
13+
- COVERAGE=false
1114
- python: 3.5
1215
env:
1316
- COVERAGE=true
@@ -29,7 +32,8 @@ install:
2932

3033
- conda create --yes -n test python=$TRAVIS_PYTHON_VERSION
3134
- source activate test
32-
- conda install --yes numpy nose scipy matplotlib coverage docopt requests pyyaml
35+
- conda install --yes numpy nose matplotlib coverage docopt requests pyyaml
36+
- if [ ${COVERAGE} = true ]; then conda install scipy --yes; fi
3337
- pip install coveralls
3438
- pip install .
3539

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,15 @@ seaborn.despine(fig=fig)
3232
```
3333

3434
![Alt text](docs/img/example.png "Example axes")
35+
36+
## Testing
37+
38+
Testing is generally done via the ``nose`` and ``numpy.testing`` modules.
39+
The best way to run the tests is in an interactive python session:
40+
41+
```python
42+
import matplotlib
43+
matplotib.use('agg')
44+
import probscale
45+
probscale.test()
46+
```
File renamed without changes.
File renamed without changes.

conda.recipe/dev/meta.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package:
2+
name: mpl-probscale
3+
version: 0.1.1
4+
5+
source:
6+
path: ../../
7+
# patches:
8+
# List any patch files here
9+
# - fix.patch
10+
11+
build:
12+
number: 1
13+
14+
requirements:
15+
build:
16+
- python
17+
- numpy
18+
- matplotlib
19+
20+
run:
21+
- python
22+
- numpy
23+
- matplotlib
24+
- nose
25+
26+
test:
27+
imports:
28+
- probscale
29+
30+
commands:
31+
- python -c "import matplotlib; matplotlib.use('agg'); import probscale; probscale.test()"
32+
33+
requires:
34+
- nose
35+
- scipy
36+
37+
about:
38+
home: http://phobson.github.io/mpl-probscale/
39+
license: BSD License
40+
summary: 'Probability scales for matplotlib.'
41+
42+
# See
43+
# http://docs.continuum.io/conda/build.html for
44+
# more information about meta.yaml/configure

conda.recipe/release/bld.bat

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"%PYTHON%" setup.py install
2+
if errorlevel 1 exit 1
3+
4+
:: Add more build steps here, if they are necessary.
5+
6+
:: See
7+
:: http://docs.continuum.io/conda/build.html
8+
:: for a list of environment variables that are set during the build process.

conda.recipe/release/build.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
$PYTHON setup.py install
4+
5+
# Add more build steps here, if they are necessary.
6+
7+
# See
8+
# http://docs.continuum.io/conda/build.html
9+
# for a list of environment variables that are set during the build process.

conda.recipe/meta.yaml conda.recipe/release/meta.yaml

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package:
22
name: mpl-probscale
3-
version: v0.1.0
3+
version: 0.1.1
44

55
source:
66
git_url: https://github.com/phobson/mpl-probscale.git
7-
git_tag: v0.1.0
7+
git_tag: v0.1.1
88
# patches:
99
# List any patch files here
1010
# - fix.patch
@@ -17,23 +17,19 @@ requirements:
1717
- python
1818
- numpy
1919
- matplotlib
20-
- scipy
2120

2221
run:
2322
- python
2423
- numpy
2524
- matplotlib
26-
- scipy
25+
- nose
2726

2827
test:
2928
imports:
3029
- probscale
3130

3231
commands:
33-
- nosetests
34-
35-
requires:
36-
- nose
32+
- python -c "import matplotlib; matplotlib.use('agg'); import probscale; probscale.test()"
3733

3834
about:
3935
home: http://phobson.github.io/mpl-probscale/

docs/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@
7676
# built documents.
7777
#
7878
# The short X.Y version.
79-
version = '0.1.0'
79+
version = '0.1.1'
8080
# The full version, including alpha/beta/rc tags.
81-
release = '0.1.0'
81+
release = '0.1.1'
8282

8383
# The language for content autogenerated by Sphinx. Refer to documentation
8484
# for a list of supported languages.

docs/index.rst

+14-5
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,31 @@ Tutorial
5454

5555
tutorial/getting_started.rst
5656

57+
Testing
58+
-------
59+
60+
It's easiest to run the tests from an interactive python session:
61+
62+
.. code-block:: python
63+
64+
import matplotlib
65+
matplotlib.use('agg')
66+
import probscale
67+
probscale.test()
68+
69+
5770
API References
5871
--------------
5972

6073
.. toctree::
6174
:maxdepth: 2
6275

63-
probscale.rst
6476
viz.rst
65-
66-
67-
77+
probscale.rst
6878

6979
Indices and tables
7080
==================
7181

7282
* :ref:`genindex`
7383
* :ref:`modindex`
7484
* :ref:`search`
75-

docs/tutorial/getting_started.ipynb

+49-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Getting started with `mpl-probscale`.\n",
7+
"# Getting started with `mpl-probscale`\n",
88
"\n",
99
"## Installation\n",
1010
"\n",
@@ -21,7 +21,7 @@
2121
"pip install .\n",
2222
"```\n",
2323
"\n",
24-
"I recommend `pip install .` over `python setup.py install` for [reasons I don't fully understand](https://github.com/numpy/numpy/issues/6551)."
24+
"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)."
2525
]
2626
},
2727
{
@@ -118,7 +118,7 @@
118118
"cell_type": "markdown",
119119
"metadata": {},
120120
"source": [
121-
"`mpl-probscale` let's you use probability scales. All you need to do is import it.\n",
121+
"`mpl-probscale` lets you use probability scales. All you need to do is import it.\n",
122122
"\n",
123123
"Before importing:"
124124
]
@@ -143,7 +143,7 @@
143143
"cell_type": "markdown",
144144
"metadata": {},
145145
"source": [
146-
"To access probability scales, simply import :py:mod:`probscale`."
146+
"To access probability scales, simply import `probscale`."
147147
]
148148
},
149149
{
@@ -167,11 +167,11 @@
167167
"cell_type": "markdown",
168168
"metadata": {},
169169
"source": [
170-
"Probability scales default to the standard normal distribution (ote that the formatting is a percentage-based probability)\n",
170+
"Probability scales default to the standard normal distribution (note that the formatting is a percentage-based probability)\n",
171171
"\n",
172-
"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",
172+
"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",
173173
"\n",
174-
"Here's a standard normal scale right next to two different beta scales for comparison"
174+
"Here's a standard normal scale with two different beta scales and a linear scale for comparison."
175175
]
176176
},
177177
{
@@ -182,23 +182,20 @@
182182
},
183183
"outputs": [],
184184
"source": [
185-
"import paramnormal\n",
186-
"seaborn.set(style='ticks', context='notebook', rc=clear_bkgd)\n",
187-
"\n",
188-
"fig, (ax1, ax2, ax3, ax4) = pyplot.subplots(figsize=(8, 6), nrows=4)\n",
185+
"fig, (ax1, ax2, ax3, ax4) = pyplot.subplots(figsize=(8, 4), nrows=4)\n",
189186
"\n",
190187
"ax1.set_xscale('prob')\n",
191188
"ax1.set_xlim(left=2, right=98)\n",
192189
"ax1.set_xlabel('Normal probability scale, as percents')\n",
193190
"ax1.set_yticks([])\n",
194191
"\n",
195-
"beta1 = paramnormal.beta(α=3, β=2)\n",
192+
"beta1 = stats.beta(a=3, b=2)\n",
196193
"ax2.set_xscale('prob', dist=beta1)\n",
197194
"ax2.set_xlim(left=2, right=98)\n",
198195
"ax2.set_xlabel('Beta probability scale (α=3, β=2)')\n",
199196
"ax2.set_yticks([])\n",
200197
"\n",
201-
"beta2 = paramnormal.beta(α=2, β=7)\n",
198+
"beta2 = stats.beta(a=2, b=7)\n",
202199
"ax3.set_xscale('prob', dist=beta2)\n",
203200
"ax3.set_xlim(left=2, right=98)\n",
204201
"ax3.set_xlabel('Beta probability scale (α=2, β=7)')\n",
@@ -231,7 +228,7 @@
231228
"outputs": [],
232229
"source": [
233230
"numpy.random.seed(0)\n",
234-
"sample = paramnormal.normal(μ=4, σ=2).rvs(size=37)\n",
231+
"sample = numpy.random.normal(loc=4, scale=2, size=37)\n",
235232
"\n",
236233
"fig = probscale.probplot(sample)\n",
237234
"seaborn.despine(fig=fig)"
@@ -281,7 +278,7 @@
281278
"fig, ax = pyplot.subplots(figsize=(3, 7))\n",
282279
"\n",
283280
"numpy.random.seed(0)\n",
284-
"new_sample = paramnormal.lognormal(μ=2.0, σ=0.75).rvs(size=37)\n",
281+
"new_sample = numpy.random.lognormal(mean=2.0, sigma=0.75, size=37)\n",
285282
"\n",
286283
"probscale.probplot(\n",
287284
" new_sample,\n",
@@ -325,11 +322,46 @@
325322
},
326323
"outputs": [],
327324
"source": [
328-
"fig, (ax1, ax2) = pyplot.subplots(ncols=2, figsize=(7, 2))\n",
325+
"fig, (ax1, ax2, ax3) = pyplot.subplots(nrows=3, figsize=(5.5, 7))\n",
326+
"\n",
329327
"probscale.probplot(sample, ax=ax1, axtype='pp', xlabel='Percentiles')\n",
330328
"probscale.probplot(sample, ax=ax2, axtype='qq', xlabel='Quantiles')\n",
329+
"probscale.probplot(sample, ax=ax3, axtype='prob', xlabel='Probabilities')\n",
330+
"\n",
331+
"ax2.set_xlim(left=-2.5, right=2.5)\n",
332+
"ax3.set_xlim(left=0.5, right=99.5)\n",
333+
"fig.tight_layout()\n",
331334
"seaborn.despine(fig=fig)"
332335
]
336+
},
337+
{
338+
"cell_type": "markdown",
339+
"metadata": {},
340+
"source": [
341+
"### Working with seaborn `FacetGrids`\n",
342+
"\n",
343+
"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)."
344+
]
345+
},
346+
{
347+
"cell_type": "code",
348+
"execution_count": null,
349+
"metadata": {
350+
"collapsed": false,
351+
"scrolled": false
352+
},
353+
"outputs": [],
354+
"source": [
355+
"plot = (\n",
356+
" seaborn.load_dataset(\"tips\")\n",
357+
" .assign(pct=lambda df: 100 * df['tip'] / df['total_bill'])\n",
358+
" .pipe(seaborn.FacetGrid, hue='time', col='sex', row='smoker', margin_titles=True, aspect=1.75)\n",
359+
" .map(probscale.probplot, 'pct', bestfit=True, otherscale='log', scatter_kws=dict(alpha=0.75))\n",
360+
" .add_legend()\n",
361+
" .set_xlabels('Non-Exceedance Probabilty')\n",
362+
" .set_ylabels('Tips as percent of total bill')\n",
363+
")"
364+
]
333365
}
334366
],
335367
"metadata": {
@@ -353,4 +385,4 @@
353385
},
354386
"nbformat": 4,
355387
"nbformat_minor": 0
356-
}
388+
}

probscale/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
from .probscale import ProbScale
55

66
scale.register_scale(ProbScale)
7+
8+
from numpy.testing import Tester
9+
test = Tester().test
Loading
Loading
Loading
Loading
Loading
Loading

probscale/tests/test_probscale.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
import numpy as np
55
import matplotlib.pyplot as plt
6-
from scipy import stats
6+
7+
try:
8+
from scipy import stats
9+
except:
10+
stats = None
711

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

9296

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

0 commit comments

Comments
 (0)