From 9c3a78e09ea872be5559c833ee66fdd81cbdf84d Mon Sep 17 00:00:00 2001 From: kolibril13 <44469195+kolibril13@users.noreply.github.com> Date: Tue, 17 Dec 2019 00:59:41 +0100 Subject: [PATCH] Backport PR #15914: Example for sigmoid function with horizontal lines --- .flake8 | 1 + examples/pyplots/axline.py | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 examples/pyplots/axline.py diff --git a/.flake8 b/.flake8 index b09f54149d93..4c1f89a6a946 100644 --- a/.flake8 +++ b/.flake8 @@ -165,6 +165,7 @@ per-file-ignores = examples/pyplots/annotation_basic.py: E402 examples/pyplots/annotation_polar.py: E231, E402 examples/pyplots/auto_subplots_adjust.py: E231, E302, E402 + examples/pyplots/axline.py: E402 examples/pyplots/boxplot_demo_pyplot.py: E231, E402 examples/pyplots/compound_path_demo.py: E231 examples/pyplots/dollar_ticks.py: E402 diff --git a/examples/pyplots/axline.py b/examples/pyplots/axline.py new file mode 100644 index 000000000000..73eed0752c7d --- /dev/null +++ b/examples/pyplots/axline.py @@ -0,0 +1,41 @@ +""" +====================================== +Infinite horizontal and vertical lines +====================================== + +`~.axes.Axes.axvline` and `~.axes.Axes.axhline` draw infinite vertical / +horizontal lines, at given *x* / *y* positions. They are usually used to mark +special data values, e.g. in this example the center and limit values of the +sigmoid function. +""" +import numpy as np +import matplotlib.pyplot as plt + +t = np.linspace(-10, 10, 100) +sig = 1 / (1 + np.exp(-t)) + +plt.axhline(y=0, color="black", linestyle="--") +plt.axhline(y=0.5, color="black", linestyle=":") +plt.axhline(y=1.0, color="black", linestyle="--") +plt.axvline(color="grey") +plt.plot(t, sig, linewidth=2, label=r"$\sigma(t) = \frac{1}{1 + e^{-t}}$") +plt.xlim(-10, 10) +plt.xlabel("t") +plt.legend(fontsize=14) +plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.pyplot.axhline +matplotlib.pyplot.axvline +matplotlib.axes.Axes.axhline +matplotlib.axes.Axes.axvline