Skip to content

Instantly share code, notes, and snippets.

@Will-777
Last active November 13, 2021 09:44
Show Gist options
  • Save Will-777/ad278c345639d24efb9d4cd275addbd2 to your computer and use it in GitHub Desktop.
Save Will-777/ad278c345639d24efb9d4cd275addbd2 to your computer and use it in GitHub Desktop.
simple sigmoid function with Python
#import section
from matplotlib import pylab
import pylab as plt
import numpy as np
#sigmoid = lambda x: 1 / (1 + np.exp(-x))
def sigmoid(x):
return (1 / (1 + np.exp(-x)))
mySamples = []
mySigmoid = []
# generate an Array with value ???
# linespace generate an array from start and stop value
# with requested number of elements. Example 10 elements or 100 elements.
#
x = plt.linspace(-10,10,10)
y = plt.linspace(-10,10,100)
# prepare the plot, associate the color r(ed) or b(lue) and the label
plt.plot(x, sigmoid(x), 'r', label='linspace(-10,10,10)')
plt.plot(y, sigmoid(y), 'b', label='linspace(-10,10,100)')
# Draw the grid line in background.
plt.grid()
# Title & Subtitle
plt.title('Sigmoid Function')
plt.suptitle('Sigmoid')
# place the legen boc in bottom right of the graph
plt.legend(loc='lower right')
# write the Sigmoid formula
plt.text(4, 0.8, r'$\sigma(x)=\frac{1}{1+e^{-x}}$', fontsize=15)
#resize the X and Y axes
plt.gca().xaxis.set_major_locator(plt.MultipleLocator(1))
plt.gca().yaxis.set_major_locator(plt.MultipleLocator(0.1))
# plt.plot(x)
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
# create the graph
plt.show()
@Will-777
Copy link
Author

image

@rtatze
Copy link

rtatze commented Aug 14, 2018

there is no need for line 10,11

@CesarMendozza
Copy link

cool!

@VishalAmbavade
Copy link

How to plot multiple sigmoid functions in a single graph?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment