Skip to content

Commit

Permalink
Merge pull request #38486 from mantidproject/mantidaxes_lines_and_ren…
Browse files Browse the repository at this point in the history
…ameworkspace_exception

account for lines sharing graphs with workspaces in mantidaxes
  • Loading branch information
peterfpeterson authored Jan 9, 2025
2 parents 17ee6bb + 2e7242e commit 0681ab2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions Framework/PythonInterface/mantid/plots/mantidaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# This file is part of the mantid package
from collections.abc import Iterable
import copy
from enum import IntEnum
from functools import wraps

import numpy as np
Expand Down Expand Up @@ -37,9 +38,13 @@

WATERFALL_XOFFSET_DEFAULT, WATERFALL_YOFFSET_DEFAULT = 10, 20


# -----------------------------------------------------------------------------
# Decorators
# -----------------------------------------------------------------------------
class AxisArgType(IntEnum):
WORKSPACE = 0
LINE = 1


def plot_decorator(func):
Expand All @@ -50,6 +55,8 @@ def wrapper(self, *args, **kwargs):
# Saves saving it on array objects
if datafunctions.validate_args(*args, **kwargs):
# Fill out kwargs with the values of args
kwargs["argType"] = AxisArgType.WORKSPACE

kwargs["workspaces"] = args[0].name()
kwargs["function"] = func_name

Expand All @@ -58,8 +65,9 @@ def wrapper(self, *args, **kwargs):
if "cmap" in kwargs and isinstance(kwargs["cmap"], Colormap):
kwargs["cmap"] = kwargs["cmap"].name
self.creation_args.append(kwargs)
elif func_name == "axhline" or func_name == "axvline":
self.creation_args.append({"function": func_name, "args": args, "kwargs": kwargs})
elif func_name in ["axhline", "axvline"]:
new_creation_args = {"function": func_name, "args": args, "kwargs": kwargs, "argType": AxisArgType.LINE}
self.creation_args.append(new_creation_args)

return func_value

Expand Down Expand Up @@ -478,8 +486,11 @@ def rename_workspace(self, new_name, old_name):
:param new_name : the new name of workspace
:param old_name : the old name of workspace
"""

for cargs in self.creation_args:
if cargs["workspaces"] == old_name:
argType = cargs["argType"]
# for workspace creation args, since lines dont have "workspaces"
if argType == AxisArgType.WORKSPACE and cargs["workspaces"] == old_name:
cargs["workspaces"] = new_name
for ws_name, ws_artist_list in list(self.tracked_workspaces.items()):
for ws_artist in ws_artist_list:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:class:`~mantid.plots.MantidAxes` accounts for plotting both workspaces and lines on the same axis in the rename case
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def _change_plot_normalization(self, ax):
raise RuntimeError("No spectrum number associated with plot of " "workspace '{}'".format(workspace.name()))

arg_set_copy = copy(arg_set)
for key in ["function", "workspaces", "autoscale_on_update", "norm"]:
for key in ["function", "workspaces", "autoscale_on_update", "norm", "argType"]:
try:
del arg_set_copy[key]
except KeyError:
Expand Down

0 comments on commit 0681ab2

Please sign in to comment.