From 86e85e18530ea71b71fee6a2da696fffb6e95a7c Mon Sep 17 00:00:00 2001 From: Abe Levitan Date: Sun, 19 Oct 2025 13:08:16 +0200 Subject: [PATCH] Fix a bug where the x-axis was double flipped --- src/cdtools/tools/plotting/plotting.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cdtools/tools/plotting/plotting.py b/src/cdtools/tools/plotting/plotting.py index f2357f7..0f570ea 100644 --- a/src/cdtools/tools/plotting/plotting.py +++ b/src/cdtools/tools/plotting/plotting.py @@ -578,7 +578,11 @@ def plot_translations(translations, fig=None, units='$\\mu$m', lines=True, inver linewidth=linewidth) if invert_xaxis: - plt.gca().invert_xaxis() + ax = plt.gca() + x_min, x_max = ax.get_xlim() + # Protect against flipping twice if plotting on top of existing graph + if x_min <= x_max: + ax.invert_xaxis() plt.xlabel('X (' + units + ')') plt.ylabel('Y (' + units + ')')