- Python Data Analysis Cookbook
- Ivan Idris
- 194字
- 2021-07-14 11:05:40
Viewing a matrix of scatterplots
If you don't have many variables in your dataset, it is a good idea to view all the possible scatterplots for your data. You can do this with one function call from either seaborn or pandas. These functions display a matrix of plots with kernel density estimation plots or histograms on the diagonal.
How to do it...
- Imports the following:
import pandas as pd from dautil import data from dautil import ts import matplotlib.pyplot as plt import seaborn as sns import matplotlib as mpl
- Load the weather data with the following lines:
df = data.Weather.load() df = ts.groupby_yday(df).mean() df.columns = [data.Weather.get_header(c) for c in df.columns]
- Plot with the Seaborn
pairplot()
function, which plots histograms on the diagonal by default:%matplotlib inline # Seaborn plotting, issues due to NaNs sns.pairplot(df.fillna(0))
The following plots are the result:
- Plot similarly with the pandas
scatter_matrix()
function and request kernel density estimation plots on the diagonal:sns.set({'figure.figsize': '16, 12'}) mpl.rcParams['axes.linewidth'] = 9 mpl.rcParams['lines.linewidth'] = 2 plots = pd.scatter_matrix(df, marker='o', diagonal='kde') plt.show()
Refer to the following plots for the end result:

The complete code is available in the scatter_matrix.ipynb
file in this book's code bundle.
推薦閱讀
- 多媒體CAI課件設計與制作導論(第二版)
- ASP.NET Web API:Build RESTful web applications and services on the .NET framework
- Python數據可視化:基于Bokeh的可視化繪圖
- ASP.NET Core 5.0開發入門與實戰
- Vue.js前端開發基礎與項目實戰
- Vue.js 3.x從入門到精通(視頻教學版)
- Java FX應用開發教程
- x86匯編語言:從實模式到保護模式(第2版)
- Getting Started with SQL Server 2012 Cube Development
- Java程序設計案例教程
- 軟件供應鏈安全:源代碼缺陷實例剖析
- Visual FoxPro 6.0程序設計
- 大數據時代的企業升級之道(全3冊)
- 官方 Scratch 3.0 編程趣味卡:讓孩子們愛上編程(全彩)
- C語言編程魔法書:基于C11標準