Skip to content

Commit 7668535

Browse files
committed
enhanced tests and made hatchcolors param required in _iter_collection()
1 parent e3b03fc commit 7668535

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def _iter_collection_uses_per_path(self, paths, all_transforms,
345345

346346
def _iter_collection(self, gc, path_ids, offsets, offset_trans, facecolors,
347347
edgecolors, linewidths, linestyles,
348-
antialiaseds, urls, offset_position, hatchcolors=None):
348+
antialiaseds, urls, offset_position, hatchcolors):
349349
"""
350350
Helper method (along with `_iter_collection_raw_paths`) to implement
351351
`draw_path_collection` in a memory-efficient manner.
@@ -368,9 +368,6 @@ def _iter_collection(self, gc, path_ids, offsets, offset_trans, facecolors,
368368
*path_ids*; *gc* is a graphics context and *rgbFace* is a color to
369369
use for filling the path.
370370
"""
371-
if hatchcolors is None:
372-
hatchcolors = []
373-
374371
Npaths = len(path_ids)
375372
Noffsets = len(offsets)
376373
N = max(Npaths, Noffsets)

lib/matplotlib/tests/test_backend_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def check(master_transform, paths, all_transforms,
3838
gc, range(len(raw_paths)), offsets,
3939
transforms.AffineDeltaTransform(master_transform),
4040
facecolors, edgecolors, [], [], [False],
41-
[], 'screen')]
41+
[], 'screen', [])]
4242
uses = rb._iter_collection_uses_per_path(
4343
paths, all_transforms, offsets, facecolors, edgecolors)
4444
if raw_paths:

lib/matplotlib/tests/test_collections.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,63 +1390,63 @@ def test_collection_hatchcolor_inherit_logic():
13901390
from matplotlib.collections import PathCollection
13911391
path = mpath.Path.unit_rectangle()
13921392

1393-
colors_1 = ['purple', 'red', 'green', 'yellow']
1394-
colors_2 = ['orange', 'cyan', 'blue', 'magenta']
1393+
edgecolors = ['purple', 'red', 'green', 'yellow']
1394+
hatchcolors = ['orange', 'cyan', 'blue', 'magenta']
13951395
with mpl.rc_context({'hatch.color': 'edge'}):
13961396
# edgecolor and hatchcolor is set
13971397
col = PathCollection([path], hatch='//',
1398-
edgecolor=colors_1, hatchcolor=colors_2)
1399-
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(colors_2))
1398+
edgecolor=edgecolors, hatchcolor=hatchcolors)
1399+
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(hatchcolors))
14001400

14011401
# explicitly setting edgecolor and then hatchcolor
14021402
col = PathCollection([path], hatch='//')
1403-
col.set_edgecolor(colors_1)
1404-
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(colors_1))
1405-
col.set_hatchcolor(colors_2)
1406-
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(colors_2))
1403+
col.set_edgecolor(edgecolors)
1404+
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(edgecolors))
1405+
col.set_hatchcolor(hatchcolors)
1406+
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(hatchcolors))
14071407

14081408
# explicitly setting hatchcolor and then edgecolor
14091409
col = PathCollection([path], hatch='//')
1410-
col.set_hatchcolor(colors_1)
1411-
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(colors_1))
1412-
col.set_edgecolor(colors_2)
1413-
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(colors_1))
1410+
col.set_hatchcolor(hatchcolors)
1411+
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(hatchcolors))
1412+
col.set_edgecolor(edgecolors)
1413+
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(hatchcolors))
14141414

14151415

14161416
def test_collection_hatchcolor_fallback_logic():
14171417
from matplotlib.collections import PathCollection
14181418
path = mpath.Path.unit_rectangle()
14191419

1420-
colors_1 = ['purple', 'red', 'green', 'yellow']
1421-
colors_2 = ['orange', 'cyan', 'blue', 'magenta']
1420+
edgecolors = ['purple', 'red', 'green', 'yellow']
1421+
hatchcolors = ['orange', 'cyan', 'blue', 'magenta']
14221422

14231423
# hatchcolor parameter should take precedence over rcParam
14241424
# When edgecolor is not set
14251425
with mpl.rc_context({'hatch.color': 'green'}):
1426-
col = PathCollection([path], hatch='//', hatchcolor=colors_1)
1427-
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(colors_1))
1426+
col = PathCollection([path], hatch='//', hatchcolor=hatchcolors)
1427+
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(hatchcolors))
14281428
# When edgecolor is set
14291429
with mpl.rc_context({'hatch.color': 'green'}):
14301430
col = PathCollection([path], hatch='//',
1431-
edgecolor=colors_2, hatchcolor=colors_1)
1432-
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(colors_1))
1431+
edgecolor=edgecolors, hatchcolor=hatchcolors)
1432+
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(hatchcolors))
14331433

14341434
# hatchcolor should not be overridden by edgecolor when
14351435
# hatchcolor parameter is not passed and hatch.color rcParam is set to a color
14361436
with mpl.rc_context({'hatch.color': 'green'}):
14371437
col = PathCollection([path], hatch='//')
14381438
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array('green'))
1439-
col.set_edgecolor(colors_1)
1439+
col.set_edgecolor(edgecolors)
14401440
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array('green'))
14411441

14421442
# hatchcolor should match edgecolor when
14431443
# hatchcolor parameter is not passed and hatch.color rcParam is set to 'edge'
14441444
with mpl.rc_context({'hatch.color': 'edge'}):
1445-
col = PathCollection([path], hatch='//', edgecolor=colors_1)
1446-
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(colors_1))
1445+
col = PathCollection([path], hatch='//', edgecolor=edgecolors)
1446+
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(edgecolors))
14471447
# hatchcolor parameter is set to 'edge'
1448-
col = PathCollection([path], hatch='//', edgecolor=colors_1, hatchcolor='edge')
1449-
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(colors_1))
1448+
col = PathCollection([path], hatch='//', edgecolor=edgecolors, hatchcolor='edge')
1449+
assert_array_equal(col.get_hatchcolor(), mpl.colors.to_rgba_array(edgecolors))
14501450

14511451
# default hatchcolor should be used when hatchcolor parameter is not passed and
14521452
# hatch.color rcParam is set to 'edge' and edgecolor is not set

0 commit comments

Comments
 (0)