Back to PyCampNextLevel Outline
Don't let that keep you behind.
Lets practice plotting functions to keep in shape!
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
def parabola(x):
return x * x
domain = np.linspace(-5,5,100) # a 100 points between [5, -5]
df = pd.DataFrame({"domain":domain, "range":[parabola(n) for n in domain]}) # slower
df.head()
domain | range | |
---|---|---|
0 | -5.00000 | 25.000000 |
1 | -4.89899 | 24.000102 |
2 | -4.79798 | 23.020610 |
3 | -4.69697 | 22.061524 |
4 | -4.59596 | 21.122845 |
df.plot(x="domain", y="range", title="PARABOLA");
df = pd.DataFrame({"domain":domain, "range":np.power(domain, 3)}) # faster than before
df.plot(x="domain", y="range", title="3RD POWER", color='orange');
df = pd.DataFrame({"domain":domain, "sine":np.sin(domain), "cosine":np.cos(domain)})
# gca stands for 'get current axis'
ax = plt.gca()
df.plot(kind='line',x='domain',y='sine', color='orange', ax=ax)
df.plot(kind='line',x='domain',y='cosine', color='black', ax=ax)
plt.show();