- 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.
推薦閱讀
- Drupal 8 Blueprints
- 認識編程:以Python語言講透編程的本質
- Wireshark Network Security
- GitLab Repository Management
- UML+OOPC嵌入式C語言開發精講
- Learn Swift by Building Applications
- HTML5+CSS3網站設計基礎教程
- C#程序設計基礎:教程、實驗、習題
- BeagleBone Black Cookbook
- 動手學數據結構與算法
- 小程序,巧應用:微信小程序開發實戰(第2版)
- Spring+Spring MVC+MyBatis從零開始學
- Principles of Strategic Data Science
- 創意UI:Photoshop玩轉APP設計
- 零基礎輕松學C++:青少年趣味編程(全彩版)