50
50
" clear_bkgd = {'axes.facecolor':'none', 'figure.facecolor':'none'}\n " ,
51
51
" seaborn.set(style='ticks', context='talk', color_codes=True, rc=clear_bkgd)\n " ,
52
52
" \n " ,
53
+ " # load up some example data from the seaborn package\n " ,
53
54
" tips = seaborn.load_dataset(\" tips\" )\n " ,
54
55
" iris = seaborn.load_dataset(\" iris\" )"
55
56
]
109
110
"outputs" : [],
110
111
"source" : [
111
112
" 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 " ,
117
116
" seaborn.despine()"
118
117
]
119
118
},
128
127
" The default distribution is the standard-normal distribution.\n " ,
129
128
" Using a different distribution is covered further down.\n " ,
130
129
" \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`."
132
131
]
133
132
},
134
133
{
169
168
"outputs" : [],
170
169
"source" : [
171
170
" 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 " ,
176
174
" ax.legend(loc='upper left')\n " ,
177
175
" seaborn.despine()"
178
176
]
198
196
" fig, (ax1, ax2) = pyplot.subplots(figsize=(6, 6), ncols=2, sharex=True)\n " ,
199
197
" \n " ,
200
198
" 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 " ,
205
201
" \n " ,
206
202
" 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 " ,
211
206
" fig.tight_layout()\n " ,
212
207
" seaborn.despine()"
213
208
]
240
235
" common_opts = dict(\n " ,
241
236
" probax='y', \n " ,
242
237
" datascale='log', \n " ,
243
- " label='Bill Amount', \n " ,
244
- " xlabel='Total Bill (USD)',\n " ,
238
+ " datalabel='Total Bill (USD)',\n " ,
245
239
" scatter_kws=dict(marker='.', linestyle='none')\n " ,
246
240
" )\n " ,
247
241
" \n " ,
248
242
" fig = probscale.probplot(tips['total_bill'], ax=ax1, \n " ,
249
243
" plottype='pp',\n " ,
250
- " ylabel ='percentile', \n " ,
244
+ " problabel ='percentile', \n " ,
251
245
" **common_opts)\n " ,
252
246
" \n " ,
253
247
" fig = probscale.probplot(tips['total_bill'], ax=ax2, \n " ,
254
248
" plottype='qq',\n " ,
255
- " ylabel ='Normal Quantiles', \n " ,
249
+ " problabel ='Normal Quantiles', \n " ,
256
250
" **common_opts)\n " ,
257
251
" \n " ,
258
252
" fig = probscale.probplot(tips['total_bill'], ax=ax3, \n " ,
259
253
" plottype='prob',\n " ,
260
- " ylabel ='Normal Probabilities', \n " ,
254
+ " problabel ='Normal Probabilities', \n " ,
261
255
" **common_opts)\n " ,
262
256
" ax3.set_ylim(bottom=0.13, top=99.87)\n " ,
263
257
" fig.tight_layout()\n " ,
290
284
" plottype='prob',\n " ,
291
285
" probax='y',\n " ,
292
286
" datascale='log',\n " ,
293
- " label='Bill Amount',\n " ,
294
- " xlabel='Total Bill (USD)',\n " ,
287
+ " datalabel='Total Bill (USD)',\n " ,
295
288
" scatter_kws=dict(marker='+', linestyle='none', mew=1)\n " ,
296
289
" )\n " ,
297
290
" \n " ,
300
293
" \n " ,
301
294
" fig, (ax1, ax2, ax3) = pyplot.subplots(figsize=(9, 6), ncols=3, sharey=True)\n " ,
302
295
" 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 " ,
304
297
" \n " ,
305
298
" 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 " ,
307
300
" \n " ,
308
301
" 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 " ,
310
303
" \n " ,
311
304
" ax3.set_ylim(bottom=0.2, top=99.8)\n " ,
312
305
" seaborn.despine()\n " ,
332
325
" plottype='qq',\n " ,
333
326
" probax='y',\n " ,
334
327
" datascale='log',\n " ,
335
- " label='Bill Amount',\n " ,
336
- " xlabel='Total Bill (USD)',\n " ,
328
+ " datalabel='Total Bill (USD)',\n " ,
337
329
" scatter_kws=dict(marker='+', linestyle='none', mew=1)\n " ,
338
330
" )\n " ,
339
331
" \n " ,
342
334
" \n " ,
343
335
" fig, (ax1, ax2, ax3) = pyplot.subplots(figsize=(9, 6), ncols=3)\n " ,
344
336
" 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 " ,
346
338
" \n " ,
347
339
" 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 " ,
349
341
" \n " ,
350
342
" 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 " ,
352
344
" \n " ,
353
345
" ax.legend(loc='upper left')\n " ,
354
346
" ax.set_ylim(bottom=0.1, top=99.9)\n " ,
389
381
" \n " ,
390
382
" common_opts = dict(\n " ,
391
383
" 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 " ,
396
388
" )\n " ,
397
389
" \n " ,
398
390
" fig = probscale.probplot(tips['total_bill'], ax=ax, dist=norm, **common_opts)\n " ,
399
391
" \n " ,
400
392
" equality_line(ax, label='Guessed Normal Distribution')\n " ,
401
- " ax.legend(loc='upper left ')\n " ,
393
+ " ax.legend(loc='lower right ')\n " ,
402
394
" seaborn.despine()"
403
395
]
404
396
},
427
419
" fig = probscale.probplot(tips['total_bill'], ax=ax, dist=lognorm, **common_opts)\n " ,
428
420
" \n " ,
429
421
" equality_line(ax, label='Fit Lognormal Distribution')\n " ,
422
+ " ax.legend(loc='lower right')\n " ,
430
423
" seaborn.despine()"
431
424
]
432
425
},
466
459
"source" : [
467
460
" fig, ax = pyplot.subplots(figsize=(6, 3))\n " ,
468
461
" 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 " ,
472
465
" ax.legend(loc='upper left')\n " ,
473
466
" seaborn.despine()"
474
467
]
493
486
"outputs" : [],
494
487
"source" : [
495
488
" 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 " ,
501
493
" ax.legend(loc='upper left')\n " ,
502
494
" ax.set_ylim(bottom=0.1, top=99.9)\n " ,
503
495
" seaborn.despine()"
504
496
]
505
497
},
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
+ },
506
562
{
507
563
"cell_type" : " markdown" ,
508
564
"metadata" : {},
563
619
" common_opts = dict(\n " ,
564
620
" plottype='prob',\n " ,
565
621
" probax='x',\n " ,
566
- " label='Bill Amount',\n " ,
567
- " ylabel='Data',\n " ,
622
+ " datalabel='Data',\n " ,
568
623
" )\n " ,
569
624
" \n " ,
570
625
" numpy.random.seed(0)\n " ,
571
626
" x = numpy.random.normal(size=15)\n " ,
572
627
" \n " ,
573
628
" 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 " ,
575
630
" **common_opts)\n " ,
576
631
" \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 " ,
578
633
" pp_kws=dict(postype='weibull'), **common_opts)\n " ,
579
634
" \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 " ,
581
636
" pp_kws=dict(alpha=0.6, beta=0.1), **common_opts)\n " ,
582
637
" ax1.set_xlim(left=1, right=99)\n " ,
583
638
" seaborn.despine()\n " ,
666
721
},
667
722
"nbformat" : 4 ,
668
723
"nbformat_minor" : 0
669
- }
724
+ }
0 commit comments