Skip to content

Commit 0681ab2

Browse files
Merge pull request #38486 from mantidproject/mantidaxes_lines_and_renameworkspace_exception
account for lines sharing graphs with workspaces in mantidaxes
2 parents 17ee6bb + 2e7242e commit 0681ab2

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Framework/PythonInterface/mantid/plots/mantidaxes.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# This file is part of the mantid package
88
from collections.abc import Iterable
99
import copy
10+
from enum import IntEnum
1011
from functools import wraps
1112

1213
import numpy as np
@@ -37,9 +38,13 @@
3738

3839
WATERFALL_XOFFSET_DEFAULT, WATERFALL_YOFFSET_DEFAULT = 10, 20
3940

41+
4042
# -----------------------------------------------------------------------------
4143
# Decorators
4244
# -----------------------------------------------------------------------------
45+
class AxisArgType(IntEnum):
46+
WORKSPACE = 0
47+
LINE = 1
4348

4449

4550
def plot_decorator(func):
@@ -50,6 +55,8 @@ def wrapper(self, *args, **kwargs):
5055
# Saves saving it on array objects
5156
if datafunctions.validate_args(*args, **kwargs):
5257
# Fill out kwargs with the values of args
58+
kwargs["argType"] = AxisArgType.WORKSPACE
59+
5360
kwargs["workspaces"] = args[0].name()
5461
kwargs["function"] = func_name
5562

@@ -58,8 +65,9 @@ def wrapper(self, *args, **kwargs):
5865
if "cmap" in kwargs and isinstance(kwargs["cmap"], Colormap):
5966
kwargs["cmap"] = kwargs["cmap"].name
6067
self.creation_args.append(kwargs)
61-
elif func_name == "axhline" or func_name == "axvline":
62-
self.creation_args.append({"function": func_name, "args": args, "kwargs": kwargs})
68+
elif func_name in ["axhline", "axvline"]:
69+
new_creation_args = {"function": func_name, "args": args, "kwargs": kwargs, "argType": AxisArgType.LINE}
70+
self.creation_args.append(new_creation_args)
6371

6472
return func_value
6573

@@ -478,8 +486,11 @@ def rename_workspace(self, new_name, old_name):
478486
:param new_name : the new name of workspace
479487
:param old_name : the old name of workspace
480488
"""
489+
481490
for cargs in self.creation_args:
482-
if cargs["workspaces"] == old_name:
491+
argType = cargs["argType"]
492+
# for workspace creation args, since lines dont have "workspaces"
493+
if argType == AxisArgType.WORKSPACE and cargs["workspaces"] == old_name:
483494
cargs["workspaces"] = new_name
484495
for ws_name, ws_artist_list in list(self.tracked_workspaces.items()):
485496
for ws_artist in ws_artist_list:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:class:`~mantid.plots.MantidAxes` accounts for plotting both workspaces and lines on the same axis in the rename case

qt/applications/workbench/workbench/plotting/figureinteraction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ def _change_plot_normalization(self, ax):
861861
raise RuntimeError("No spectrum number associated with plot of " "workspace '{}'".format(workspace.name()))
862862

863863
arg_set_copy = copy(arg_set)
864-
for key in ["function", "workspaces", "autoscale_on_update", "norm"]:
864+
for key in ["function", "workspaces", "autoscale_on_update", "norm", "argType"]:
865865
try:
866866
del arg_set_copy[key]
867867
except KeyError:

0 commit comments

Comments
 (0)