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.
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 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]) + 0.5, minor=False) ax.set_yticks(np.arange(data.shape[1]) + 0.5, minor=False) # Make it look like a table ax.invert_yaxis...