# 12.6. Math Plotting¶

• matplotlib allows to plot charts

• requires installation pip install matplotlib

• matplotlib.pyplot is used for 2D charts

## 12.6.1. Matplotlib and Jupyter¶

• To display matplotlib figures inline, you have run at least once per kernel run:

%matplotlib inline


## 12.6.2. Points¶

Figure 12.8. Points chart

Matplotlib example:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [1, 2, 3, 4]
plt.plot(x, y, 'o')
plt.show()


## 12.6.3. Sinusoid on grid¶

Figure 12.9. Sinusoid on grid

Matplotlib example:

import matplotlib.pyplot as plt
import numpy as np

y = np.arange(0.0, 2.0, 0.01)
x = 1 + np.sin(2 * np.pi * y)

fig, ax = plt.subplots()

ax.plot(y, x)
ax.grid()
ax.set(
xlabel='time (s)',
ylabel='voltage (mV)',
title='Voltage in Time')

plt.show()


## 12.6.4. Multiple charts¶

Figure 12.10. Multiple charts

Matplotlib example:

import numpy as np
import matplotlib.pyplot as plt

def f(t):
return np.exp(-t) * np.cos(2 * np.pi * t)

t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)

plt.figure(1)
plt.subplot(211)
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')

plt.subplot(212)
plt.plot(t2, np.cos(2 * np.pi * t2), 'r--')
plt.show()