import numpy as np
x = np.linspace(0, 10, 20)
y = x ** 2
# Let's plot the relationship between X and Y
# Don't hesitate to draw plot !
import matplotlib.pyplot as plt
%matplotlib inline
plt.plot(x, y)
# OK, But there is no title and labels of x and y.
# Lets add them
plt.xlabel('X')
# Uhm... Something happened
# But's there exactly no plot at all except creating x label.
# We need to re-write plotting codes again.
plt.plot(x, y)
plt.xlabel('X')
plt.ylabel('Y')
# Ah... Forgot to draw title of the plot
plt.plot(x, y)
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Simple X and Y')
# We did that all we want draw. But this is a kind of stupid approach, isn't it?
# Let's do the same thing with object-oriented style
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(x, y)
ax1.set_xlabel('X')
fig
ax1.set_ylabel('Y')
ax1.set_title('Simple X and Y')
fig
# Isn't it more intuitive?
# In MATLAB style coding, it's hard to adjust previous plot.
# If you want to do that, you should re-write previous code again. That's bad.
# (Actually there is a way to catch previous handle,
# but it should use something special. ex) ax = plt.gca()