|
499 | 499 | "cell_type": "markdown", |
500 | 500 | "metadata": {}, |
501 | 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", |
| 502 | + "### Bootstrapped confidence intervals\n", |
506 | 503 | "\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:" |
| 504 | + "Regardless of the scales of the plot (linear, log, or prob), you can add bootstrapped confidence intervals around the best-fit line. \n", |
| 505 | + "Simply use the ``estimate_ci=True`` option along with ``bestfit=True``:" |
511 | 506 | ] |
512 | 507 | }, |
513 | 508 | { |
|
518 | 513 | }, |
519 | 514 | "outputs": [], |
520 | 515 | "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." |
| 516 | + "N = 15\n", |
| 517 | + "numpy.random.seed(0)\n", |
| 518 | + "x = numpy.random.normal(size=N) + numpy.random.uniform(size=N)\n", |
| 519 | + "fig, ax = pyplot.subplots(figsize=(8, 4))\n", |
| 520 | + "fig = probscale.probplot(x, ax=ax, bestfit=True, estimate_ci=True, \n", |
| 521 | + " line_kws={'label': 'BF Line', 'color': 'b'},\n", |
| 522 | + " scatter_kws={'label': 'Observations'},\n", |
| 523 | + " problabel='Probability (%)')\n", |
| 524 | + "ax.legend(loc='lower right')\n", |
| 525 | + "seaborn.despine(fig)" |
560 | 526 | ] |
561 | 527 | }, |
562 | 528 | { |
|
575 | 541 | "You should read that function's docstring for more detailed information.\n", |
576 | 542 | "But the high-level overview is that there are a couple of parameters (``alpha`` and ``beta``) that you can tweak in the plotting positions calculation.\n", |
577 | 543 | "\n", |
578 | | - "The most common values can be selected via the ``postype`` parameter and are described as follows:\n", |
579 | | - "\n", |
580 | | - " \"type 4\" (α=0, β=1)\n", |
581 | | - " Linear interpolation of the empirical CDF.\n", |
582 | | - " \"type 5\" or \"hazen\" (α=0.5, β=0.5)\n", |
583 | | - " Piecewise linear interpolation.\n", |
584 | | - " \"type 6\" or \"weibull\" (α=0, β=0)\n", |
585 | | - " Weibull plotting positions. Unbiased exceedance probability\n", |
586 | | - " for all distributions. Recommended for hydrologic applications.\n", |
587 | | - " \"type 7\" (α=1, β=1)\n", |
588 | | - " The default values in R. Not recommended with probability\n", |
589 | | - " scales as the min and max data points get plotting positions\n", |
590 | | - " of 0 and 1, respectively, and therefore cannot be shown.\n", |
591 | | - " \"type 8\" (α=1/3, β=1/3)\n", |
592 | | - " Approximately median-unbiased.\n", |
593 | | - " \"type 9\" or \"blom\" (α=0.375, β=0.375)\n", |
594 | | - " Approximately unbiased positions if the data are normally\n", |
595 | | - " distributed.\n", |
596 | | - " \"median\" (α=0.3175, β=0.3175)\n", |
597 | | - " Median exceedance probabilities for all distributions\n", |
598 | | - " (used in ``scipy.stats.probplot``).\n", |
599 | | - " \"apl\" or \"pwm\" (α=0.35, β=0.35)\n", |
600 | | - " Used with probability-weighted moments.\n", |
601 | | - " \"cunnane\" (α=0.4, β=0.4)\n", |
602 | | - " Nearly unbiased quantiles for normally distributed data.\n", |
603 | | - " This is the default value.\n", |
604 | | - " \"gringorten\" (α=0.44, β=0.44)\n", |
605 | | - " Used for Gumble distributions.\n", |
606 | | - " \n", |
| 544 | + "The most common values can be selected via the ``postype`` parameter.\n", |
| 545 | + "\n", |
607 | 546 | "These are controlled via the `pp_kws` parameter in `probplot`\n", |
608 | | - "and are discussed in much more detail in the next tutorial.\n" |
| 547 | + "and are discussed in much more detail in the `next tutorial <closer_look_at_plot_pos.html>`_." |
609 | 548 | ] |
610 | 549 | }, |
611 | 550 | { |
|
639 | 578 | "fig.tight_layout()" |
640 | 579 | ] |
641 | 580 | }, |
| 581 | + { |
| 582 | + "cell_type": "markdown", |
| 583 | + "metadata": {}, |
| 584 | + "source": [ |
| 585 | + "## Controlling the aesthetics of the plot elements\n", |
| 586 | + "\n", |
| 587 | + "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", |
| 588 | + "These dictionaries are passed directly to the `plot` method of current axes.\n", |
| 589 | + "\n", |
| 590 | + "By default, the data series assumes that `linestyle='none'` and `marker='o'`.\n", |
| 591 | + "These can be overwritten through `scatter_kws`\n", |
| 592 | + "\n", |
| 593 | + "Revisting the previous example, we can customize it like so:" |
| 594 | + ] |
| 595 | + }, |
| 596 | + { |
| 597 | + "cell_type": "code", |
| 598 | + "execution_count": null, |
| 599 | + "metadata": { |
| 600 | + "collapsed": false |
| 601 | + }, |
| 602 | + "outputs": [], |
| 603 | + "source": [ |
| 604 | + "scatter_options = dict(\n", |
| 605 | + " marker='^',\n", |
| 606 | + " markerfacecolor='none',\n", |
| 607 | + " markeredgecolor='firebrick',\n", |
| 608 | + " markeredgewidth=1.25,\n", |
| 609 | + " linestyle='none',\n", |
| 610 | + " alpha=0.35,\n", |
| 611 | + " zorder=5,\n", |
| 612 | + " label='Meal Cost ($)'\n", |
| 613 | + ")\n", |
| 614 | + "\n", |
| 615 | + "line_options = dict(\n", |
| 616 | + " dashes=(10,2,5,2,10,2),\n", |
| 617 | + " color='0.25',\n", |
| 618 | + " linewidth=3,\n", |
| 619 | + " zorder=10,\n", |
| 620 | + " label='Best-fit line'\n", |
| 621 | + ") \n", |
| 622 | + "\n", |
| 623 | + "fig, ax = pyplot.subplots(figsize=(4, 6))\n", |
| 624 | + "fig = probscale.probplot(tips['total_bill'], ax=ax, plottype='prob', probax='y', bestfit=True, \n", |
| 625 | + " datascale='log', problabel='Probabilities', datalabel='Total Bill (USD)',\n", |
| 626 | + " scatter_kws=scatter_options, line_kws=line_options)\n", |
| 627 | + "ax.legend(loc='upper left')\n", |
| 628 | + "ax.set_ylim(bottom=0.1, top=99.9)\n", |
| 629 | + "seaborn.despine()" |
| 630 | + ] |
| 631 | + }, |
| 632 | + { |
| 633 | + "cell_type": "raw", |
| 634 | + "metadata": {}, |
| 635 | + "source": [ |
| 636 | + ".. note::\n", |
| 637 | + " The ``probplot`` function can take two additional aesthetic parameters:\n", |
| 638 | + " `color` and `label`. If provided, `color` will override the marker face color\n", |
| 639 | + " and line color options of the `scatter_kws` and `line_kws` parameters, respectively.\n", |
| 640 | + " Similarly, the label of the scatter series will be overridden by the explicit parameter.\n", |
| 641 | + " It is not recommended that `color` and `label` are used. They exist primarily for \n", |
| 642 | + " compatibility with the seaborn package." |
| 643 | + ] |
| 644 | + }, |
642 | 645 | { |
643 | 646 | "cell_type": "markdown", |
644 | 647 | "metadata": {}, |
|
716 | 719 | "name": "python", |
717 | 720 | "nbconvert_exporter": "python", |
718 | 721 | "pygments_lexer": "ipython3", |
719 | | - "version": "3.5.1" |
| 722 | + "version": "3.5.2" |
720 | 723 | } |
721 | 724 | }, |
722 | 725 | "nbformat": 4, |
|
0 commit comments