How to add an empty facet to a relplot or FacetGrid

Question:

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?

Asked By: Rylan Schaeffer

||

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

Answered By: mwaskom
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.