Basic Plotting with Matplotlib¶
In [6]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline # allows notebook plotting
In [7]:
x = np.arange(0, 10)
print x
In [8]:
y = np.sin(x)
print y
In [10]:
plt.plot(x,y)
plt.show()
In [11]:
z = np.cos(x)
print z
In [12]:
plt.plot(x,y)
plt.plot(x,z)
plt.xlabel('range of numbers between 1 and 10')
plt.ylabel('functions of the numbers')
plt.title('some weird sine and cosine graph')
plt.legend(['sine','cosine'])
plt.show()
In [13]:
print x
print y
print z
In [25]:
plt.subplot(2,1,1) # 2 = number of rows, 1= number of column, 1 = number of plot
plt.plot(x,y)
plt.title('Sine')
plt.subplot(2,1,2)
plt.plot(x,z)
plt.title('Cosine')
plt.subplots_adjust(hspace=0.35) # for adjusting linear spaces
plt.show()
showing Images¶
The Thing is that I need an image to explain this subplot. So I would kill two birds with one stone.
In [22]:
from scipy.misc import imread
In [21]:
img_horizontal_subplot = imread('plot_subplot-horizontal_1.png')
plt.imshow(img_horizontal_subplot)
Out[21]:
In [23]:
img_vertical_subplot = imread('plot_subplot-vertical_1.png')
plt.imshow(img_vertical_subplot)
Out[23]:
In [24]:
img_grid_subplot = imread('plot_subplot-grid_1.png')
plt.imshow(img_grid_subplot)
Out[24]: