import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
# generate data
x = np.linspace(0,5,11)
y = x ** 2
x
y
# Functional Method
plt.plot(x,y,)
plt.xlabel('xlabel')
plt.ylabel('ylabel')
plt.title('sample plot')
plt.subplot(1,2,1)
plt.plot(x,y,'r')
plt.subplot(1,2,2)
plt.plot(y,x,)
# OO Method
fig = plt.figure()
axes = fig.add_axes([0.1,0.1,0.8,0.8])
axes.plot(x,y)
axes.set_xlabel('X label')
axes.set_ylabel('Y label')
axes.set_title('Plot Title')
fig = plt.figure()
axes1 = fig.add_axes([0.1,0.1,0.8,0.8])
axes2 = fig.add_axes([0.5,0.1,0.4,0.5])
axes1.plot(y, x)
axes2.plot(x, y,'r')
# axes title.
axes1.set_title('Large Plot')
axes2.set_title('small Plot')
fig, axes = plt.subplots(nrows=1,ncols=2)
axes[0].plot(x,y)
axes[0].set_title('First Plot')
axes[1].plot(y,x,'r')
axes[1].set_title('second plot')
plt.tight_layout()
fig,axes = plt.subplots(nrows=2,ncols=1,figsize=(5,2))
axes[0].plot(x,y)
axes[1].plot(y,x,'r')
plt.tight_layout()
fig.savefig('matplot_fig.png',dpi=200)
fig = plt.figure()
ax = fig.add_axes([0.1,0.1,0.8,0.8])
ax.plot(x,y, label='X-Squared')
ax.plot(x*2,y, label='X-Doubled')
ax.legend(loc=0)
fig = plt.figure()
ax = fig.add_axes([0.0,0.0,0.8,0.8])
ax.plot(x,y,lw=2, alpha=0.5,ls='-.',
marker='o', markersize=10,
)
# # between markers
# ax.set_xlim([0,2])
# ax.set_ylim([0,5])