8000 Restore but deprecate positional args in LineCollection · matplotlib/matplotlib@34faf5d · GitHub
[go: up one dir, main page]

Skip to content

Commit 34faf5d

Browse files
committed
Restore but deprecate positional args in LineCollection
1 parent 88c6ccb commit 34faf5d

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/matplotlib/collections.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,7 @@ def get_offset_position(self):
592592

593593
def _get_default_linewidth(self):
594594
# This may be overridden in a subclass.
595-
lw = mpl.rcParams['patch.linewidth']
596-
if lw is None:
597-
lw = mpl.rcParams['lines.linewidth']
598-
return lw
595+
return mpl.rcParams['patch.linewidth'] # validated as float
599596

600597
def set_linewidth(self, lw):
601598
"""
@@ -1419,6 +1416,7 @@ class LineCollection(Collection):
14191416
_edge_default = True
14201417

14211418
def __init__(self, segments, # Can be None.
1419+
*args, # Deprecated.
14221420
zorder=2, # Collection.zorder is 1
14231421
**kwargs
14241422
):
@@ -1453,7 +1451,17 @@ def __init__(self, segments, # Can be None.
14531451
**kwargs
14541452
Forwarded to `.Collection`.
14551453
"""
1456-
1454+
argnames = ["linewidths", "colors", "antialiaseds", "linestyles",
1455+
"offsets", "transOffset", "norm", "cmap", "pickradius",
1456+
"zorder", "facecolors"]
1457+
if args:
1458+
argkw = {name: val for name, val in zip(argnames, args)}
1459+
kwargs.update(argkw)
1460+
cbook.warn_deprecated(
1461+
"3.4", message="In a future release, all LineCollection "
1462+
"arguments other than the first, 'segments', will be "
1463+
"keyword-only arguments."
1464+
)
14571465
super().__init__(
14581466
zorder=zorder,
14591467
**kwargs)

lib/matplotlib/tests/test_collections.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from matplotlib.collections import (Collection, LineCollection,
1313
EventCollection, PolyCollection)
1414
from matplotlib.testing.decorators import image_comparison
15+
from matplotlib.cbook.deprecation import MatplotlibDeprecationWarning
1516

1617

1718
def generate_EventCollection_plot():
@@ -789,6 +790,15 @@ def test_color_logic(pcfunc):
789790
assert_array_equal(pc.get_edgecolor(), [[1, 0, 0, 1]])
790791

791792

793+
def test_LineCollection_args():
794+
with pytest.warns(MatplotlibDeprecationWarning):
795+
lc = LineCollection(None, 2.2, 'r', zorder=3, facecolors=[0, 1, 0, 1])
796+
assert lc.get_linewidth()[0] == 2.2
797+
assert list(lc.get_edgecolor()[0]) == [1, 0, 0, 1]
798+
assert lc.get_zorder() == 3
799+
assert list(lc.get_facecolor()[0]) == [0, 1, 0, 1]
800+
801+
792802
def test_array_wrong_dimensions():
793803
z = np.arange(12).reshape(3, 4)
794804
pc = plt.pcolor(z)

0 commit comments

Comments
 (0)
0