The most common usecases are presented
matplotlib : To visualize results of computations
pandas : Visualize data from files
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
Used to visualize results of computations
x = np.arange(0,10)
x
y = x**2
y1 = x**1.8
plt.plot(x,y,y1)
Change styles
plt.plot(x,y,'r*')
Zoom, title, axis labels
#Viewing specific portion of graph
plt.xlim(0,4)
plt.ylim(0,10)
#Specifying labels and title
plt.title("TITLE")
plt.xlabel('X LABEL')
plt.ylabel('Y LABEL')
plt.xticks([0,1,2,3,4],['A','B','C','D','E'])
plt.plot(x,y)
Scatter plot to visualize features from two classes
feature = np.random.randint(0,10,(10,2))
labels = np.random.randint(0,2,10)
print(feature)
print(labels)
Each point on the plot is (feature[sample,0],feature[sample,1])
#plt.plot(feature[:,0],feature[:,1],'*') #same, except we dont no if there is an option to include labels
plt.scatter(feature[:,0],feature[:,1],c=labels)
Used to visualize CNN filetrs
mat = np.arange(0,100).reshape(10,10)
mat
plt.imshow(mat)
plt.imshow(mat,cmap='coolwarm')
plt.colorbar()
#For non sqaure matrices, we may have to change the aspect to get the right visualization
mat2 = np.random.randint(0,101,(100,5))
plt.imshow(mat2)
#set correct aspect
plt.imshow(mat2,aspect=0.08)
Use pandas to visualize from files. You dont have to extract columns, set axis labels manually
df = pd.read_csv('files/data_csv.csv')
df
df.plot(x='Age',y='Salary',kind='scatter',title="TITLE")
df.plot(x='Country',y='Salary',kind='bar',title="TITLE")
df1 = pd.read_csv("files/pima-indians-diabetes.csv")
df1.head()
df1["Age"].hist(bins=20)
The same done using matplotlib
plt.hist(df1["Age"].values,bins=20)