10000 Restore but deprecate positional args in LineCollection · matplotlib/matplotlib@8c3ab54 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c3ab54

Browse files
committed
Restore but deprecate positional args in LineCollection
1 parent 4b147a9 commit 8c3ab54

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
@@ -593,10 +593,7 @@ def get_offset_position(self):
593593

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

601598
def set_linewidth(self, lw):
602599
"""
@@ -1420,6 +1417,7 @@ class LineCollection(Collection):
14201417
_edge_default = True
14211418

14221419
def __init__(self, segments, # Can be None.
1420+
*args, # Deprecated.
14231421
zorder=2, # Collection.zorder is 1
14241422
**kwargs
14251423
):
@@ -1454,7 +1452,17 @@ def __init__(self, segments, # Can be None.
14541452
**kwargs
14551453
Forwarded to `.Collection`.
14561454
"""
1457-
1455+
argnames = ["linewidths", "colors", "antialiaseds", "linestyles",
1456+
"offsets", "transOffset", "norm", "cmap", "pickradius",
1457+
"zorder", "facecolors"]
1458+
if args:
1459+
argkw = {name: val for name, val in zip(argnames, args)}
1460+
kwargs.update(argkw)
1461+
cbook.warn_deprecated(
1462+
"3.4", message="In a future release, all LineCollection "
1463+
"arguments other than the first, 'segments', will be "
1464+
"keyword-only arguments."
1465+
)
14581466
super().__init__(
14591467
zorder=zorder,
14601468
**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():
@@ -791,6 +792,15 @@ def test_color_logic(pcfunc):
791792
assert_array_equal(pc.get_edgecolor(), [[1, 0, 0, 1]])
792793

793794

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

0 commit comments

Comments
 (0)
0