Repository navigation
Closed
Labels
API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …Consistency of the matplotlib API, including naming, behavior, defaults, …Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuestopic: collections and mappablestopic: color/color & colormaps
Milestone
Description
Bug summary
LineCollection doesn't have a get_gapcolor or set_gapcolor, so gapcolor doesn't work in plotting methods that return LineCollections (like vlines or hlines).
Code for reproduction
fig, ax = plt.subplots(figsize=(1,1))
ax.vlines([.25, .75], 0, 1, linestyle=':', gapcolor='orange')Actual outcome
File ~\miniconda3\envs\prop\lib\site-packages\matplotlib\artist.py:1186, in Artist._internal_update(self, kwargs)
-> 1186 return self._update_props(
1187 kwargs, "{cls.__name__}.set() got an unexpected keyword argument "
1188 "{prop_name!r}")
AttributeError: LineCollection.set() got an unexpected keyword argument 'gapcolor'Expected outcome
Additional information
I think the easiest fix is probably add set_color and get_color to LineCollection, modeled on get_color and set_color
matplotlib/lib/matplotlib/collections.py
Lines 1463 to 1481 in 5093150
| def set_color(self, c): | |
| """ | |
| Set the edgecolor(s) of the LineCollection. | |
| Parameters | |
| ---------- | |
| c : color or list of colors | |
| Single color (all lines have same color), or a | |
| sequence of RGBA tuples; if it is a sequence the lines will | |
| cycle through the sequence. | |
| """ | |
| self.set_edgecolor(c) | |
| set_colors = set_color | |
| def get_color(self): | |
| return self._edgecolors | |
| get_colors = get_color # for compatibility with old versions |
Matplotlib Version
3.7.0.dev1121+g509315008c
Reacted by Ruth Comer
Metadata
Metadata
Assignees
Labels
API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …Consistency of the matplotlib API, including naming, behavior, defaults, …Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuestopic: collections and mappablestopic: color/color & colormaps

Activity
rcomer commentedon Dec 23, 2022
I had a look at this. Although the
LineCollectiondocstring states that it “Represents a sequence of Line2Ds”, it doesn’t seem to use theLine2Dobject (unless I’m missing something).So I think we might need to modify the
Collection.drawmethod in an analogous way to how we did theLine2D.drawmethod at #23208. ThoughCollection.drawis more complicated as it’s obviously supporting a much wider range of cases.Another possibility might be to modify
LineCollectionitself so that, if gapgolor is set, we add the inverse paths intoLineCollection._paths(and update._edgecolors,._linestyleswith gapcolors and inverse linestyles). This would mean that what you get out of e.g..get_colorswould be longer than what was put into.set_colors, which might not be desirable.Anyway, for now I just mark this as “medium difficulty”, as I do not think it is a task for a beginner.