|
| 1 | +""" |
| 2 | +================ |
| 3 | +Logit Demo |
| 4 | +================ |
| 5 | +
|
| 6 | +Examples of plots with logit axes. |
| 7 | +""" |
| 8 | + |
| 9 | +import numpy as np |
| 10 | +import matplotlib.pyplot as plt |
| 11 | + |
| 12 | +xmax = 10 |
| 13 | +x = np.linspace(-xmax, xmax, 10000) |
| 14 | +cdf_norm = np.array([np.math.erf(w / np.sqrt(2)) / 2 + 1 / 2 for w in x]) |
| 15 | +cdf_laplacian = np.array( |
| 16 | + [1 / 2 * np.exp(w) if w < 0 else 1 - 1 / 2 * np.exp(-w) for w in x] |
| 17 | +) |
| 18 | +cdf_cauchy = 1 / np.pi * np.arctan(x) + 1 / 2 |
| 19 | + |
| 20 | +fig, axs = plt.subplots(nrows=3, ncols=2, figsize=(6.4, 8.5)) |
| 21 | + |
| 22 | +# Common part, for the example, we will do the same plots on all graphs |
| 23 | +for i in range(3): |
| 24 | + for j in range(2): |
| 25 | + axs[i, j].plot(x, cdf_norm, label=r"$\mathcal{N}$") |
| 26 | + axs[i, j].plot(x, cdf_laplacian, label=r"$\mathcal{L}$") |
| 27 | + axs[i, j].plot(x, cdf_cauchy, label="Cauchy") |
| 28 | + axs[i, j].legend() |
| 29 | + axs[i, j].grid() |
| 30 | + |
| 31 | +# First line, logitscale, with standard notation |
| 32 | +axs[0, 0].set(title="logit scale") |
| 33 | +axs[0, 0].set_yscale("logit") |
| 34 | +axs[0, 0].set_ylim(1e-5, 1 - 1e-5) |
| 35 | + |
| 36 | +axs[0, 1].set(title="logit scale") |
| 37 | +axs[0, 1].set_yscale("logit") |
| 38 | +axs[0, 1].set_xlim(0, xmax) |
| 39 | +axs[0, 1].set_ylim(0.8, 1 - 5e-3) |
| 40 | + |
| 41 | +# Second line, logitscale, with survival notation (with `use_overline`), and |
| 42 | +# other format display 1/2 |
| 43 | +axs[1, 0].set(title="logit scale") |
| 44 | +axs[1, 0].set_yscale("logit", one_half="1/2", use_overline=True) |
| 45 | +axs[1, 0].set_ylim(1e-5, 1 - 1e-5) |
| 46 | + |
| 47 | +axs[1, 1].set(title="logit scale") |
| 48 | +axs[1, 1].set_yscale("logit", one_half="1/2", use_overline=True) |
| 49 | +axs[1, 1].set_xlim(0, xmax) |
| 50 | +axs[1, 1].set_ylim(0.8, 1 - 5e-3) |
| 51 | + |
| 52 | +# Third line, linear scale |
| 53 | +axs[2, 0].set(title="linear scale") |
| 54 | +axs[2, 0].set_ylim(0, 1) |
| 55 | + |
| 56 | +axs[2, 1].set(title="linear scale") |
| 57 | +axs[2, 1].set_xlim(0, xmax) |
| 58 | +axs[2, 1].set_ylim(0.8, 1) |
| 59 | + |
| 60 | +fig.tight_layout() |
| 61 | +plt.show() |
0 commit comments