Skip to content

Instantly share code, notes, and snippets.

@mwaskom
Created July 18, 2021 20:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwaskom/7bf5ee9c474a6d3c9b223188a96e6e43 to your computer and use it in GitHub Desktop.
Save mwaskom/7bf5ee9c474a6d3c9b223188a96e6e43 to your computer and use it in GitHub Desktop.
Put a title on the right y axis of a matplotlib axes using the set_title API.
import matplotlib as mpl
import matplotlib.pyplot as plt
f, ax = plt.subplots(figsize=(5, 5))
ax.set_title("Col title", y=1)
title = ax.set_title(
"Row title", loc="right", y=.5,
rotation=270, ha="left", va="center",
)
offset_trans = mpl.transforms.ScaledTranslation(
mpl.rcParams["axes.titlepad"] / 72, 0, ax.figure.dpi_scale_trans
)
title.set_transform(ax.transAxes + offset_trans)
@mwaskom
Copy link
Author

mwaskom commented Jul 18, 2021

right_title

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment