Skip to content

Commit

Permalink
refactoring docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dfm committed Mar 7, 2021
1 parent b224f0c commit 65661af
Show file tree
Hide file tree
Showing 23 changed files with 352 additions and 812 deletions.
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ repos:
hooks:
- id: isort
additional_dependencies: [toml]
exclude: docs/tutorials
exclude: docs/pages
- repo: https://github.com/psf/black
rev: "20.8b1"
hooks:
- id: black
- repo: https://github.com/kynan/nbstripout
rev: "0.3.9"
hooks:
- id: nbstripout
5 changes: 0 additions & 5 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .

PAGES = pages/sigmas.rst pages/quickstart.rst pages/custom.rst

pages/%.rst: _static/notebooks/%.ipynb
cd pages;jupyter nbconvert --template page_rst --to rst --output-dir . ../$<

.PHONY: help
help:
@echo "Please use \`make <target>' where <target> is one of"
Expand Down
169 changes: 0 additions & 169 deletions docs/_static/notebooks/custom.ipynb

This file was deleted.

Binary file removed docs/_static/notebooks/demo.png
Binary file not shown.
144 changes: 0 additions & 144 deletions docs/_static/notebooks/quickstart.ipynb

This file was deleted.

160 changes: 0 additions & 160 deletions docs/_static/notebooks/sigmas.ipynb

This file was deleted.

40 changes: 10 additions & 30 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
# -*- coding: utf-8 -*-

import os
import sys

d = os.path.dirname
sys.path.insert(0, d(d(os.path.abspath(__file__))))
import corner # NOQA
import corner

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.mathjax",
"sphinx.ext.napoleon",
"nbsphinx",
]
templates_path = ["_templates"]
source_suffix = ".rst"
master_doc = "index"

# General information about the project.
project = u"corner.py"
copyright = u"2013-2016 Dan Foreman-Mackey & contributors"
copyright = u"2013-2021 Dan Foreman-Mackey & contributors"

version = corner.__version__
release = corner.__version__

exclude_patterns = ["_build", "_static/notebooks/profile"]
pygments_style = "sphinx"

# Sphinx-gallery
sphinx_gallery_conf = dict(
examples_dirs="../examples",
gallery_dirs="examples",
)

# Readthedocs.
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
if not on_rtd:
Expand All @@ -40,24 +32,12 @@
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# htmp_theme_options = dict(
# analytics_id="analytics_id",
# )
# html_context = dict(
# display_github=True,
# github_user="dfm",
# github_repo="corner.py",
# github_version="corner.py",
# conf_py_path="/docs/",
# favicon="favicon.png",
# script_files=[
# "_static/jquery.js",
# "_static/underscore.js",
# "_static/doctools.js",
# "//cdn.mathjax.org/mathjax/latest/MathJax.js"
# "?config=TeX-AMS-MML_HTMLorMML",
# "_static/js/analytics.js",
# ],
# )
html_static_path = ["_static"]
html_show_sourcelink = False

nbsphinx_execute = "always"
nbsphinx_prolog = """
.. note:: This page was generated from an IPython notebook that can be downloaded
`here <https://github.com/dfm/corner.py/blob/main/docs/{{ env.doc2path(env.docname, base=None) }}>`_.
"""
139 changes: 139 additions & 0 deletions docs/pages/custom.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Custom plotting\n",
"\n",
"It can sometimes be useful to add custom annotations or plot elements to the output of `corner.corner`.\n",
"This tutorial shows how you can do this.\n",
"\n",
"For example, let's say that we want to overplot a few different values for comparison.\n",
"The `truths` interface isn't sufficient for supporting this use case, so here's how you can do it.\n",
"\n",
"First, let's generate some fake data with a mode at the origin and another randomly sampled mode:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import corner\n",
"import numpy as np\n",
"\n",
"ndim, nsamples = 4, 50000\n",
"np.random.seed(1234)\n",
"data1 = np.random.randn(ndim * 4 * nsamples // 5).reshape([4 * nsamples // 5, ndim])\n",
"mean = 4*np.random.rand(ndim)\n",
"data2 = (mean[None, :] + np.random.randn(ndim * nsamples // 5).reshape([nsamples // 5, ndim]))\n",
"samples = np.vstack([data1, data2])\n",
"\n",
"figure = corner.corner(samples)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let's overplot the empirical mean of the samples and the true mean of the second mode."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# This is the true mean of the second mode that we used above:\n",
"value1 = mean\n",
"\n",
"# This is the empirical mean of the sample:\n",
"value2 = np.mean(samples, axis=0)\n",
"\n",
"# Make the base corner plot\n",
"figure = corner.corner(samples)\n",
"\n",
"# Extract the axes\n",
"axes = np.array(figure.axes).reshape((ndim, ndim))\n",
"\n",
"# Loop over the diagonal\n",
"for i in range(ndim):\n",
" ax = axes[i, i]\n",
" ax.axvline(value1[i], color=\"g\")\n",
" ax.axvline(value2[i], color=\"r\")\n",
" \n",
"# Loop over the histograms\n",
"for yi in range(ndim):\n",
" for xi in range(yi):\n",
" ax = axes[yi, xi]\n",
" ax.axvline(value1[xi], color=\"g\")\n",
" ax.axvline(value2[xi], color=\"r\")\n",
" ax.axhline(value1[yi], color=\"g\")\n",
" ax.axhline(value2[yi], color=\"r\")\n",
" ax.plot(value1[xi], value1[yi], \"sg\")\n",
" ax.plot(value2[xi], value2[yi], \"sr\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A similar procedure could be used to add anything to the axes that you can normally do with matplotlib.\n",
"\n",
"This being said, there is actually an even easier way to do this using the `overplot_lines` and `overplot_points` functions:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# This is the true mean of the second mode that we used above:\n",
"value1 = mean\n",
"\n",
"# This is the empirical mean of the sample:\n",
"value2 = np.mean(samples, axis=0)\n",
"\n",
"# Make the base corner plot\n",
"figure = corner.corner(samples)\n",
"\n",
"corner.overplot_lines(figure, value1, color=\"C1\")\n",
"corner.overplot_points(figure, value1[None], marker=\"s\", color=\"C1\")\n",
"corner.overplot_lines(figure, value2, color=\"C2\")\n",
"corner.overplot_points(figure, value2[None], marker=\"s\", color=\"C2\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
83 changes: 0 additions & 83 deletions docs/pages/custom.rst

This file was deleted.

Binary file removed docs/pages/custom_files/custom_2_0.png
Binary file not shown.
Binary file removed docs/pages/custom_files/custom_4_0.png
Binary file not shown.
7 changes: 7 additions & 0 deletions docs/pages/matplotlibrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
savefig.dpi: 100
figure.dpi: 100
font.size: 14
font.family: sans-serif
font.sans-serif: Liberation Sans
font.cursive: Liberation Sans
mathtext.fontset: custom

0 comments on commit 65661af

Please sign in to comment.