Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import copy
from dataclasses import dataclass

from numbers import Integral, Number, Real
import logging
Expand Down Expand Up @@ -227,7 +228,15 @@
raise ValueError(f"markevery={markevery!r} is not a recognized value")



@dataclass
class _LineStyle:
"""Container for Line2D style properties."""
linewidth: float = None
linestyle: str = None
color: object = None

@_docstring.interpd

Check warning on line 239 in lib/matplotlib/lines.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Expected 2 blank lines, found 1 Raw Output: message:"Expected 2 blank lines, found 1" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/lines.py" range:{start:{line:239 column:1} end:{line:239 column:2}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E302" url:"https://docs.astral.sh/ruff/rules/blank-lines-top-level"} suggestions:{range:{start:{line:238 column:1} end:{line:239 column:1}} text:"\n\n"}
@_api.define_aliases({
"antialiased": ["aa"],
"color": ["c"],
Expand Down Expand Up @@ -334,6 +343,7 @@

"""
super().__init__()
self._style = _LineStyle()

# Convert sequences to NumPy arrays.
if not np.iterable(xdata):
Expand Down Expand Up @@ -366,7 +376,7 @@

self._linestyles = None
self._drawstyle = None
self._linewidth = linewidth
self._style.linewidth = linewidth
self._unscaled_dash_pattern = (0, None) # offset, dash
self._dash_pattern = (0, None) # offset, dash (scaled by linewidth)

Expand Down Expand Up @@ -777,7 +787,7 @@
gc.set_url(self.get_url())

gc.set_antialiased(self._antialiased)
gc.set_linewidth(self._linewidth)
gc.set_linewidth(self._style.linewidth)

if self.is_dashed():
cap = self._dashcapstyle
Expand Down Expand Up @@ -931,7 +941,7 @@

See also `~.Line2D.set_linewidth`.
"""
return self._linewidth
return self._style.linewidth

def get_marker(self):
"""
Expand Down Expand Up @@ -1138,9 +1148,9 @@
Line width, in points.
"""
w = float(w)
if self._linewidth != w:
if self._style.linewidth != w:
self.stale = True
self._linewidth = w
self._style.linewidth = w
self._dash_pattern = _scale_dashes(*self._unscaled_dash_pattern, w)

def set_linestyle(self, ls):
Expand Down Expand Up @@ -1185,7 +1195,7 @@
self._linestyle = '--'
self._unscaled_dash_pattern = _get_dash_pattern(ls)
self._dash_pattern = _scale_dashes(
*self._unscaled_dash_pattern, self._linewidth)
*self._unscaled_dash_pattern, self._style.linewidth)
self.stale = True

@_docstring.interpd
Expand Down Expand Up @@ -1340,7 +1350,7 @@
"""Copy properties from *other* to self."""
super().update_from(other)
self._linestyle = other._linestyle
self._linewidth = other._linewidth
self._style.linewidth = other._linewidth
self._color = other._color
self._gapcolor = other._gapcolor
self._markersize = other._markersize
Expand Down
Loading