Skip to content

Commit fd99f02

Browse files
Merge pull request #38346 from peterfpeterson/matplotlib_and_ruff
Matplotlib 3.8 and ruff E402 - ornl-next
2 parents abc1a92 + 6887ca3 commit fd99f02

File tree

53 files changed

+196
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+196
-169
lines changed

Framework/PythonInterface/mantid/plots/mantidaxes.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import numpy as np
1313
import re
1414

15+
from cycler import cycler
1516
from matplotlib.axes import Axes
1617
from matplotlib.cbook import safe_masked_invalid
1718
from matplotlib.collections import Collection, PolyCollection
@@ -22,6 +23,7 @@
2223
from matplotlib.patches import Patch
2324
from matplotlib.table import Table
2425
from matplotlib.ticker import NullLocator
26+
import matplotlib.pyplot as plt
2527
from mpl_toolkits.mplot3d import Axes3D
2628

2729
from mantid import logger
@@ -145,7 +147,9 @@ def from_mpl_axes(ax, ignore_artists=None):
145147
"""
146148
if not ignore_artists:
147149
ignore_artists = []
148-
prop_cycler = ax._get_lines.prop_cycler # tracks line color cycle
150+
151+
default_cycle_colours = plt.rcParams["axes.prop_cycle"].by_key()["color"]
152+
number_of_mpl_lines = len(ax.get_lines())
149153
artists = ax.get_children()
150154
mantid_axes = ax.figure.add_subplot(111, projection="mantid", label="mantid")
151155
for artist in artists:
@@ -155,7 +159,14 @@ def from_mpl_axes(ax, ignore_artists=None):
155159
except NotImplementedError:
156160
pass
157161
mantid_axes.set_title(ax.get_title())
158-
mantid_axes._get_lines.prop_cycler = prop_cycler
162+
163+
if number_of_mpl_lines > 0:
164+
used_colors = default_cycle_colours[: (number_of_mpl_lines % len(default_cycle_colours)) + 1]
165+
remaining_colors = default_cycle_colours[(number_of_mpl_lines % len(default_cycle_colours)) + 1 :]
166+
default_cycle_colours = remaining_colors + used_colors
167+
168+
mantid_axes.set_prop_cycle(cycler(color=default_cycle_colours))
169+
159170
ax.remove()
160171
return mantid_axes
161172

Framework/PythonInterface/plugins/algorithms/AngularAutoCorrelationsSingleAxis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
66
# SPDX - License - Identifier: GPL - 3.0 +
77
# pylint: disable=too-many-branches,too-many-locals, invalid-name
8+
# ruff: noqa: E741 # Ambiguous variable name
89
from mantid.api import AlgorithmFactory, FileAction, FileProperty, PythonAlgorithm, WorkspaceProperty
910
from mantid.kernel import Direction
1011
from mantid.simpleapi import logger, CreateWorkspace

Framework/PythonInterface/plugins/algorithms/AngularAutoCorrelationsTwoAxes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
66
# SPDX - License - Identifier: GPL - 3.0 +
77
# pylint: disable=too-many-branches,too-many-locals, invalid-name
8+
# ruff: noqa: E741 # Ambiguous variable name
89
from mantid.api import AlgorithmFactory, FileAction, FileProperty, PythonAlgorithm, WorkspaceProperty
910
from mantid.kernel import Direction
1011
from mantid.simpleapi import logger, CreateWorkspace

Framework/PythonInterface/plugins/algorithms/CreateLeBailFitInput.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
66
# SPDX - License - Identifier: GPL - 3.0 +
77
# pylint: disable=no-init,invalid-name
8+
# ruff: noqa: E741 # Ambiguous variable name
89
import mantid.simpleapi as api
910
from mantid.api import (
1011
AlgorithmFactory,

Framework/PythonInterface/plugins/algorithms/CylinderPaalmanPingsCorrection2.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,10 @@ def _sum_rom(self, n_scat, n_abs, a, r1, r2, ms, theta, amu_scat, amu_tot_i, amu
773773
Area_y = r * r_step * omega_ster * amu_scat[n_scat]
774774
sum_1 = 0.0
775775
sum_2 = 0.0
776-
I = 1
776+
i = 1
777777
Area_sum = 0.0
778778
for _ in range(1, number_omega + 1):
779-
omega = I * omega_ster + omega_deg
779+
omega = i * omega_ster + omega_deg
780780
distance = r * math.sin(omega)
781781

782782
skip = True
@@ -790,11 +790,11 @@ def _sum_rom(self, n_scat, n_abs, a, r1, r2, ms, theta, amu_scat, amu_tot_i, amu
790790
LIS.append(LISN - LIST)
791791
#
792792
# CALCULATE DISTANCE SCATTERED NEUTRON PASSES THROUGH EACH ANNULUS
793-
O = omega + theta_deg
793+
omega_scattered = omega + theta_deg
794794
LSS = []
795795
for j in range(0, nan):
796-
LSST = self._distance(r, self._radii[j], O)
797-
LSSN = self._distance(r, self._radii[j + 1], O)
796+
LSST = self._distance(r, self._radii[j], omega_scattered)
797+
LSSN = self._distance(r, self._radii[j + 1], omega_scattered)
798798
LSS.append(LSSN - LSST)
799799
#
800800
# CALCULATE ABSORPTION FOR PATH THROUGH ALL ANNULI,AND THROUGH INNER ANNULI
@@ -810,9 +810,9 @@ def _sum_rom(self, n_scat, n_abs, a, r1, r2, ms, theta, amu_scat, amu_tot_i, amu
810810
skip = False
811811

812812
if skip:
813-
I = number_omega - I + 2
813+
i = number_omega - i + 2
814814
else:
815-
I += 1
815+
i += 1
816816
AAA += sum_1 * Area_y
817817
BBB += sum_2 * Area_y
818818
Area += Area_sum * Area_y

Framework/PythonInterface/plugins/algorithms/DeltaPDF3D.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# NScD Oak Ridge National Laboratory, European Spallation Source,
55
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
66
# SPDX - License - Identifier: GPL - 3.0 +
7+
# ruff: noqa: E741 # Ambiguous variable name
78
from mantid.api import PythonAlgorithm, AlgorithmFactory, IMDHistoWorkspaceProperty, PropertyMode, WorkspaceProperty, Progress
89
from mantid.kernel import (
910
Direction,

Framework/PythonInterface/plugins/algorithms/GSASIIRefineFitPeaks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# NScD Oak Ridge National Laboratory, European Spallation Source,
55
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
66
# SPDX - License - Identifier: GPL - 3.0 +
7+
# ruff: noqa: E741 # Ambiguous variable name
78
from contextlib import contextmanager
89
import numpy
910
import os

Framework/PythonInterface/plugins/algorithms/GenerateGroupingSNSInelastic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ def PyExec(self):
117117
groupname = str(groupnum)
118118
ids = spectra[i, j : j + pixelsx, k : k + pixelsy].reshape(-1)
119119
detids = []
120-
for l in ids:
121-
detids.append(__w.getDetector(int(l)).getID())
120+
for id in ids:
121+
detids.append(__w.getDetector(int(id)).getID())
122122

123123
detids = str(detids).replace("[", "").replace("]", "")
124124

Framework/PythonInterface/plugins/algorithms/LRReflectivityOutput.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ def _get_value(name, default=None):
285285
if len(meta_data.strip()) > 0:
286286
content += "#\n"
287287
lines = meta_data.strip().split("\n")
288-
for l in lines:
289-
content += "# %s\n" % l
288+
for line in lines:
289+
content += f"# {line}\n"
290290
content += "#\n"
291291
except:
292292
logger.error("Could not write meta-data to reflectivity file.")

Framework/PythonInterface/plugins/algorithms/LinkedUBs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# NScD Oak Ridge National Laboratory, European Spallation Source,
55
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
66
# SPDX - License - Identifier: GPL - 3.0 +
7+
# ruff: noqa: E741 # Ambiguous variable name
78
from mantid.api import DataProcessorAlgorithm, mtd, AlgorithmFactory, WorkspaceProperty, PropertyMode, ITableWorkspaceProperty
89
from mantid.simpleapi import CalculateUMatrix, PredictPeaks, FilterPeaks, DeleteWorkspace, CreatePeaksWorkspace
910
from mantid.kernel import Direction, FloatBoundedValidator, IntBoundedValidator, StringMandatoryValidator, StringListValidator, V3D

0 commit comments

Comments
 (0)