Skip to content

Commit 10d30a7

Browse files
authored
fix: fix based on review
1 parent 47e4a69 commit 10d30a7

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

galleries/examples/lines_bars_and_markers/multicolored_line.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from matplotlib.collections import LineCollection
2222

2323

24-
def colored_line(x, y, c, ax=None, scalex=True, scaley=True, **lc_kwargs):
24+
def colored_line(x, y, c, ax=None, **lc_kwargs):
2525
"""
2626
Plot a line with a color specified along the line by a third value.
2727
@@ -38,10 +38,7 @@ def colored_line(x, y, c, ax=None, scalex=True, scaley=True, **lc_kwargs):
3838
The color values, which should be the same size as x and y.
3939
ax : matplotlib.axes.Axes, optional
4040
The axes to plot on. If not provided, the current axes will be used.
41-
scalex, scaley : bool
42-
These parameters determine if the view limits are adapted to the data limits.
43-
The values are passed on to autoscale_view.
44-
**lc_kwargs : Any
41+
**lc_kwargs
4542
Any additional arguments to pass to matplotlib.collections.LineCollection
4643
constructor. This should not include the array keyword argument because
4744
that is set to the color argument. If provided, it will be overridden.
@@ -63,13 +60,11 @@ def colored_line(x, y, c, ax=None, scalex=True, scaley=True, **lc_kwargs):
6360
(xy[0, :][None, :], (xy[:-1, :] + xy[1:, :]) / 2, xy[-1, :][None, :]), axis=0
6461
)
6562
segments = np.stack((xy_mid[:-1, :], xy, xy_mid[1:, :]), axis=-2)
66-
# Note that segments is [
67-
# [[x[0], y[0]], [x[0], y[0]], [mean(x[0], x[1]), mean(y[0], y[1])]],
68-
# [[mean(x[0], x[1]), mean(y[0], y[1])], [x[1], y[1]],
69-
# [mean(x[1], x[2]), mean(y[1], y[2])]],
70-
# ...
71-
# [[mean(x[-2], x[-1]), mean(y[-2], y[-1])], [x[-1], y[-1]], [x[-1], y[-1]]]
72-
# ]
63+
# Note that
64+
# segments[0, :, :] is [xy[0, :], xy[0, :], (xy[0, :] + xy[1, :]) / 2]
65+
# segments[i, :, :] is [(xy[i - 1, :] + xy[i, :]) / 2, xy[i, :],
66+
# (xy[i, :] + xy[i + 1, :]) / 2] if i not in {0, len(x) - 1}
67+
# segments[-1, :, :] is [(xy[-2, :] + xy[-1, :]) / 2, xy[-1, :], xy[-1, :]]
7368

7469
lc_kwargs["array"] = c
7570
lc = LineCollection(segments, **lc_kwargs)
@@ -79,7 +74,6 @@ def colored_line(x, y, c, ax=None, scalex=True, scaley=True, **lc_kwargs):
7974
ax.add_collection(lc)
8075
ax.autoscale_view(scalex=scalex, scaley=scaley)
8176

82-
# Return the LineCollection object
8377
return lc
8478

8579

0 commit comments

Comments
 (0)