Seaborn Heatmaps
sns.heatmap is an axes-level function to plot rectangular data as a color-encoded matrix. You need a 2D list or array to draw a heatmap.
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import pandas as pd
foods = np.array([
"pizza",
"pasta",
"lunch box",
"ice cream",
"coffee"
])
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
number_of_orders = pd.DataFrame([[7, 8, 9, 12, 4],
[6, 5, 12, 4, 3],
[3, 5, 7, 9, 12],
[4,2, 7, 10, 15],
[6, 8, 12,9,7]], columns=days)
number_of_orders.index = foods
ax = sns.heatmap(number_of_orders, annot=True)
ax.set(xlabel="Days", ylabel="Foods")
ax.set_title("Food Orders")
plt.show()

number_of_orders is the 2-dimensional list created by pandas DataFrame. It shows the number of orders from Monday to Friday. The x-axis displays the 'Days' using the columns parameter. The y-axis displays the foods using the index parameter. For example, the total number of coffee orders is 6 on Monday. The annot parameter displays the data values in each cell when set to True. You can also use xlabel and ylabel parameters to write a label for the x and y axes. set_title() sets a title for the Axes. You can draw the same heatmap using the Matplotlib library as well.
You can also add a colormap:
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import pandas as pd
foods = np.array([
"pizza",
"pasta",
"lunch box",
"ice cream",
"coffee"
])
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
number_of_orders = pd.DataFrame([[7, 8, 9, 12, 4],
[6, 5, 12, 4, 3],
[3, 5, 7, 9, 12],
[4,2, 7, 10, 15],
[6, 8, 12,9,7]], columns=days)
number_of_orders.index = foods
ax = sns.heatmap(number_of_orders, annot=True, cmap="viridis")
ax.set(xlabel="Days", ylabel="Foods")
ax.set_title("Food Orders")
plt.show()
You can find all the registered colormaps in the Matplotlib webpage. To learn more about Matplotlib colormaps, visit the Matplotlib webpage.