From 5b065730a57f5791b92d7181b38ebc340e0918bd Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Tue, 7 Feb 2017 17:56:25 -0800 Subject: [PATCH 1/5] minor tweaks to figures --- docs/tutorial/closer_look_at_viz.ipynb | 72 ++++++++++++++------------ docs/tutorial/getting_started.ipynb | 4 +- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/docs/tutorial/closer_look_at_viz.ipynb b/docs/tutorial/closer_look_at_viz.ipynb index c77f102..8ef4b28 100644 --- a/docs/tutorial/closer_look_at_viz.ipynb +++ b/docs/tutorial/closer_look_at_viz.ipynb @@ -90,7 +90,7 @@ "ax.set_xlabel('Percentile')\n", "ax.set_ylabel('Total Bill (USD)')\n", "ax.set_yscale('log')\n", - "ax.legend(loc='upper left')\n", + "ax.set_ylim(bottom=1, top=100)\n", "seaborn.despine()" ] }, @@ -113,6 +113,7 @@ "fig = probscale.probplot(tips['total_bill'], ax=ax, plottype='pp', datascale='log',\n", " problabel='Percentile', datalabel='Total Bill (USD)',\n", " scatter_kws=dict(marker='.', linestyle='none', label='Bill Amount'))\n", + "ax.set_ylim(bottom=1, top=100)\n", "seaborn.despine()" ] }, @@ -148,7 +149,7 @@ "ax.set_xlabel('Normal Quantiles')\n", "ax.set_ylabel('Total Bill (USD)')\n", "ax.set_yscale('log')\n", - "ax.legend(loc='upper left')\n", + "ax.set_ylim(bottom=1, top=100)\n", "seaborn.despine()" ] }, @@ -169,9 +170,10 @@ "source": [ "fig, ax = pyplot.subplots(figsize=(6, 3))\n", "fig = probscale.probplot(tips['total_bill'], ax=ax, plottype='qq', datascale='log', \n", - " problabel='Normal Quantiles', datalabel='Total Bill (USD)',\n", + " problabel='Standard Normal Quantiles', datalabel='Total Bill (USD)',\n", " scatter_kws=dict(marker='.', linestyle='none', label='Bill Amount'))\n", - "ax.legend(loc='upper left')\n", + "\n", + "ax.set_ylim(bottom=1, top=100)\n", "seaborn.despine()" ] }, @@ -194,15 +196,17 @@ "outputs": [], "source": [ "fig, (ax1, ax2) = pyplot.subplots(figsize=(6, 6), ncols=2, sharex=True)\n", + "markers = dict(marker='.', linestyle='none', label='Bill Amount')\n", "\n", "fig = probscale.probplot(tips['total_bill'], ax=ax1, plottype='pp', probax='y',\n", - " datascale='log', problabel='Percentile', datalabel='Total Bill (USD)',\n", - " scatter_kws=dict(marker='.', linestyle='none', label='Bill Amount'))\n", + " datascale='log', problabel='Percentiles',\n", + " datalabel='Total Bill (USD)', scatter_kws=markers)\n", "\n", "fig = probscale.probplot(tips['total_bill'], ax=ax2, plottype='qq', probax='y',\n", - " datascale='log', problabel='Normal Quantiles', datalabel='Total Bill (USD)',\n", - " scatter_kws=dict(marker='.', linestyle='none', label='Bill Amount'))\n", - "ax.legend(loc='upper left')\n", + " datascale='log', problabel='Standard Normal Quantiles',\n", + " datalabel='Total Bill (USD)', scatter_kws=markers)\n", + "\n", + "ax1.set_xlim(left=1, right=100)\n", "fig.tight_layout()\n", "seaborn.despine()" ] @@ -239,20 +243,16 @@ " scatter_kws=dict(marker='.', linestyle='none')\n", ")\n", "\n", - "fig = probscale.probplot(tips['total_bill'], ax=ax1, \n", - " plottype='pp',\n", - " problabel='percentile', \n", - " **common_opts)\n", + "fig = probscale.probplot(tips['total_bill'], ax=ax1, plottype='pp',\n", + " problabel='Percentiles', **common_opts)\n", "\n", - "fig = probscale.probplot(tips['total_bill'], ax=ax2, \n", - " plottype='qq',\n", - " problabel='Normal Quantiles', \n", - " **common_opts)\n", + "fig = probscale.probplot(tips['total_bill'], ax=ax2, plottype='qq',\n", + " problabel='Standard Normal Quantiles', **common_opts)\n", "\n", - "fig = probscale.probplot(tips['total_bill'], ax=ax3, \n", - " plottype='prob',\n", - " problabel='Normal Probabilities', \n", - " **common_opts)\n", + "fig = probscale.probplot(tips['total_bill'], ax=ax3, plottype='prob',\n", + " problabel='Standard Normal Probabilities', **common_opts)\n", + "\n", + "ax3.set_xlim(left=1, right=100)\n", "ax3.set_ylim(bottom=0.13, top=99.87)\n", "fig.tight_layout()\n", "seaborn.despine()" @@ -291,17 +291,19 @@ "alpha = stats.alpha(10)\n", "beta = stats.beta(6, 3)\n", "\n", - "fig, (ax1, ax2, ax3) = pyplot.subplots(figsize=(9, 6), ncols=3, sharey=True)\n", + "fig, (ax1, ax2, ax3) = pyplot.subplots(figsize=(9, 6), ncols=3, sharex=True)\n", "fig = probscale.probplot(tips['total_bill'], ax=ax1, dist=alpha, \n", - " problabel='Alpha Probabilities', **common_opts)\n", + " problabel='Alpha(10) Probabilities', **common_opts)\n", "\n", "fig = probscale.probplot(tips['total_bill'], ax=ax2, dist=beta, \n", - " problabel='Beta Probabilities', **common_opts)\n", + " problabel='Beta(6, 1) Probabilities', **common_opts)\n", "\n", "fig = probscale.probplot(tips['total_bill'], ax=ax3, dist=None,\n", - " problabel='Normal Probabilities', **common_opts)\n", + " problabel='Standard Normal Probabilities', **common_opts)\n", "\n", - "ax3.set_ylim(bottom=0.2, top=99.8)\n", + "ax3.set_xlim(left=1, right=100)\n", + "for ax in [ax1, ax2, ax3]:\n", + " ax.set_ylim(bottom=0.2, top=99.8)\n", "seaborn.despine()\n", "fig.tight_layout()" ] @@ -332,18 +334,17 @@ "alpha = stats.alpha(10)\n", "beta = stats.beta(6, 3)\n", "\n", - "fig, (ax1, ax2, ax3) = pyplot.subplots(figsize=(9, 6), ncols=3)\n", + "fig, (ax1, ax2, ax3) = pyplot.subplots(figsize=(9, 6), ncols=3, sharex=True)\n", "fig = probscale.probplot(tips['total_bill'], ax=ax1, dist=alpha, \n", - " problabel='Alpha Quantiles', **common_opts)\n", + " problabel='Alpha(10) Quantiles', **common_opts)\n", "\n", "fig = probscale.probplot(tips['total_bill'], ax=ax2, dist=beta, \n", - " problabel='Beta Quantiles', **common_opts)\n", + " problabel='Beta(6, 3) Quantiles', **common_opts)\n", "\n", "fig = probscale.probplot(tips['total_bill'], ax=ax3, dist=None,\n", - " problabel='Normal Quantiles', **common_opts)\n", + " problabel='Standard Normal Quantiles', **common_opts)\n", "\n", - "ax.legend(loc='upper left')\n", - "ax.set_ylim(bottom=0.1, top=99.9)\n", + "ax1.set_xlim(left=1, right=100)\n", "seaborn.despine()\n", "fig.tight_layout()" ] @@ -494,6 +495,7 @@ " line_kws=dict(label='Best-fit line'))\n", "ax.legend(loc='upper left')\n", "ax.set_ylim(bottom=0.1, top=99.9)\n", + "ax.set_xlim(left=1, right=100)\n", "seaborn.despine()" ] }, @@ -524,6 +526,7 @@ " scatter_kws={'label': 'Observations'},\n", " problabel='Probability (%)')\n", "ax.legend(loc='lower right')\n", + "ax.set_ylim(bottom=-2, top=4)\n", "seaborn.despine(fig)" ] }, @@ -566,7 +569,8 @@ "numpy.random.seed(0)\n", "x = numpy.random.normal(size=15)\n", "\n", - "fig, (ax1, ax2, ax3) = pyplot.subplots(figsize=(6, 6), nrows=3, sharex=True)\n", + "fig, (ax1, ax2, ax3) = pyplot.subplots(figsize=(6, 6), nrows=3,\n", + " sharey=True, sharex=True)\n", "fig = probscale.probplot(x, ax=ax1, problabel='Cunnuane (default) plotting positions',\n", " **common_opts)\n", "\n", @@ -697,7 +701,7 @@ "outputs": [], "source": [ "fg = (\n", - " seaborn.FacetGrid(data=tips, hue='sex', row='smoker', col='time', aspect=1.5, margin_titles=True)\n", + " seaborn.FacetGrid(data=tips, hue='sex', row='smoker', col='time', margin_titles=True, size=4)\n", " .map(probscale.probplot, 'total_bill', probax='y', bestfit=True)\n", " .set_ylabels('Probability')\n", " .add_legend()\n", diff --git a/docs/tutorial/getting_started.ipynb b/docs/tutorial/getting_started.ipynb index db5aefd..c1b2963 100644 --- a/docs/tutorial/getting_started.ipynb +++ b/docs/tutorial/getting_started.ipynb @@ -366,12 +366,12 @@ "plot = (\n", " seaborn.load_dataset(\"tips\")\n", " .assign(pct=lambda df: 100 * df['tip'] / df['total_bill'])\n", - " .pipe(seaborn.FacetGrid, hue='sex', col='time', row='smoker', margin_titles=True, aspect=1.25, size=4)\n", + " .pipe(seaborn.FacetGrid, hue='sex', col='time', row='smoker', margin_titles=True, aspect=1., size=4)\n", " .map(probscale.probplot, 'pct', bestfit=True, scatter_kws=dict(alpha=0.75), probax='y')\n", " .add_legend()\n", " .set_ylabels('Non-Exceedance Probabilty')\n", " .set_xlabels('Tips as percent of total bill')\n", - " .set(ylim=(0.5, 99.5))\n", + " .set(ylim=(0.5, 99.5), xlim=(0, 100))\n", ")" ] } From 2048c6c4bb44cfb9fbd6b9c613c0e01b4cc15c0f Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Tue, 7 Feb 2017 18:05:13 -0800 Subject: [PATCH 2/5] restore default kernel in notebooks --- docs/tutorial/closer_look_at_plot_pos.ipynb | 4 ++-- docs/tutorial/closer_look_at_viz.ipynb | 4 ++-- docs/tutorial/getting_started.ipynb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/tutorial/closer_look_at_plot_pos.ipynb b/docs/tutorial/closer_look_at_plot_pos.ipynb index 0ac1606..50ae69a 100644 --- a/docs/tutorial/closer_look_at_plot_pos.ipynb +++ b/docs/tutorial/closer_look_at_plot_pos.ipynb @@ -280,9 +280,9 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "probscale", + "display_name": "Python [default]", "language": "python", - "name": "probscale" + "name": "python3" }, "language_info": { "codemirror_mode": { diff --git a/docs/tutorial/closer_look_at_viz.ipynb b/docs/tutorial/closer_look_at_viz.ipynb index 8ef4b28..ed3a2f5 100644 --- a/docs/tutorial/closer_look_at_viz.ipynb +++ b/docs/tutorial/closer_look_at_viz.ipynb @@ -712,9 +712,9 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "probscale", + "display_name": "Python [default]", "language": "python", - "name": "probscale" + "name": "python3" }, "language_info": { "codemirror_mode": { diff --git a/docs/tutorial/getting_started.ipynb b/docs/tutorial/getting_started.ipynb index c1b2963..b243ebc 100644 --- a/docs/tutorial/getting_started.ipynb +++ b/docs/tutorial/getting_started.ipynb @@ -379,9 +379,9 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "probscale", + "display_name": "Python [default]", "language": "python", - "name": "probscale" + "name": "python3" }, "language_info": { "codemirror_mode": { From 9f9fd5629233ea2e219e370861a71236b4719923 Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Wed, 8 Feb 2017 11:28:44 -0800 Subject: [PATCH 3/5] fix tutorial exporter to work with greek letters --- docs/tutorial/closer_look_at_plot_pos.ipynb | 6 +-- docs/tutorial/getting_started.ipynb | 4 +- docs/tutorial/make.py | 48 +++++---------------- 3 files changed, 15 insertions(+), 43 deletions(-) diff --git a/docs/tutorial/closer_look_at_plot_pos.ipynb b/docs/tutorial/closer_look_at_plot_pos.ipynb index 50ae69a..c96a12c 100644 --- a/docs/tutorial/closer_look_at_plot_pos.ipynb +++ b/docs/tutorial/closer_look_at_plot_pos.ipynb @@ -154,8 +154,8 @@ }, "outputs": [], "source": [ - "w_opts = {'label': 'Weibull (a=0, b=0)', 'marker': 'o', 'markeredgecolor': 'b'}\n", - "c_opts = {'label': 'Cunnane (a=0.4, b=0.4)', 'marker': 's', 'markeredgecolor': 'g'}\n", + "w_opts = {'label': 'Weibull (α=0, β=0)', 'marker': 'o', 'markeredgecolor': 'b'}\n", + "c_opts = {'label': 'Cunnane (α=0.4, β=0.4)', 'marker': 's', 'markeredgecolor': 'g'}\n", "\n", "common_opts = {\n", " 'markerfacecolor': 'none',\n", @@ -198,7 +198,7 @@ }, "outputs": [], "source": [ - "h_opts = {'label': 'Hazen (a=0.5, b=0.5)', 'marker': '^', 'markeredgecolor': 'r'}\n", + "h_opts = {'label': 'Hazen (α=0.5, β=0.5)', 'marker': '^', 'markeredgecolor': 'r'}\n", "fig, (ax1, ax2) = pyplot.subplots(figsize=(10, 8), ncols=2, sharex=True, sharey=False)\n", "\n", "for dist, ax in zip([None, weibull], [ax1, ax2]):\n", diff --git a/docs/tutorial/getting_started.ipynb b/docs/tutorial/getting_started.ipynb index b243ebc..9301d54 100644 --- a/docs/tutorial/getting_started.ipynb +++ b/docs/tutorial/getting_started.ipynb @@ -208,11 +208,11 @@ "\n", "beta1 = stats.beta(a=3, b=2)\n", "ax2.set_xscale('prob', dist=beta1)\n", - "ax2.set_xlabel('Beta probability scale (a=3, b=2)')\n", + "ax2.set_xlabel('Beta probability scale (α=3, β=2)')\n", "\n", "beta2 = stats.beta(a=2, b=7)\n", "ax3.set_xscale('prob', dist=beta2)\n", - "ax3.set_xlabel('Beta probability scale (a=2, b=7)')\n", + "ax3.set_xlabel('Beta probability scale (α=2, β=7)')\n", "\n", "ax4.set_xticks(ax1.get_xticks()[12:-12])\n", "ax4.set_xlabel('Linear scale (for reference)')\n", diff --git a/docs/tutorial/make.py b/docs/tutorial/make.py index aefccb0..6e91554 100644 --- a/docs/tutorial/make.py +++ b/docs/tutorial/make.py @@ -2,61 +2,33 @@ import glob import nbformat -from nbconvert import RSTExporter, preprocessors +from nbconvert import RSTExporter +from nbconvert.preprocessors import ExecutePreprocessor -def cache(nbfile): +def convert(nbfile): basename, _ = os.path.splitext(nbfile) - bakfile = basename + '.bak' - with open(nbfile, 'r') as nb, open(bakfile, 'w') as bak: - bak.write(nb.read()) - return bakfile - -def process(nbfile, processor): meta = {'metadata': {'path': '.'}} - with open(nbfile, 'r') as nbf: - nbook = nbformat.read(nbf, as_version=4) - - runner = processor(timeout=600, kernel_name='probscale') - runner.preprocess(nbook, meta) - - with open(nbfile, 'w') as nbf: - nbformat.write(nbook, nbf) + with open(nbfile, 'r', encoding='utf-8') as nbf: + nbdata = nbformat.read(nbf, as_version=4, encoding='utf-8') + runner = ExecutePreprocessor(timeout=600, kernel_name='probscale') + runner.preprocess(nbdata, meta) -def convert(nbfile): - basename, _ = os.path.splitext(nbfile) img_folder = basename + '_files' - os.makedirs(img_folder, exist_ok=True) - print("\tconverting " + nbfile) - - with open(nbfile, 'r') as nb: - nbdata = nbformat.reads(nb.read(), as_version=4) - - rst = RSTExporter() - body_raw, images = rst.from_notebook_node(nbdata) + body_raw, images = RSTExporter().from_notebook_node(nbdata) body_final = body_raw.replace('.. image:: ', '.. image:: {}/'.format(img_folder)) - with open(basename + '.rst', 'w') as rst_out: + with open(basename + '.rst', 'w', encoding='utf-8') as rst_out: rst_out.write(body_final) for img_name, img_data in images['outputs'].items(): img_path = os.path.join(img_folder, img_name) with open(img_path, 'wb') as img: - print('\twriting ' + img_path) img.write(img_data) if __name__ == '__main__': for nbfile in glob.glob('*.ipynb'): - bak = cache(nbfile) - success = False - try: - process(nbfile, preprocessors.ExecutePreprocessor) - convert(nbfile) - success = True - finally: - process(nbfile, preprocessors.ClearOutputPreprocessor) - if success: - os.remove(bak) + convert(nbfile) From 130be221d49cbbf5db8deedca325d62cbe440b58 Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Tue, 7 Feb 2017 16:49:05 -0800 Subject: [PATCH 4/5] update readme for new ownership --- README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c9d5322..2005e55 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,30 @@ # mpl-probscale Real probability scales for matplotlib -[![Build Status](https://travis-ci.org/phobson/mpl-probscale.svg)](https://travis-ci.org/phobson/mpl-probscale) -[![codecov](https://codecov.io/gh/phobson/mpl-probscale/branch/master/graph/badge.svg)](https://codecov.io/gh/phobson/mpl-probscale) -[![Code Climate](https://codeclimate.com/github/phobson/mpl-probscale/badges/gpa.svg)](https://codeclimate.com/github/phobson/mpl-probscale) +[![Build Status](https://travis-ci.org/matplotlib/mpl-probscale.svg)](https://travis-ci.org/matplotlib/mpl-probscale) +[![codecov](https://codecov.io/gh/matplotlib/mpl-probscale/branch/master/graph/badge.svg)](https://codecov.io/gh/matplotlib/mpl-probscale) -[Sphinx Docs](http://phobson.github.io/mpl-probscale/) +[Sphinx Docs](http://matplotlib.org/mpl-probscale/) ## Installation ### Official releases -Official releases are available through the conda-forge channel or pip" +Official releases are available through the conda-forge channel or pip + `conda install mpl-probscale --channel=conda-forge` `pip install probscale` ### Development builds -Development builds are available through my conda channel: - -`conda install mpl-probscale --channel=phobson` - +This is a pure-python package, so building from source is easy on all platforms: +``` +git clone git@github.com:matplotlib/mpl-probscale.git +cd mpl-probscale +pip install -e . +``` ## Quick start From 316dce99a2b4d71a7e0c563e22e94c562af4ba26 Mon Sep 17 00:00:00 2001 From: Paul Hobson Date: Wed, 8 Feb 2017 17:41:32 -0800 Subject: [PATCH 5/5] update docs for MPL org --- docs/index.rst | 12 ++++++------ docs/installation.rst | 8 ++++---- docs/tutorial/getting_started.ipynb | 6 +++--- probscale/tests/test_viz.py | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index b0baccf..417a56f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -7,13 +7,13 @@ mpl-probscale: Real probability scales for matplotlib ===================================================== -.. image:: https://travis-ci.org/phobson/watershed.svg?branch=master - :target: https://travis-ci.org/phobson/watershed +.. image:: https://travis-ci.org/matplotlib/mpl-probscale.svg?branch=master + :target: https://travis-ci.org/matplotlib/mpl-probscale -.. image:: https://coveralls.io/repos/phobson/mpl-probscale/badge.svg?branch=master&service=github - :target: https://coveralls.io/github/phobson/mpl-probscale?branch=master +.. image:: https://coveralls.io/repos/matplotlib/mpl-probscale/badge.svg?branch=master&service=github + :target: https://coveralls.io/github/matplotlib/mpl-probscale?branch=master -https://github.com/phobson/mpl-probscale +https://github.com/matplotlib/mpl-probscale Installation ------------ @@ -34,7 +34,7 @@ Development builds Development builds are available through my conda channel: -``conda install mpl-probscale --channel=phobson`` +``conda install mpl-probscale --channel=conda-forge`` Quickstart diff --git a/docs/installation.rst b/docs/installation.rst index 9737d90..e139ad9 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -32,13 +32,13 @@ You can either clone the public repository: .. code-block:: console - $ git clone git://github.com/phobson/probscale + $ git clone git://github.com/matplotlib/mpl-probscale Or download the `tarball`_: .. code-block:: console - $ curl -OL https://github.com/phobson/probscale/tarball/master + $ curl -OL https://github.com/matplotlib/mpl-probscale/tarball/master Once you have a copy of the source, you can install it with: @@ -47,5 +47,5 @@ Once you have a copy of the source, you can install it with: $ pip install . -.. _Github repo: https://github.com/phobson/probscale -.. _tarball: https://github.com/phobson/probscale/tarball/master +.. _Github repo: https://github.com/matplotlib/mpl-probscale +.. _tarball: https://github.com/matplotlib/mpl-probscale/tarball/master diff --git a/docs/tutorial/getting_started.ipynb b/docs/tutorial/getting_started.ipynb index 9301d54..f4935a9 100644 --- a/docs/tutorial/getting_started.ipynb +++ b/docs/tutorial/getting_started.ipynb @@ -8,7 +8,7 @@ "\n", "## Installation\n", "\n", - "`mpl-probscale` is developed on Python 3.5. It is also tested on Python 3.4 and even 2.7 (for the time being).\n", + "`mpl-probscale` is developed on Python 3.6. It is also tested on Python 3.4, 3.5, and even 2.7 (for the time being).\n", "\n", "### From conda\n", "Official releases of `mpl-probscale` can be found on conda-forge:\n", @@ -17,7 +17,7 @@ "\n", "Fairly recent builds of the development verions are available on my channel:\n", "\n", - "`conda install --channel=phobson mpl-probscale`\n", + "`conda install --channel=conda-forge mpl-probscale`\n", "\n", "\n", "### From PyPI\n", @@ -27,7 +27,7 @@ "\n", "### From source\n", "\n", - "`mpl-probscale` is a pure python package. It should be fairly trivial to install from source on any platform. To do that, download or clone from [github](https://github.com/phobson/mpl-probscale), unzip the archive if necessary then do:\n", + "`mpl-probscale` is a pure python package. It should be fairly trivial to install from source on any platform. To do that, download or clone from [github](https://github.com/matplotlib/mpl-probscale), unzip the archive if necessary then do:\n", "\n", "```\n", "cd mpl-probscale # or wherever the setup.py got placed\n", diff --git a/probscale/tests/test_viz.py b/probscale/tests/test_viz.py index 32156b7..b52a07e 100644 --- a/probscale/tests/test_viz.py +++ b/probscale/tests/test_viz.py @@ -20,7 +20,7 @@ if PY27: # pragma: no cover import mock TIGHT_TOLERANCE = 15 - LOOSE_TOLERANCE = 18 + LOOSE_TOLERANCE = 20 else: from unittest import mock TIGHT_TOLERANCE = 13