22.9 C
New York

Heatmaps – AICorr.com

Heatmaps
This page covers a matplotlib heatmaps tutorial.
A heatmap is a data visualisation technique that represents numerical data in a graphical format. Typically, it displays data values as colors in a two-dimensional matrix. Each cell colour is determined by its numeric value. Heatmaps are commonly applicable within visualising patterns, correlations, or distributions in data across different categories or dimensions. They are especially useful for identifying trends or outliers in large datasets. This is due to grasp of the intensity of colour, which helps to quickly comprehend the significance of values. Heatmaps are widely used in various fields. Such as biology, finance, web analytics, and social sciences for data analysis and decision-making.
Why use heatmaps?
Heatmaps help identify patterns and trends in data that may not be immediately apparent from raw numbers or traditional tabular presentations. They also can reveal correlations between variables or categories by visualising how their values change relative to each other. Furthermore, heatmaps make it easier to spot outliers or unusual values in a dataset. These will often stand out visually due to their distinct color or intensity. Also, they facilitate comparing data across different categories, time periods, or other dimensions. As such, allowing for quick insights into relative performance or distribution.
In addition, by providing a visually intuitive representation of data, heatmaps aid in decision-making processes. This enables stakeholders to make informed choices based on data-driven insights. Finally, heatmaps are effective tools for communicating complex data findings to stakeholders who may not have expertise in data analysis. This is due to the ability to communicate a clear and visually appealing way of presenting information.
Implementation
Matplotlib offers an easy way of creating heatmaps. The library implements them through the imshow() method.
import matplotlib.pyplot as plt

# Sample data
data = [[7, 13, 2, 6, 2, 1], [11, 10, 6, 2, 8, 2], [7, 5, 12, 14, 1, 8],
[2, 10, 12, 1, 4, 3], [9, 10, 5, 5, 1, 3], [13, 10, 5, 9, 2, 6]]

# Heatmap
plt.imshow(data)

# Title and labels
plt.title(‘Heatmap Example’)
plt.xlabel(‘X Axis’)
plt.ylabel(‘Y Axis’)

# Show plot
plt.show()

We can further add and customise the heatmap. This can help with data readability. The above example implements the default colours. The variety of colours refers to a colour map. Matplotlib offers multiple colour maps to choose from. Therefore, we will change the colour map as well as add a colour bar on the right hand side. These techniques apply with the methods cmap and colorbar, respectively.
For more information about colour maps, please refer to the matplotlib documentation here.
import matplotlib.pyplot as plt

# Sample data
data = [[7, 13, 2, 6, 2, 1], [11, 10, 6, 2, 8, 2], [7, 5, 12, 14, 1, 8],
[2, 10, 12, 1, 4, 3], [9, 10, 5, 5, 1, 3], [13, 10, 5, 9, 2, 6]]

# Heatmap
plt.imshow(data, cmap=”twilight”)
plt.colorbar()

# Title and labels
plt.title(‘Heatmap Example’)
plt.xlabel(‘X Axis’)
plt.ylabel(‘Y Axis’)

# Show plot
plt.show()

This is an original matplotlib heatmaps tutorial. Created by aicorr.com.
Next: Multiple Subplots

Related articles

Recent articles