-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
352 additions
and
812 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.