INNER CODE UNIT · Python
trim
lgienapp/aquarel · aquarel/transforms.py:40
def trim(axis: str):
"""
Trims axes of a plot to first and last major tick.
Code partly taken from https://github.com/mwaskom/seaborn/blob/563e96d3be1eaee8db8dfbccf7eed1f1c66dfd31/seaborn/utils.py#L292
:param axis: axes to apply the trim to. Can be {"x", "y", "both"}.
"""
# Apply trim to all axes
for ax_i in plt.gcf().axes:
if axis in ["x", "both"]:
# Trim x direction (bottom and top)
xticks_major = np.asarray(ax_i.get_xticks(minor=False))
xticks = np.asarray(ax_i.get_xticks(minor=True))
if xticks.size:
# Get first and last major ticks
firsttick = np.compress(
xticks_major >= min(ax_i.get_xlim()), xticks_major
)[0]