Correlations and heatmaps

As promised, let's learn an easier way to generate heatmaps compared to what we had to do in Chapter 5, Visualizing Data with Pandas and Matplotlib. Once again, we will make a heatmap of the correlations between the OHLC stock prices, the log of volume traded, and the daily difference between the highest and lowest prices (max_abs_change); however, this time, we will use seaborn, which gives us the heatmap() function for an easier way to produce this visualization:

>>> sns.heatmap(...     fb.sort_index().assign(...         volume=np.log(fb.volume), ...         max_abs_change=fb.high - fb.low...     ).corr(), ...     annot=True, center=0... )

We also pass center=0 so that seaborn puts values of 0 (no correlation) at the center of the colormap ...

Get Hands-On Data Analysis with Pandas now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.