Skip to content

Commit c9599a2

Browse files
committed
Clarify variable names.
1 parent ad16cb6 commit c9599a2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/matplotlib/backends/backend_pdf.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1557,12 +1557,13 @@ def _writeImg(self, data, id, smask=None):
15571557
(alpha channel) *smask*, which should be either None or a ``(height,
15581558
width, 1)`` array.
15591559
"""
1560-
height, width, colors = data.shape
1560+
height, width, color_channels = data.shape
15611561
obj = {'Type': Name('XObject'),
15621562
'Subtype': Name('Image'),
15631563
'Width': width,
15641564
'Height': height,
1565-
'ColorSpace': Name({1: 'DeviceGray', 3: 'DeviceRGB'}[colors]),
1565+
'ColorSpace': Name({1: 'DeviceGray',
1566+
3: 'DeviceRGB'}[color_channels]),
15661567
'BitsPerComponent': 8}
15671568
if smask:
15681569
obj['SMask'] = smask
@@ -1571,13 +1572,13 @@ def _writeImg(self, data, id, smask=None):
15711572
data = data.squeeze(axis=-1)
15721573
img = Image.fromarray(data)
15731574
img_colors = img.getcolors(maxcolors=256)
1574-
if colors == 3 and img_colors is not None:
1575+
if color_channels == 3 and img_colors is not None:
15751576
# Convert to indexed color if there are 256 colors or fewer
15761577
# This can significantly reduce the file size
15771578
num_colors = len(img_colors)
15781579
img = img.convert(mode='P', dither=Image.NONE,
15791580
palette=Image.ADAPTIVE, colors=num_colors)
1580-
data, bit_depth, palette = self._writePng(img)
1581+
png_data, bit_depth, palette = self._writePng(img)
15811582
if bit_depth is None or palette is None:
15821583
raise RuntimeError("invalid PNG header")
15831584
palette = palette[:num_colors * 3] # Trim padding
@@ -1586,10 +1587,10 @@ def _writeImg(self, data, id, smask=None):
15861587
+ str(num_colors - 1).encode()
15871588
+ b' ' + palette + b']')
15881589
obj['BitsPerComponent'] = bit_depth
1589-
colors = 1
1590+
color_channels = 1
15901591
else:
1591-
data, _, _ = self._writePng(img)
1592-
png = {'Predictor': 10, 'Colors': colors, 'Columns': width}
1592+
png_data, _, _ = self._writePng(img)
1593+
png = {'Predictor': 10, 'Colors': color_channels, 'Columns': width}
15931594
else:
15941595
png = None
15951596
self.beginStream(
@@ -1599,7 +1600,7 @@ def _writeImg(self, data, id, smask=None):
15991600
png=png
16001601
)
16011602
if png:
1602-
self.currentstream.write(data)
1603+
self.currentstream.write(png_data)
16031604
else:
16041605
self.currentstream.write(data.tobytes())
16051606
self.endStream()

0 commit comments

Comments
 (0)