Skip to content

Commit 9c0fdba

Browse files
committed
Minor doc tweaks (titles, formatting, organization) (#19)
1 parent a671f14 commit 9c0fdba

File tree

9 files changed

+93
-27
lines changed

9 files changed

+93
-27
lines changed

docs/api/formatters.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. _formatters_auto:
2+
3+
The ``formatters`` API
4+
5+
``formatters`` API Reference
6+
============================
7+
8+
.. automodule:: probscale.formatters
9+
:members:
10+
:undoc-members:
11+
:show-inheritance:

docs/api/transforms.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. _transforms_auto:
2+
3+
The ``transforms`` API
4+
5+
``transforms`` API Reference
6+
============================
7+
8+
.. automodule:: probscale.transforms
9+
:members:
10+
:undoc-members:
11+
:show-inheritance:

docs/tutorial/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
notebooks:
22

3-
tools/nb_to_doc.py getting_started
3+
tools/nb_to_doc.py getting_started
44
tools/nb_to_doc.py closer_look_at_viz

docs/tutorial/closer_look_at_viz.ipynb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# A closer look probability plots\n",
7+
"# A closer look at probability plots\n",
88
"\n",
99
"## Overview\n",
1010
"\n",
@@ -39,6 +39,9 @@
3939
},
4040
"outputs": [],
4141
"source": [
42+
"import warnings\n",
43+
"warnings.simplefilter('ignore')\n",
44+
"\n",
4245
"import numpy\n",
4346
"from matplotlib import pyplot\n",
4447
"import seaborn\n",
@@ -520,28 +523,28 @@
520523
"\n",
521524
"The most common values can be selected via the ``postype`` parameter and are described as follows:\n",
522525
"\n",
523-
" \"type 4\" : (0, 1)\n",
526+
" \"type 4\" (α=2, β=1)\n",
524527
" Linear interpolation of the empirical CDF.\n",
525-
" \"type 5\" or \"hazen\" : (0.5, 0.5)\n",
528+
" \"type 5\" or \"hazen\" (α=0.5, β=0.5)\n",
526529
" Piecewise linear interpolation.\n",
527-
" \"type 6\" or \"weibull\" : (0, 0)\n",
530+
" \"type 6\" or \"weibull\" (α=0, β=0)\n",
528531
" Weibull plotting positions. Unbiased exceedance probability\n",
529532
" for all distributions. This is will be the default value.\n",
530-
" \"type 7\" : (1, 1)\n",
533+
" \"type 7\" (α=1, β=1)\n",
531534
" The default values in R.\n",
532-
" \"type 8\" : (1/3, 1/3)\n",
535+
" \"type 8\" (α=1/3, β=1/3)\n",
533536
" Approximately median-unbiased.\n",
534-
" \"type 9\" or \"blom\" : (0.375, 0.375)\n",
537+
" \"type 9\" or \"blom\" (α=0.375, β=0.375)\n",
535538
" Approximately unbiased positions if the data are normally\n",
536539
" distributed.\n",
537-
" \"median\" : (0.3175, 0.3175)\n",
540+
" \"median\" (α=0.3175, β=0.3175)\n",
538541
" Median exceedance probabilities for all distributions\n",
539542
" (used in ``scipy.stats.probplot``).\n",
540-
" \"apl\" or \"pwm\" : (0.35, 0.35)\n",
543+
" \"apl\" or \"pwm\" (α=0.35, β=0.35)\n",
541544
" Used with probability-weighted moments.\n",
542-
" \"cunnane\" : (0.4, 0.4)\n",
545+
" \"cunnane\" (α=0.4, β=0.4)\n",
543546
" Nearly unbiased quantiles for normally distributed data.\n",
544-
" \"gringorten\" : (0.44, 0.44)\n",
547+
" \"gringorten\" (α=0.44, β=0.44)\n",
545548
" Used for Gumble distributions.\n",
546549
" \n",
547550
"These are controlled via the `pp_kws` parameter in `probplot`"
@@ -661,4 +664,4 @@
661664
},
662665
"nbformat": 4,
663666
"nbformat_minor": 0
664-
}
667+
}

docs/tutorial/getting_started.ipynb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,27 +197,23 @@
197197
"source": [
198198
"fig, (ax1, ax2, ax3, ax4) = pyplot.subplots(figsize=(8, 4), nrows=4)\n",
199199
"\n",
200+
"for ax in [ax1, ax2, ax3, ax4]:\n",
201+
" ax.set_xlim(left=2, right=98)\n",
202+
" ax.set_yticks([])\n",
203+
"\n",
200204
"ax1.set_xscale('prob')\n",
201-
"ax1.set_xlim(left=2, right=98)\n",
202205
"ax1.set_xlabel('Normal probability scale, as percents')\n",
203-
"ax1.set_yticks([])\n",
204206
"\n",
205207
"beta1 = stats.beta(a=3, b=2)\n",
206208
"ax2.set_xscale('prob', dist=beta1)\n",
207-
"ax2.set_xlim(left=2, right=98)\n",
208209
"ax2.set_xlabel('Beta probability scale (α=3, β=2)')\n",
209-
"ax2.set_yticks([])\n",
210210
"\n",
211211
"beta2 = stats.beta(a=2, b=7)\n",
212212
"ax3.set_xscale('prob', dist=beta2)\n",
213-
"ax3.set_xlim(left=2, right=98)\n",
214213
"ax3.set_xlabel('Beta probability scale (α=2, β=7)')\n",
215-
"ax3.set_yticks([])\n",
216214
"\n",
217-
"ax4.set_xlim(left=2, right=98)\n",
218215
"ax4.set_xticks(ax1.get_xticks()[12:-12])\n",
219216
"ax4.set_xlabel('Linear scale (for reference)')\n",
220-
"ax4.set_yticks([])\n",
221217
"\n",
222218
"seaborn.despine(fig=fig, left=True)"
223219
]
@@ -398,4 +394,4 @@
398394
},
399395
"nbformat": 4,
400396
"nbformat_minor": 0
401-
}
397+
}

probscale/formatters.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33

44

55
class _FormatterMixin(Formatter):
6+
""" A mpl-axes formatter mixin class """
7+
68
@classmethod
79
def _sig_figs(cls, x, n, expthresh=5, forceint=False):
8-
""" Formats a number with the correct number of sig figs.
10+
"""
11+
Formats a number with the correct number of significant digits.
912
1013
Parameters
1114
----------
@@ -85,12 +88,22 @@ def __call__(self, x, pos=None):
8588

8689

8790
class PctFormatter(_FormatterMixin):
91+
"""
92+
Formatter class for MPL axes to display probalities as percentages.
93+
94+
"""
95+
8896
factor = 1.0
8997
offset = 2
9098
top = 100
9199

92100

93101
class ProbFormatter(_FormatterMixin):
102+
"""
103+
Formatter class for MPL axes to display probalities as decimals.
104+
105+
"""
106+
94107
factor = 100.0
95108
offset = 0
96109
top = 1

probscale/probscale.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313

1414
class _minimal_norm(object):
15+
"""
16+
A basic implmentation of a normal distribution, minimally
17+
API-complient with scipt.stats.norm
18+
19+
"""
20+
1521
_A = -(8 * (numpy.pi - 3.0) / (3.0 * numpy.pi * (numpy.pi - 4.0)))
1622

1723
@classmethod
@@ -71,10 +77,16 @@ class ProbScale(ScaleBase):
7177
7278
Examples
7379
--------
74-
>>> from matplotlib import pyplot
75-
>>> import probscale
76-
>>> fig, ax = pyplot.subplots()
77-
>>> ax.set_xscale('prob')
80+
The most basic use:
81+
82+
.. plot::
83+
:context: close-figs
84+
85+
>>> from matplotlib import pyplot
86+
>>> import probscale
87+
>>> fig, ax = pyplot.subplots()
88+
>>> ax.set_xlim(left=0.2, right=99.9)
89+
>>> ax.set_xscale('prob')
7890
7991
"""
8092

@@ -111,6 +123,7 @@ def _get_probs(cls, nobs, as_pct):
111123
new_lower = lower_fringe / 10**(n)
112124
new_upper = upper_fringe / 10**(n) + axis_probs.max()
113125
axis_probs = numpy.hstack([new_lower, axis_probs, new_upper])
126+
114127
locs = axis_probs / factor
115128
return locs
116129

probscale/transforms.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ def _clip_out_of_bounds(a):
2828

2929

3030
class _ProbTransformMixin(Transform):
31+
"""
32+
Mixin for MPL axes transform for quantiles/probabilities or
33+
percentages.
34+
35+
"""
36+
3137
input_dims = 1
3238
output_dims = 1
3339
is_separable = True
@@ -52,6 +58,12 @@ def __init__(self, dist, as_pct=True, nonpos='mask'):
5258

5359

5460
class ProbTransform(_ProbTransformMixin):
61+
"""
62+
MPL axes tranform class to convert quantiles to probabilities
63+
or percents.
64+
65+
"""
66+
5567
def transform_non_affine(self, prob):
5668
prob = self._handle_out_of_bounds(numpy.asarray(prob) / self.factor)
5769
q = self.dist.ppf(prob)
@@ -62,6 +74,12 @@ def inverted(self):
6274

6375

6476
class QuantileTransform(_ProbTransformMixin):
77+
"""
78+
MPL axes tranform class to convert probabilities or percents to
79+
quantiles.
80+
81+
"""
82+
6583
def transform_non_affine(self, q):
6684
prob = self.dist.cdf(q) * self.factor
6785
return prob

probscale/viz.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def plot_pos(data, postype=None, alpha=None, beta=None):
242242
'cunnane': (0.4, 0.4),
243243
'gringorten': (0.44, 0.44), # Gumble
244244
}
245+
245246
postype = 'cunnane' if postype is None else postype
246247
if alpha is None and beta is None:
247248
alpha, beta = pos_params[postype.lower()]

0 commit comments

Comments
 (0)