Skip to content

Commit ea362ab

Browse files
authored
Merge pull request matplotlib#31561 from ayshih/colormap_init
2 parents dc0c572 + ec9a273 commit ea362ab

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

lib/matplotlib/colors.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,16 +1162,18 @@ def __init__(self, name, segmentdata, N=256, gamma=1.0, *,
11621162
self._gamma = gamma
11631163

11641164
def _init(self):
1165-
self._lut = np.ones((self.N + 3, 4), float)
1166-
self._lut[:-3, 0] = _create_lookup_table(
1165+
# Assemble the LUT first in a local variable in case of parallel threads
1166+
lut = np.ones((self.N + 3, 4), float)
1167+
lut[:-3, 0] = _create_lookup_table(
11671168
self.N, self._segmentdata['red'], self._gamma)
1168-
self._lut[:-3, 1] = _create_lookup_table(
1169+
lut[:-3, 1] = _create_lookup_table(
11691170
self.N, self._segmentdata['green'], self._gamma)
1170-
self._lut[:-3, 2] = _create_lookup_table(
1171+
lut[:-3, 2] = _create_lookup_table(
11711172
self.N, self._segmentdata['blue'], self._gamma)
11721173
if 'alpha' in self._segmentdata:
1173-
self._lut[:-3, 3] = _create_lookup_table(
1174+
lut[:-3, 3] = _create_lookup_table(
11741175
self.N, self._segmentdata['alpha'], 1)
1176+
self._lut = lut
11751177
self._isinit = True
11761178
self._update_lut_extremes()
11771179

@@ -1362,8 +1364,10 @@ def __init__(self, colors, name='unnamed', N=None, *,
13621364
super().__init__(name, N, bad=bad, under=under, over=over)
13631365

13641366
def _init(self):
1365-
self._lut = np.zeros((self.N + 3, 4), float)
1366-
self._lut[:-3] = to_rgba_array(self.colors)
1367+
# Assemble the LUT first in a local variable in case of parallel threads
1368+
lut = np.zeros((self.N + 3, 4), float)
1369+
lut[:-3] = to_rgba_array(self.colors)
1370+
self._lut = lut
13671371
self._isinit = True
13681372
self._update_lut_extremes()
13691373

0 commit comments

Comments
 (0)