Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an empty facet to a relplot or FacetGrid

I have a relplot with columns split on one variable. I'd like to add one additional column with no subplot or subpanel. To give a clear example, suppose I have the following plot:

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns

x = np.random.random(10000)
t = np.random.randint(low=0, high=3, size=10000)
y = np.multiply(x, t)
df = pd.DataFrame({'x': x, 't': t, 'y': y})
g = sns.relplot(df, x='x', y='y', col='t')

This generates a plot something like

enter image description here

I want a 4th column for t=3 that displays no data nor axes. I just want a blank white subplot of equal size as the first three subplots. How can I do this?

like image 586
Rylan Schaeffer Avatar asked Sep 02 '25 16:09

Rylan Schaeffer


1 Answers

Add a value not observed in the data to col_order, e.g.

g = sns.relplot(df, x='x', y='y', col='t', col_order=[0, 1, 2, ""])
g.axes.flat[-1].set_title("")

enter image description here

like image 106
mwaskom Avatar answered Sep 05 '25 09:09

mwaskom