{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Logit scale\n\nExamples of plots with logit axes.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import math\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nxmax = 10\nx = np.linspace(-xmax, xmax, 10000)\ncdf_norm = [math.erf(w / np.sqrt(2)) / 2 + 1 / 2 for w in x]\ncdf_laplacian = np.where(x < 0, 1 / 2 * np.exp(x), 1 - 1 / 2 * np.exp(-x))\ncdf_cauchy = np.arctan(x) / np.pi + 1 / 2\n\nfig, axs = plt.subplots(nrows=3, ncols=2, figsize=(6.4, 8.5))\n\n# Common part, for the example, we will do the same plots on all graphs\nfor i in range(3):\n for j in range(2):\n axs[i, j].plot(x, cdf_norm, label=r\"$\\mathcal{N}$\")\n axs[i, j].plot(x, cdf_laplacian, label=r\"$\\mathcal{L}$\")\n axs[i, j].plot(x, cdf_cauchy, label=\"Cauchy\")\n axs[i, j].legend()\n axs[i, j].grid()\n\n# First line, logitscale, with standard notation\naxs[0, 0].set(title=\"logit scale\")\naxs[0, 0].set_yscale(\"logit\")\naxs[0, 0].set_ylim(1e-5, 1 - 1e-5)\n\naxs[0, 1].set(title=\"logit scale\")\naxs[0, 1].set_yscale(\"logit\")\naxs[0, 1].set_xlim(0, xmax)\naxs[0, 1].set_ylim(0.8, 1 - 5e-3)\n\n# Second line, logitscale, with survival notation (with `use_overline`), and\n# other format display 1/2\naxs[1, 0].set(title=\"logit scale\")\naxs[1, 0].set_yscale(\"logit\", one_half=\"1/2\", use_overline=True)\naxs[1, 0].set_ylim(1e-5, 1 - 1e-5)\n\naxs[1, 1].set(title=\"logit scale\")\naxs[1, 1].set_yscale(\"logit\", one_half=\"1/2\", use_overline=True)\naxs[1, 1].set_xlim(0, xmax)\naxs[1, 1].set_ylim(0.8, 1 - 5e-3)\n\n# Third line, linear scale\naxs[2, 0].set(title=\"linear scale\")\naxs[2, 0].set_ylim(0, 1)\n\naxs[2, 1].set(title=\"linear scale\")\naxs[2, 1].set_xlim(0, xmax)\naxs[2, 1].set_ylim(0.8, 1)\n\nfig.tight_layout()\nplt.show()" ] } ], "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.13.2" } }, "nbformat": 4, "nbformat_minor": 0 }