```python
import seaborn as sns
sns.set_theme(style="whitegrid",font_scale=1.3,rc={"grid.linewidth": 0.5,'lines.linewidth': 5,})

import sympy
import numpy as np
```


```python
from sympy import symbols
from sympy.plotting import plot

x = symbols('x')
y = symbols('y')
```

# Pre


```python
f = 0.2*sympy.sin(3*x)+3

x_array = np.linspace(0, 3)
f_array = sympy.lambdify(x, f)(x_array)

fb = {'x':x_array,'y1':f_array,'y2':0,'facecolor' : 'green', 'alpha' : 0.2}

ix=plot(f,
     ylim=(-5,5),
     xlim=(0,5),
     size=(8,6),
     ylabel='',
     fill = fb,
     title='Area under $f(x)$ and $y=0$'
    )

#ix.save('images/curve_introA.png')
```


```python
f = 0.2*sympy.sin(3*x)+3
g = f-1.5

x_array = np.linspace(0, 3)
f_array = sympy.lambdify(x, f)(x_array)
g_array = sympy.lambdify(x, g)(x_array)
fb = {'x':x_array,'y1':f_array,'y2':g_array,'facecolor' : 'green', 'alpha' : 0.2}

ix=plot(f,g,
     ylim=(-5,5),
     xlim=(0,5),
     size=(8,6),
     ylabel='',
     fill = fb,
     title='General: Area between $f(x)$ and $g(x)$',
        markers=False,
    )
#ix.save('images/curve_introB.png')
```

## Example 1.0


```python
f = x + 2
g = x - 2

x_array = np.linspace(0, 3)
f_array = sympy.lambdify(x, f)(x_array)
g_array = sympy.lambdify(x, g)(x_array)

fb = {'x':x_array,'y1':f_array,'y2':g_array,'facecolor' : 'green', 'alpha' : 0.2}

i0=plot(f,g,
     ylim=(-5,8),
     xlim=(-3.5,3.5),
     size=(8,6),
     ylabel='',
     fill = fb
    )

i0.save('images/curve0.png')
```

## Example I.1


```python
f = x+2
g = x**2 -4

x_array = np.linspace(-2, 3)
f_array = sympy.lambdify(x, f)(x_array)
g_array = sympy.lambdify(x, g)(x_array)

fb = {'x':x_array,'y1':f_array,'y2':g_array,'facecolor' : 'green', 'alpha' : 0.2}

i1=plot(f,g,
     ylim=(-5,8),
     xlim=(-3.5,3.5),
     size=(8,6),
     ylabel='',
     fill = fb
    )

i1.save('images/curve2v2.png')
```

## Example 1.1B


```python
f = x+2
g = x**2 -4

x_array = np.linspace(-2, 4)
f_array = sympy.lambdify(x, f)(x_array)
g_array = sympy.lambdify(x, g)(x_array)

fb = {'x':x_array,'y1':f_array,'y2':g_array,'facecolor' : 'green', 'alpha' : 0.2}

i1=plot(f,g,
     ylim=(-5,13),
     xlim=(-5.5,5.5),
     size=(8,6),
     ylabel='',
     fill = fb
    )

i1.save('images/curve2bv2.png')
```

## Example I.2


```python
f = sympy.sin(x)
g = sympy.cos(x)

x_array = np.linspace(0, np.pi/2)
f_array = sympy.lambdify(x, f)(x_array)
g_array = sympy.lambdify(x, g)(x_array)

fb = {'x':x_array,'y1':f_array,'y2':g_array,'facecolor' : 'green', 'alpha' : 0.2}

i2=plot(f,g,
     ylim=(-5,8),
     xlim=(-3.5,3.5),
     size=(8,6),
     ylabel='',
     fill = fb
    )

i2.save('images/curve3v3.png')
```


```python

```


```python

```

## Example I.3


```python
f = sympy.sqrt(4*x)
g = (4/3)*(x-1)

x_array = np.linspace(0, 4)
f1_array = sympy.lambdify(x, f)(x_array)
f2_array = sympy.lambdify(x, -f)(x_array)

g_array = sympy.lambdify(x, g)(x_array)

idx = np.where(x_array>float(sympy.solve(-f - g, x)[0]))[0][0]

fb = {'x':x_array,'y1':f1_array,'y2':np.concatenate((f2_array[0:idx],g_array[idx:])),
      'facecolor' : 'green', 'alpha' : 0.2}

i3=plot(f,-f,
        ylabel='',
        fill = fb,
        show=False,
        ylim=(-5,8),
        xlim=(-4.5,4.5),
        size=(8,6),
        line_color=sns.color_palette()[1]
    )
i3.extend(plot(g,
        ylim=(-5,8),
        xlim=(-3.5,3.5),
        size=(8,6),
        show=False,
        line_color=sns.color_palette()[0])
)

i3.save('images/curve1v2.png')
```


```python
sns.color_palette()[0]
```




    (0.2980392156862745, 0.4470588235294118, 0.6901960784313725)




```python
type(i3)
```




    sympy.plotting.plot.Plot




```python

```


```python

```

ed0fa470d6e517b3878cfe16015a55391617b0df
ipynb
Jupyter Notebook
class/week03/create_plots.ipynb
org-firasm/math_talk
9f3cf0c91d1312bc13b799e9fd14738f5ac60df9
MIT
class/week03/create_plots.ipynb
org-firasm/math_talk
9f3cf0c91d1312bc13b799e9fd14738f5ac60df9
MIT
class/week03/create_plots.ipynb
org-firasm/math_talk
9f3cf0c91d1312bc13b799e9fd14738f5ac60df9
MIT
Qwen/Qwen-72B
1. YES
2. YES