From 265dbe4a8c9b42eeb7b8af7bbc7528ad3452581f Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Tue, 28 Jun 2022 21:02:02 +0300 Subject: [PATCH] Fix axis range settings when logging plots --- clearml/binding/matplotlib_bind.py | 7 ++++--- clearml/utilities/plotlympl/mpltools.py | 12 ++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/clearml/binding/matplotlib_bind.py b/clearml/binding/matplotlib_bind.py index df7c9af3..a873ab65 100644 --- a/clearml/binding/matplotlib_bind.py +++ b/clearml/binding/matplotlib_bind.py @@ -470,9 +470,10 @@ class PatchedMatplotlib: pass # let plotly deal with the range in realtime (otherwise there is no real way to change it to - plotly_renderer.plotly_fig.get('layout', {}).get('xaxis', {}).pop('range', None) - plotly_renderer.plotly_fig.get('layout', {}).get('yaxis', {}).pop('range', None) - + if not plotly_renderer.plotly_fig.get("layout", {}).get("xaxis", {}).pop("custom_range", False): + plotly_renderer.plotly_fig.get("layout", {}).get("xaxis", {}).pop("range", None) + if not plotly_renderer.plotly_fig.get("layout", {}).get("yaxis", {}).pop("custom_range", False): + plotly_renderer.plotly_fig.get("layout", {}).get("yaxis", {}).pop("range", None) return deepcopy(plotly_renderer.plotly_fig) plotly_dict = our_mpl_to_plotly(mpl_fig) diff --git a/clearml/utilities/plotlympl/mpltools.py b/clearml/utilities/plotlympl/mpltools.py index 2e66968d..95fb3e89 100644 --- a/clearml/utilities/plotlympl/mpltools.py +++ b/clearml/utilities/plotlympl/mpltools.py @@ -485,6 +485,12 @@ def prep_ticks(ax, index, ax_type, props): axis_dict["tick0"] = tick0 axis_dict["dtick"] = dtick axis_dict["tickmode"] = None + if ax_type == "x" and "xlim" in props: + axis_dict["range"] = [props["xlim"][0], props["xlim"][1]] + axis_dict["custom_range"] = True + elif ax_type == "y" and "ylim" in props: + axis_dict["range"] = [props["ylim"][0], props["ylim"][1]] + axis_dict["custom_range"] = True elif scale == "log": try: axis_dict["tick0"] = props["axes"][index]["tickvalues"][0] @@ -497,16 +503,18 @@ def prep_ticks(ax, index, ax_type, props): axis_dict = dict(nticks=props["axes"][index]["nticks"]) base = axis.get_transform().base if base == 10: - if ax_type == "x": + if ax_type == "x" and "xlim" in props: axis_dict["range"] = [ math.log10(props["xlim"][0]), math.log10(props["xlim"][1]), ] - elif ax_type == "y": + axis_dict["custom_range"] = True + elif ax_type == "y" and "ylim" in props: axis_dict["range"] = [ math.log10(props["ylim"][0]), math.log10(props["ylim"][1]), ] + axis_dict["custom_range"] = True else: axis_dict = dict(range=None, type="linear") warnings.warn(