If your main goal is to visualize the correlation matrix, rather than creating a graph as such, convenient pandas style options are a viable built-in solution:
import pandas as pd import numpy as np rs = np.random.RandomState(0) df = pd.DataFrame(rs.rand(10, 10)) corr = df.corr() corr.style.background_gradient(cmap='coolwarm')

Note that this should be in the backend that supports HTML rendering, such as JupyterLab Notepad. (The automatic light text on a dark background is taken from the existing PR, and not from the latest released version, pandas 0.23).
styling
You can easily limit the accuracy of the numbers:
corr.style.background_gradient(cmap='coolwarm').set_precision(2)

Or get rid of numbers altogether if you prefer a matrix without annotations:
corr.style.background_gradient(cmap='coolwarm').set_properties(**{'font-size': '0pt'})

The style documentation also contains instructions for more complex styles, for example, how to change the display of the cell above which the mouse pointer is located. To save the output, you can return the HTML by adding the render() method and then writing it to a file (or just taking a screenshot for less formal purposes).
Time comparison
In my testing, style.background_gradient() was 4 times faster than plt.matshow() and in sns.heatmap() faster than sns.heatmap() with a 10x10 matrix. Unfortunately, it does not scale as well as plt.matshow() : they take about the same time for a 100x100 matrix, and plt.matshow() works 10 times faster for a matrix.
saving
There are several possible ways to save a stylized data frame:
- Return the HTML by adding the
render() method and then write the result to a file. - Save as a conditional formatted
.xslx file by adding the to_excel() method. - Combine with imgkit to save a bitmap
- Take a screenshot (for less formal purposes).
Update for pandas> = 0.24
By setting axis=None , you can now calculate colors based on the entire matrix, and not for a column or row:
corr.style.background_gradient(cmap='coolwarm', axis=None)
