From 64c0b6e0ab8f8ca715a4ca561be18a126e29152d Mon Sep 17 00:00:00 2001 From: Phil Colebrooke <philipc99@hotmail.co.uk> Date: Tue, 10 Mar 2020 13:21:57 +0000 Subject: [PATCH] Re #28308 add check for plot already having fills + test --- .../PythonInterface/mantid/plots/datafunctions.py | 3 +++ .../PythonInterface/mantid/plots/mantidaxes.py | 2 +- .../test/python/mantid/plots/plots__init__Test.py | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Framework/PythonInterface/mantid/plots/datafunctions.py b/Framework/PythonInterface/mantid/plots/datafunctions.py index af7e0992f3c..ec1b3bd9451 100644 --- a/Framework/PythonInterface/mantid/plots/datafunctions.py +++ b/Framework/PythonInterface/mantid/plots/datafunctions.py @@ -949,6 +949,9 @@ def waterfall_fill_is_line_colour(ax): def waterfall_create_fill(ax): + if ax.waterfall_has_fill(): + return + errorbar_cap_lines = remove_and_return_errorbar_cap_lines(ax) for i, line in enumerate(ax.get_lines()): diff --git a/Framework/PythonInterface/mantid/plots/mantidaxes.py b/Framework/PythonInterface/mantid/plots/mantidaxes.py index a6f16a7f8f6..0681624a0e1 100644 --- a/Framework/PythonInterface/mantid/plots/mantidaxes.py +++ b/Framework/PythonInterface/mantid/plots/mantidaxes.py @@ -1024,7 +1024,7 @@ class MantidAxes(Axes): else: if bool(x_offset) or bool(y_offset) or fill: raise RuntimeError("You have set waterfall to false but have given a non-zero value for the offset or " - "set fill to true.") + "set fill to true.") if not self.is_waterfall(): # Nothing needs to be changed. diff --git a/Framework/PythonInterface/test/python/mantid/plots/plots__init__Test.py b/Framework/PythonInterface/test/python/mantid/plots/plots__init__Test.py index dca6fcbd739..6d34107ee73 100644 --- a/Framework/PythonInterface/test/python/mantid/plots/plots__init__Test.py +++ b/Framework/PythonInterface/test/python/mantid/plots/plots__init__Test.py @@ -649,6 +649,21 @@ class Plots__init__Test(unittest.TestCase): # Check that there are now three filled areas and the new fill colour matches the others. self.assertTrue((ax.collections[2].get_facecolor() == [1, 0, 0, 1]).all()) + def test_fills_not_created_if_waterfall_plot_already_has_filled_areas(self): + fig, ax = plt.subplots(subplot_kw={'projection': 'mantid'}) + ax.plot([0, 1], [0, 1]) + ax.plot([0, 1], [0, 1]) + + # Make a waterfall plot + ax.set_waterfall(True) + + # Add filled areas twice + ax.set_waterfall_fill(True) + ax.set_waterfall_fill(True) + + # There should still be only two filled areas (one for each line) + self.assertEqual(len(datafunctions.get_waterfall_fills(ax)), 2) + def _run_check_axes_distribution_consistency(self, normalization_states): mock_tracked_workspaces = { 'ws': [ -- GitLab