Skip to content

Instantly share code, notes, and snippets.

View AmirMardan's full-sized avatar

Amir Mardan AmirMardan

View GitHub Profile
def train(theta0, x, y, iteration, alpha=0.01):
"""
This function find the best model parameters using gradient descent method
Parameters
----------
theta0 : float
Model parameters
x : float
Training data
@AmirMardan
AmirMardan / 2ceea576-30da-40cc-b469-872b7ff80cda.py
Created March 21, 2022 04:13
plots_using_matplotlib_with_animation_in_matplotlib_and_emojis_in_matplotlib0
# Importing matplotlib
import matplotlib.pyplot as plt
import matplotlib as mpl
# For plotting in jupyter notebook
%matplotlib inline
# Import more packages to generate data
import numpy as np
@AmirMardan
AmirMardan / 8629790f-041b-42cc-b42a-a16ea5f73dba.py
Created March 21, 2022 04:13
plots_using_matplotlib_with_animation_in_matplotlib_and_emojis_in_matplotlib1
# Let's set give data to our plot
x1 = np.arange(-3 * np.pi, 3 * np.pi, np.pi/6)
x2 = np.arange(-3 * np.pi, 3 * np.pi, np.pi/3)
y1 = np.sin(x1)
y2 = np.cos(x2)
plt.plot(x1, y1, label='sin')
@AmirMardan
AmirMardan / 883802f9-e785-4873-aaa4-81caa3b40560.py
Created March 21, 2022 04:13
plots_using_matplotlib_with_animation_in_matplotlib_and_emojis_in_matplotlib2
# Let's add more parameters to our plot
plt.plot(x1, y1, label='sin', color='teal', marker='v')
# Add title
plt.title('Simple plot')
# Add label
plt.xlabel('X')
plt.ylabel('Y')
@AmirMardan
AmirMardan / 9f5d9c41-3707-4a1c-954d-643e6a6d9740.py
Created March 21, 2022 04:13
plots_using_matplotlib_with_animation_in_matplotlib_and_emojis_in_matplotlib3
# Let's add more parameters to our plot
plt.plot(x1, y1, label='sin', linestyle=':',
color='teal', marker='$\U0001F609$', ms=15)
# Add title
plt.title('Simple plot')
# Add label
plt.xlabel('X')
@AmirMardan
AmirMardan / e6ec62ff-ae4c-4184-93d4-94a022a5d017.py
Created March 21, 2022 04:13
plots_using_matplotlib_with_animation_in_matplotlib_and_emojis_in_matplotlib4
# Simple subplot
plt.subplot(1, 2, 1)
plt.plot(x1, y1)
plt.title('Plot 1')
plt.subplot(1, 2, 2)
plt.plot(x2, y2)
plt.title('Plot 2')
@AmirMardan
AmirMardan / 72e879f4-128e-4b2a-a0c3-896cdb0b51b6.py
Created March 21, 2022 04:13
plots_using_matplotlib_with_animation_in_matplotlib_and_emojis_in_matplotlib5
# Subplot with
plt.subplot(2, 1, 1)
plt.plot(x1, y1)
plt.title('Plot 1')
plt.subplot(2, 2, 3)
plt.plot(x2, y2)
plt.title('Plot 2')
@AmirMardan
AmirMardan / 9477c53e-820b-4b76-91a0-11adc8674a07.py
Created March 21, 2022 04:13
plots_using_matplotlib_with_animation_in_matplotlib_and_emojis_in_matplotlib6
# Let's add a text to a plot with specific color and make it bold and italic
arrowprops = dict(arrowstyle="->",
connectionstyle="arc3,rad=.3", # Specify the connection style
color='red', # Set the color
lw=1 # Set the width of line
)
plt.plot(x2, y2)
plt.annotate('Local max', # text to annotate
@AmirMardan
AmirMardan / b08e2e5f-5db0-458a-9791-4add2e856007.py
Created March 21, 2022 04:13
plots_using_matplotlib_with_animation_in_matplotlib_and_emojis_in_matplotlib7
# Let's plot a heart
theta = np.linspace(0, 2 * np.pi, 100)
x = 16 * ( np.sin(theta) ** 3 )
y = 13 * np.cos(theta) - 5* np.cos(2*theta) - 2 * np.cos(3*theta) - np.cos(4*theta)
# font
hfont = {'fontname':'Apple Chancery',
'fontsize': 14,
'color': 'w'}
@AmirMardan
AmirMardan / 9f62441c-b007-4571-8a6c-0625095a958b.py
Created March 21, 2022 04:13
plots_using_matplotlib_with_animation_in_matplotlib_and_emojis_in_matplotlib8
plt.figure(figsize=(8, 5), # size
dpi=200, # dpi
facecolor='yellow' # color of background
)
plt.plot(x1, y1)