Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

seabornのpairplotで下半分(上半分)だけ表示する

More than 1 year has passed since last update.

https://tutorialmore.com/questions-1150768.htmにやり方があったのでメモ。

import seaborn as sns
import matplotlib.pyplot as plt


def hide_current_axis(*args, **kwds):
    plt.gca().set_visible(False)

# データフレーム準備
X = sns.load_dataset("iris")

# ペアプロット
pg = sns.pairplot(X)

# 上のグラフを消す=下三角部分を表示
pg.map_upper(hide_current_axis)

# 下のグラフを消す=上三角部分を表示
# pg.map_lower(hide_current_axis)

# 対角部分を消す
# pg.map_diag(hide_current_axis)

スクリーンショット 2020-02-26 22.45.00.png

もしくはpairgridで好きな位置に好きなグラフを配置する。

from itertools import groupby
import seaborn as sns
import matplotlib.pyplot as plt


def hide_current_axis(*args, **kwds):
    plt.gca().set_visible(False)


def stackedhist(data, stackby, **kwds):
    groups = groupby(zip(stackby, data), lambda x: x[0])
    grouped_data = [[v for _, v in items] for key, items in groups]
    plt.hist(grouped_data, stacked=True, edgecolor='none')


# データフレーム準備
X = sns.load_dataset("iris")

g = sns.PairGrid(X, diag_sharey=False)
g.map_lower(sns.scatterplot, data=X, hue='species', alpha=0.3, edgecolor='none')
g.map_diag(stackedhist, stackby=X['species'])
g.map_upper(hide_current_axis)

スクリーンショット 2020-02-26 22.47.16.png

ground0state
「小さいネタでもoutput」をモットーに小ネタ投稿していきます。 統計検定準1級/G検定2018#2/IoTエキスパート/Signate/kaggle/AWS/Serverless
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away