Bikash Santra
Indian Statistical Institute, Kolkata
import matplotlib # OR, from matplotlib import pyplot as plt
import numpy as np
print(matplotlib.__version__)
3.3.4
# The inline is important for the notebook, so that plots are displayed in the notebook and not in a new window.
import matplotlib.pyplot as plt
image = np.random.randint(0,256,(30,30,3))
# image = np.random.rand(30, 30)
plt.imshow(image, cmap=plt.cm.hot)
plt.colorbar()
plt.show()
print(image[5,5], np.max(image), np.min(image))
[ 66 120 222] 255 0
plt.imshow(image, cmap=plt.cm.hot)
plt.colorbar()
plt.show()
fig = plt.figure()
image1 = np.random.randint(0, 2, (30, 30))
image2 = np.random.randint(0, 256, (30, 30))
image3 = np.random.randint(0, 256, (30, 30,3))
image4 = np.random.randint(0, 256, (30, 90,3))
x = np.linspace(0, 3, 20)
plt.subplot(4, 3, 1)
plt.imshow(image1, cmap = plt.cm.binary)
plt.subplot(4, 3, 2)
plt.imshow(image2, cmap = plt.cm.gray)
plt.subplot(4, 3, 3)
plt.imshow(image3, cmap = plt.cm.hot)
plt.subplot(4, 1, 2)
plt.imshow(image4, cmap = plt.cm.hot)
plt.subplot(4, 3, 7)
plt.plot(x, np.sqrt(x))
plt.xticks(())
plt.yticks(())
plt.subplot(4, 3, 8)
plt.plot(x, ((0.2*x)+0.7))
plt.xticks(())
plt.yticks(())
plt.subplot(4, 3, 9)
plt.plot(x, x**3)
plt.xticks(())
plt.yticks(())
plt.subplot(4, 2, 7)
plt.plot(x, 5*(x**5))
plt.xticks(())
plt.yticks(())
plt.subplot(4, 2, 8)
plt.plot(x,(x*(x**(1/2))))
plt.xticks(())
plt.yticks(())
plt.show()
# Regular Plots
n = 256
X = np.linspace(-np.pi, np.pi, n, endpoint=True)
Y = np.sin(2 * X)
plt.axes([0.025, 0.025, 0.95, 0.95])
plt.plot(X, Y + 1, color='blue', alpha=1.00)
plt.fill_between(X, 1, Y + 1, color='blue', alpha=.25)
plt.plot(X, Y - 1, color='blue', alpha=1.00)
plt.fill_between(X, -1, Y - 1, (Y - 1) > -1, color='blue', alpha=.25)
plt.fill_between(X, -1, Y - 1, (Y - 1) < -1, color='red', alpha=.25)
plt.xlim(-np.pi, np.pi)
plt.xticks(())
plt.ylim(-2.5, 2.5)
plt.yticks(())
plt.show()
# Scaller Plot
n = 1024
X = np.random.normal(0, 1, n)
Y = np.random.normal(0, 1, n)
T = np.arctan2(Y, X)
plt.axes([0.025, 0.025, 0.95, 0.95])
plt.scatter(X, Y, s=75, c=T, alpha=.5)
plt.xlim(-1.5, 1.5)
plt.xticks(())
plt.ylim(-1.5, 1.5)
plt.yticks(())
plt.show()
# Bar plots
n = 12
X = np.arange(n)
Y1 = (1 - X / float(n)) * np.random.uniform(0.5, 1.0, n)
Y2 = (1 - X / float(n)) * np.random.uniform(0.5, 1.0, n)
plt.axes([0.025, 0.025, 0.95, 0.95])
plt.bar(X, +Y1, facecolor='#9999ff', edgecolor='white')
plt.bar(X, -Y2, facecolor='#ff9999', edgecolor='white')
for x, y in zip(X, Y1):
plt.text(x + 0.4, y + 0.05, '%.2f' % y, ha='center', va= 'bottom')
for x, y in zip(X, Y2):
plt.text(x + 0.4, -y - 0.05, '%.2f' % y, ha='center', va= 'top')
plt.xlim(-.5, n)
plt.xticks(())
plt.ylim(-1.25, 1.25)
plt.yticks(())
plt.show()
a) Matpltlob documentation gallery
b) https://www.scipy-lectures.org/intro/matplotlib/index.html
c) https://www.scipy-lectures.org/packages/3d_plotting/index.html
d) https://github.com/kuleshov/cs228-material/blob/master/tutorials/python/cs228-python-tutorial.ipynb