Chapter 6 Data Visualization

6.1 Matplotlib

import matplotlib.pyplot as plt 
img = np.empty((20,30,3))
img[:, :10] = [0, 0.6, 0]
img[:, 10:20] = [1, 1, 1]
img[:, 20:] = [0.6, 0, 0]
plt.imshow(img)
plt.show()

6.2 Exploratory Visualization

Suppose we want to have a look at the distribution of our dataset

df = pd.read_csv('data/housing.csv')
df.hist(bins=50, figsize=(20,15))
plt.show()

Detect how each attribute correlates with the scatter_matrix() function, applied to a subset of attributes. It draws a matrix of scatter plot.

from pandas.plotting import scatter_matrix

attributes = ["median_house_value", "median_income", "total_rooms", "housing_median_age"]
scatter_matrix(df[attributes], figsize=(12, 8))
plt.show()

6.3 Other Packages

6.3.1 Seaborn

6.3.2 Bokeh

6.3.3 Plotly