Skip to content

Commit 40620d4

Browse files
committed
document new api and restore seaborn compat
1 parent f1b89cb commit 40620d4

File tree

5 files changed

+133
-65
lines changed

5 files changed

+133
-65
lines changed

docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ API and Source Reference
66

77
api/viz.rst
88
api/probscale.rst
9+
api/formatters.rst
10+
api/transforms.rst
11+
api/validate.rst

docs/tutorial/closer_look_at_plot_pos.ipynb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@
6969
"cell_type": "code",
7070
"execution_count": null,
7171
"metadata": {
72-
"collapsed": true
72+
"collapsed": false
7373
},
7474
"outputs": [],
7575
"source": [
76+
"import warnings\n",
77+
"warnings.simplefilter('ignore')\n",
78+
"\n",
7679
"import numpy\n",
7780
"from matplotlib import pyplot\n",
7881
"from scipy import stats\n",

docs/tutorial/closer_look_at_viz.ipynb

Lines changed: 107 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"clear_bkgd = {'axes.facecolor':'none', 'figure.facecolor':'none'}\n",
5151
"seaborn.set(style='ticks', context='talk', color_codes=True, rc=clear_bkgd)\n",
5252
"\n",
53+
"# load up some example data from the seaborn package\n",
5354
"tips = seaborn.load_dataset(\"tips\")\n",
5455
"iris = seaborn.load_dataset(\"iris\")"
5556
]
@@ -109,11 +110,9 @@
109110
"outputs": [],
110111
"source": [
111112
"fig, ax = pyplot.subplots(figsize=(6, 3))\n",
112-
"fig = probscale.probplot(tips['total_bill'], ax=ax, plottype='pp',\n",
113-
" datascale='log', label='Bill Amount', \n",
114-
" xlabel='Percentile', ylabel='Total Bill (USD)',\n",
115-
" scatter_kws=dict(marker='.', linestyle='none'))\n",
116-
"ax.legend(loc='upper left')\n",
113+
"fig = probscale.probplot(tips['total_bill'], ax=ax, plottype='pp', datascale='log',\n",
114+
" problabel='Percentile', datalabel='Total Bill (USD)',\n",
115+
" scatter_kws=dict(marker='.', linestyle='none', label='Bill Amount'))\n",
117116
"seaborn.despine()"
118117
]
119118
},
@@ -128,7 +127,7 @@
128127
"The default distribution is the standard-normal distribution.\n",
129128
"Using a different distribution is covered further down.\n",
130129
"\n",
131-
"Usings the same dataset as a above let's make a quantile plot, again from scratch and then using `probplot`."
130+
"Usings the same dataset as a above let's make a quantile plot. Like above, we'll do it from scratch and then using `probplot`."
132131
]
133132
},
134133
{
@@ -169,10 +168,9 @@
169168
"outputs": [],
170169
"source": [
171170
"fig, ax = pyplot.subplots(figsize=(6, 3))\n",
172-
"fig = probscale.probplot(tips['total_bill'], ax=ax, plottype='qq',\n",
173-
" datascale='log', label='Bill Amount', \n",
174-
" xlabel='Normal Quantiles', ylabel='Total Bill (USD)',\n",
175-
" scatter_kws=dict(marker='.', linestyle='none'))\n",
171+
"fig = probscale.probplot(tips['total_bill'], ax=ax, plottype='qq', datascale='log', \n",
172+
" problabel='Normal Quantiles', datalabel='Total Bill (USD)',\n",
173+
" scatter_kws=dict(marker='.', linestyle='none', label='Bill Amount'))\n",
176174
"ax.legend(loc='upper left')\n",
177175
"seaborn.despine()"
178176
]
@@ -198,16 +196,13 @@
198196
"fig, (ax1, ax2) = pyplot.subplots(figsize=(6, 6), ncols=2, sharex=True)\n",
199197
"\n",
200198
"fig = probscale.probplot(tips['total_bill'], ax=ax1, plottype='pp', probax='y',\n",
201-
" datascale='log', label='Bill Amount', \n",
202-
" ylabel='Percentile', xlabel='Total Bill (USD)',\n",
203-
" scatter_kws=dict(marker='.', linestyle='none'))\n",
204-
"ax.legend()\n",
199+
" datascale='log', problabel='Percentile', datalabel='Total Bill (USD)',\n",
200+
" scatter_kws=dict(marker='.', linestyle='none', label='Bill Amount'))\n",
205201
"\n",
206202
"fig = probscale.probplot(tips['total_bill'], ax=ax2, plottype='qq', probax='y',\n",
207-
" datascale='log', label='Bill Amount', \n",
208-
" ylabel='Normal Quantiles', xlabel='Total Bill (USD)',\n",
209-
" scatter_kws=dict(marker='.', linestyle='none'))\n",
210-
"ax.legend()\n",
203+
" datascale='log', problabel='Normal Quantiles',datalabel='Total Bill (USD)',\n",
204+
" scatter_kws=dict(marker='.', linestyle='none', label='Bill Amount'))\n",
205+
"ax.legend(loc='upper left')\n",
211206
"fig.tight_layout()\n",
212207
"seaborn.despine()"
213208
]
@@ -240,24 +235,23 @@
240235
"common_opts = dict(\n",
241236
" probax='y', \n",
242237
" datascale='log', \n",
243-
" label='Bill Amount', \n",
244-
" xlabel='Total Bill (USD)',\n",
238+
" datalabel='Total Bill (USD)',\n",
245239
" scatter_kws=dict(marker='.', linestyle='none')\n",
246240
")\n",
247241
"\n",
248242
"fig = probscale.probplot(tips['total_bill'], ax=ax1, \n",
249243
" plottype='pp',\n",
250-
" ylabel='percentile', \n",
244+
" problabel='percentile', \n",
251245
" **common_opts)\n",
252246
"\n",
253247
"fig = probscale.probplot(tips['total_bill'], ax=ax2, \n",
254248
" plottype='qq',\n",
255-
" ylabel='Normal Quantiles', \n",
249+
" problabel='Normal Quantiles', \n",
256250
" **common_opts)\n",
257251
"\n",
258252
"fig = probscale.probplot(tips['total_bill'], ax=ax3, \n",
259253
" plottype='prob',\n",
260-
" ylabel='Normal Probabilities', \n",
254+
" problabel='Normal Probabilities', \n",
261255
" **common_opts)\n",
262256
"ax3.set_ylim(bottom=0.13, top=99.87)\n",
263257
"fig.tight_layout()\n",
@@ -290,8 +284,7 @@
290284
" plottype='prob',\n",
291285
" probax='y',\n",
292286
" datascale='log',\n",
293-
" label='Bill Amount',\n",
294-
" xlabel='Total Bill (USD)',\n",
287+
" datalabel='Total Bill (USD)',\n",
295288
" scatter_kws=dict(marker='+', linestyle='none', mew=1)\n",
296289
")\n",
297290
"\n",
@@ -300,13 +293,13 @@
300293
"\n",
301294
"fig, (ax1, ax2, ax3) = pyplot.subplots(figsize=(9, 6), ncols=3, sharey=True)\n",
302295
"fig = probscale.probplot(tips['total_bill'], ax=ax1, dist=alpha, \n",
303-
" ylabel='Alpha Probabilities', **common_opts)\n",
296+
" problabel='Alpha Probabilities', **common_opts)\n",
304297
"\n",
305298
"fig = probscale.probplot(tips['total_bill'], ax=ax2, dist=beta, \n",
306-
" ylabel='Beta Probabilities', **common_opts)\n",
299+
" problabel='Beta Probabilities', **common_opts)\n",
307300
"\n",
308301
"fig = probscale.probplot(tips['total_bill'], ax=ax3, dist=None,\n",
309-
" ylabel='Normal Probabilities', **common_opts)\n",
302+
" problabel='Normal Probabilities', **common_opts)\n",
310303
"\n",
311304
"ax3.set_ylim(bottom=0.2, top=99.8)\n",
312305
"seaborn.despine()\n",
@@ -332,8 +325,7 @@
332325
" plottype='qq',\n",
333326
" probax='y',\n",
334327
" datascale='log',\n",
335-
" label='Bill Amount',\n",
336-
" xlabel='Total Bill (USD)',\n",
328+
" datalabel='Total Bill (USD)',\n",
337329
" scatter_kws=dict(marker='+', linestyle='none', mew=1)\n",
338330
")\n",
339331
"\n",
@@ -342,13 +334,13 @@
342334
"\n",
343335
"fig, (ax1, ax2, ax3) = pyplot.subplots(figsize=(9, 6), ncols=3)\n",
344336
"fig = probscale.probplot(tips['total_bill'], ax=ax1, dist=alpha, \n",
345-
" ylabel='Alpha Quantiles', **common_opts)\n",
337+
" problabel='Alpha Quantiles', **common_opts)\n",
346338
"\n",
347339
"fig = probscale.probplot(tips['total_bill'], ax=ax2, dist=beta, \n",
348-
" ylabel='Beta Quantiles', **common_opts)\n",
340+
" problabel='Beta Quantiles', **common_opts)\n",
349341
"\n",
350342
"fig = probscale.probplot(tips['total_bill'], ax=ax3, dist=None,\n",
351-
" ylabel='Normal Quantiles', **common_opts)\n",
343+
" problabel='Normal Quantiles', **common_opts)\n",
352344
"\n",
353345
"ax.legend(loc='upper left')\n",
354346
"ax.set_ylim(bottom=0.1, top=99.9)\n",
@@ -389,16 +381,16 @@
389381
"\n",
390382
"common_opts = dict(\n",
391383
" plottype='qq',\n",
392-
" probax='y',\n",
393-
" ylabel='Theoretical Quantiles',\n",
394-
" xlabel='Emperical Quantiles',\n",
395-
" label='Bill amounts'\n",
384+
" probax='x',\n",
385+
" problabel='Theoretical Quantiles',\n",
386+
" datalabel='Emperical Quantiles',\n",
387+
" scatter_kws=dict(label='Bill amounts')\n",
396388
")\n",
397389
"\n",
398390
"fig = probscale.probplot(tips['total_bill'], ax=ax, dist=norm, **common_opts)\n",
399391
"\n",
400392
"equality_line(ax, label='Guessed Normal Distribution')\n",
401-
"ax.legend(loc='upper left')\n",
393+
"ax.legend(loc='lower right')\n",
402394
"seaborn.despine()"
403395
]
404396
},
@@ -427,6 +419,7 @@
427419
"fig = probscale.probplot(tips['total_bill'], ax=ax, dist=lognorm, **common_opts)\n",
428420
"\n",
429421
"equality_line(ax, label='Fit Lognormal Distribution')\n",
422+
"ax.legend(loc='lower right')\n",
430423
"seaborn.despine()"
431424
]
432425
},
@@ -466,9 +459,9 @@
466459
"source": [
467460
"fig, ax = pyplot.subplots(figsize=(6, 3))\n",
468461
"fig = probscale.probplot(tips['total_bill'], ax=ax, plottype='pp', bestfit=True,\n",
469-
" label='Bill Amount', xlabel='Percentile', ylabel='Total Bill (USD)',\n",
470-
" scatter_kws=dict(marker='.', linestyle='none', alpha=0.5),\n",
471-
" line_kws=dict(label='Best-fit line', linestyle='--', linewidth=2.5))\n",
462+
" problabel='Percentile', datalabel='Total Bill (USD)',\n",
463+
" scatter_kws=dict(label='Bill Amount'),\n",
464+
" line_kws=dict(label='Best-fit line'))\n",
472465
"ax.legend(loc='upper left')\n",
473466
"seaborn.despine()"
474467
]
@@ -493,16 +486,79 @@
493486
"outputs": [],
494487
"source": [
495488
"fig, ax = pyplot.subplots(figsize=(4, 6))\n",
496-
"fig = probscale.probplot(tips['total_bill'], ax=ax, plottype='prob', bestfit=True, \n",
497-
" probax='y', datascale='log',label='Bill Amount',\n",
498-
" ylabel='Probabilities', xlabel='Total Bill (USD)',\n",
499-
" scatter_kws=dict(marker='+', linestyle='none', alpha=0.75, mew=1),\n",
500-
" line_kws=dict(label='Best-fit line', linewidth=2.5, zorder=0))\n",
489+
"fig = probscale.probplot(tips['total_bill'], ax=ax, plottype='prob', probax='y', bestfit=True, \n",
490+
" datascale='log', problabel='Probabilities', datalabel='Total Bill (USD)',\n",
491+
" scatter_kws=dict(label='Bill Amount'),\n",
492+
" line_kws=dict(label='Best-fit line'))\n",
501493
"ax.legend(loc='upper left')\n",
502494
"ax.set_ylim(bottom=0.1, top=99.9)\n",
503495
"seaborn.despine()"
504496
]
505497
},
498+
{
499+
"cell_type": "markdown",
500+
"metadata": {},
501+
"source": [
502+
"## Controlling the aesthetics of the plot elements\n",
503+
"\n",
504+
"As it has been hinted in the examples above, the `probplot` function takes two dictionaries to customize the data series and the best-fit line (`scatter_kws` and `line_kws`, respectively.\n",
505+
"These dictionaries are passed directly to the `plot` method of current axes.\n",
506+
"\n",
507+
"By default, the data series assumes that `linestyle='none'` and `marker='o'`.\n",
508+
"These can be overwritten through `scatter_kws`\n",
509+
"\n",
510+
"Revisting the previous example, we can customize it like so:"
511+
]
512+
},
513+
{
514+
"cell_type": "code",
515+
"execution_count": null,
516+
"metadata": {
517+
"collapsed": false
518+
},
519+
"outputs": [],
520+
"source": [
521+
"scatter_options = dict(\n",
522+
" marker='^',\n",
523+
" markerfacecolor='none',\n",
524+
" markeredgecolor='firebrick',\n",
525+
" markeredgewidth=1.25,\n",
526+
" linestyle='none',\n",
527+
" alpha=0.35,\n",
528+
" zorder=5,\n",
529+
" label='Meal Cost ($)'\n",
530+
")\n",
531+
"\n",
532+
"line_options = dict(\n",
533+
" dashes=(10,2,5,2,10,2),\n",
534+
" color='0.25',\n",
535+
" linewidth=3,\n",
536+
" zorder=10,\n",
537+
" label='Best-fit line'\n",
538+
") \n",
539+
"\n",
540+
"fig, ax = pyplot.subplots(figsize=(4, 6))\n",
541+
"fig = probscale.probplot(tips['total_bill'], ax=ax, plottype='prob', probax='y', bestfit=True, \n",
542+
" datascale='log', problabel='Probabilities', datalabel='Total Bill (USD)',\n",
543+
" scatter_kws=scatter_options, line_kws=line_options)\n",
544+
"ax.legend(loc='upper left')\n",
545+
"ax.set_ylim(bottom=0.1, top=99.9)\n",
546+
"seaborn.despine()"
547+
]
548+
},
549+
{
550+
"cell_type": "raw",
551+
"metadata": {},
552+
"source": [
553+
".. note::\n",
554+
" The ``probplot`` function can take two additional aesthetic parameters:\n",
555+
" `color` and `label`. If provided `color` will override the marker face color\n",
556+
" and line color options of the `scatter_kws` and `line_kws` parameters, respectively.\n",
557+
" Similarly, the label of the scatter series will be overridden by the explicit parameter.\n",
558+
" It is not recommended that `color` and `label` are used. They exist primarily for \n",
559+
" compatibility with the seaborn package."
560+
]
561+
},
506562
{
507563
"cell_type": "markdown",
508564
"metadata": {},
@@ -563,21 +619,20 @@
563619
"common_opts = dict(\n",
564620
" plottype='prob',\n",
565621
" probax='x',\n",
566-
" label='Bill Amount',\n",
567-
" ylabel='Data',\n",
622+
" datalabel='Data',\n",
568623
")\n",
569624
"\n",
570625
"numpy.random.seed(0)\n",
571626
"x = numpy.random.normal(size=15)\n",
572627
"\n",
573628
"fig, (ax1, ax2, ax3) = pyplot.subplots(figsize=(6, 6), nrows=3, sharex=True)\n",
574-
"fig = probscale.probplot(x, ax=ax1, xlabel='Cunnuane (default) plotting positions',\n",
629+
"fig = probscale.probplot(x, ax=ax1, problabel='Cunnuane (default) plotting positions',\n",
575630
" **common_opts)\n",
576631
"\n",
577-
"fig = probscale.probplot(x, ax=ax2, xlabel='Weibull plotting positions',\n",
632+
"fig = probscale.probplot(x, ax=ax2, problabel='Weibull plotting positions',\n",
578633
" pp_kws=dict(postype='weibull'), **common_opts)\n",
579634
"\n",
580-
"fig = probscale.probplot(x, ax=ax3, xlabel='Custom plotting positions',\n",
635+
"fig = probscale.probplot(x, ax=ax3, problabel='Custom plotting positions',\n",
581636
" pp_kws=dict(alpha=0.6, beta=0.1), **common_opts)\n",
582637
"ax1.set_xlim(left=1, right=99)\n",
583638
"seaborn.despine()\n",
@@ -666,4 +721,4 @@
666721
},
667722
"nbformat": 4,
668723
"nbformat_minor": 0
669-
}
724+
}

0 commit comments

Comments
 (0)