Skip to content

Instantly share code, notes, and snippets.

@cwindolf
Last active December 6, 2022 22:59
Show Gist options
  • Save cwindolf/4f5eaa1658f9ad30290c84a9a3ec8c92 to your computer and use it in GitHub Desktop.
Save cwindolf/4f5eaa1658f9ad30290c84a9a3ec8c92 to your computer and use it in GitHub Desktop.
Inline {x,y}axis labels in Matplotlib
# https://stackoverflow.com/a/74706214/3979938
from matplotlib.transforms import offset_copy
def inline_xlabel(ax, label):
t = offset_copy(
ax.transAxes,
y=-(ax.xaxis.get_tick_padding() + ax.xaxis.get_tick_space()),
fig=fig,
units='points'
)
ax.xaxis.set_label_coords(.5, 0, transform=t)
ax.set_xlabel(label, va='top')
def inline_ylabel(ax, label):
t = offset_copy(
ax.transAxes,
x=-(ax.yaxis.get_tick_padding() + ax.yaxis.get_tick_space()),
fig=fig,
units='points'
)
ax.yaxis.set_label_coords(0, .5, transform=t)
ax.set_ylabel(label, va='bottom')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment