Visualizing heat maps
Let's look at how to visualize heat maps in this recipe. This is a pictorial representation of data where two groups are associated point by point. The individual values that are contained in a matrix are represented as color values in the plot.
How to do it…
- Create a new Python file, and import the following packages:
import numpy as np import matplotlib.pyplot as plt
- Define the two groups:
# Define the two groups group1 = ['France', 'Italy', 'Spain', 'Portugal', 'Germany'] group2 = ['Japan', 'China', 'Brazil', 'Russia', 'Australia']
- Generate a random 2D matrix:
# Generate some random values data = np.random.rand(5, 5)
- Create a figure:
# Create a figure fig, ax = plt.subplots()
- Create the heat map:
# Create the heat map heatmap = ax.pcolor(data, cmap=plt.cm.gray)
- Plot these values:
# Add major ticks at the middle of each cell ax.set_xticks(np.arange(data.shape[0])...