In [189]:
##set color scheme
light_green="#36B37E"
mid_green="#00875A"
dark_green="#006644"

light_red="#DCBCBC"
mid_red="#B97C7C"
dark_red="#8F2727"

ink="#172B4D"
light_highlight="#505F79"
fade = "#B3BAC5"
dark_fade="#8993A4"

import numpy as np
import scipy.special
import scipy.stats as st
import scipy.optimize as opt
from scipy.stats import beta

from math import sqrt as sqrt

from matplotlib import pyplot as plt
plt.style.use('seaborn-white')

import pandas as pd 
import altair as alt 
In [52]:
data = pd.DataFrame({
    'Country': ['Africa', 'Asia', 'Europe', 'Middle East', 'North America'],
    'number_students': [1, 16, 10, 1, 5]}
)

num_students = alt.Chart().mark_bar().encode(
        y='Country',
        x=alt.X('number_students', title='Number of students', scale=alt.Scale(domain=(0, 16)))
)

chart = alt.layer(num_students).properties(
    data=data
).configure_view(
        height=400,
        width=500
).configure_axis(
        titleFontSize=14,
        titleFontWeight='normal'
).properties(
    width=600,
    height=175
)
In [53]:
chart.configure_scale(
        bandPaddingInner=0.3,
        bandPaddingOuter=1
).configure_axisX(labelFontSize=14
).configure_axisY(labelFontSize=14)
Out[53]:
In [54]:
data = pd.DataFrame({
    'Background': ['Technical', 'Non-Technical'],
    'number_students': [15, 16]}
)

num_students = alt.Chart().mark_bar().encode(
        y='Background',
        x=alt.X('number_students', title='Number of students', scale=alt.Scale(domain=(0, 16)))
)

chart = alt.layer(num_students).properties(
    data=data
).configure_view(
        height=400,
        width=500
).configure_axis(
        titleFontSize=14,
        titleFontWeight='normal'
).properties(
    width=600,
    height=175
)
In [55]:
chart.configure_scale(
        bandPaddingInner=0.3,
        bandPaddingOuter=1
).configure_axisX(labelFontSize=14
).configure_axisY(labelFontSize=14)
Out[55]:
In [59]:
def simple_function(x):
    return 5*(x-5)**2 + 3*(x-5)**3+5

# generate grid for plotting
x = np.linspace(0, 10, 400, endpoint=True)
In [113]:
plt.figure(figsize=(11, 4), dpi=160)

# limits
plt.xlim(3.0, 6.0)
plt.ylim(0.0, 10.0)

plt.xticks([])
plt.yticks([])

ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.spines['left'].set_color(light_highlight)
ax.spines['bottom'].set_color(light_highlight)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
plt.xlabel('$x$ or independent variable', fontsize=18)
plt.ylabel('$y$ or dependant variable', fontsize=18)

plt.plot(x, simple_function(x), color=dark_red, linewidth=2.0, linestyle="-")
plt.title("")
plt.savefig("graph1.png", dpi=160)
In [158]:
def exercise_function1(x):
    return -100000 + 28000*x

# generate grid for plotting
x = np.linspace(-10, 10, 400, endpoint=True)
plt.figure(figsize=(11, 4), dpi=160)

# limits
plt.xlim(0.0, 6.0)
plt.ylim(-120000.0, 120000.0)


plt.plot(x, exercise_function1(x), color=dark_red, linewidth=2.0, linestyle="-")
plt.savefig("graph2.png", dpi=160)
In [197]:
def fixed_point(x):
    return x

# generate grid for plotting
x = np.linspace(0, 10, 400, endpoint=True)
plt.figure(figsize=(11, 4), dpi=160)


# limits
plt.xlim(0.0, 5.0)
plt.ylim(0.0, 5.0)

plt.plot(x, fixed_point(x), color=light_red, linewidth=2.0, linestyle="-", label="$f(x) = x$")
plt.plot(x, x**2, color=dark_red, linewidth=2.0, linestyle="-", label="$f(x) = x^2$")
plt.plot(x, x**(1/2), color=ink, linewidth=2.0, linestyle="-", label="$f(x) = \sqrt{x}$")
plt.legend(loc='upper left', fontsize=10)
plt.savefig("graph3.png", dpi=160)
In [216]:
def fixed_point(x):
    return 3*x**2 - 3*x - 4

# generate grid for plotting
x = np.linspace(-10, 10, 400, endpoint=True)
plt.figure(figsize=(6, 4), dpi=160)

## axes 
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.spines['left'].set_color(light_highlight)
ax.spines['bottom'].set_color(light_highlight)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

# limits
plt.xlim(-5.0, 5.0)
plt.ylim(-10.0, 35.0)

plt.plot(x, fixed_point(x), color=dark_red, linewidth=2.0, linestyle="-", label="$f(x) = 3x^2 - 3x - 4$")

plt.legend(loc='upper center', fontsize=10)
plt.title("$a > 0$, curve has a minimum", loc='left', pad=10, color=lines, fontsize=10)

plt.savefig("graph4.png", dpi=160)
In [220]:
def fixed_point(x):
    return -x**2 + 4*x - 2

# generate grid for plotting
x = np.linspace(-10, 10, 400, endpoint=True)
plt.figure(figsize=(6, 4), dpi=160)

## axes 
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.spines['left'].set_color(light_highlight)
ax.spines['bottom'].set_color(light_highlight)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

# limits
plt.xlim(-1.0, 5.0)
plt.ylim(-3.0, 3.0)

plt.plot(x, fixed_point(x), color=dark_red, linewidth=2.0, linestyle="-", label="$f(x) = -x^2 + 4x - 2$")

plt.legend(loc='upper center', fontsize=10)
plt.title("$a < 0$, curve has a maximum", loc='left', pad=10, color=lines, fontsize=10)

plt.savefig("graph5.png", dpi=160)
In [ ]: