Skip to content

Example for sigmoid function with horizontal lines #15914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,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
Expand Down
41 changes: 41 additions & 0 deletions examples/pyplots/axline.py
Original file line number Diff line number Diff line change
@@ -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