8000 [Bug]: gapcolor not supported for LineCollections · Issue #24796 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[Bug]: gapcolor not supported for LineCollections #24796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
story645 opened this issue Dec 21, 2022 · 1 comment · Fixed by #24849
Closed

[Bug]: gapcolor not supported for LineCollections #24796

story645 opened this issue Dec 21, 2022 · 1 comment · Fixed by #24849
Labels
Milestone

Comments

@story645
Copy link
Member
story645 commented Dec 21, 2022

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

image

Additional information

I think the easiest fix is probably add set_color and get_color to LineCollection, modeled on get_color and set_color

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

@story645 story645 added topic: color/color & colormaps topic: collections and mappables Good first issue Open a pull request against these issues if there are no active ones! labels Dec 21, 2022
@rcomer
Copy link
Member
rcomer commented Dec 23, 2022

I had a look at this. Although the LineCollection docstring states that it “Represents a sequence of Line2Ds”, it doesn’t seem to use the Line2D object (unless I’m missing something).

So I think we might need to modify the Collection.draw method in an analogous way to how we did the Line2D.draw method at #23208. Though Collection.draw is more complicated as it’s obviously supporting a much wider range of cases.

Another possibility might be to modify LineCollection itself so that, if gapgolor is set, we add the inverse paths into LineCollection._paths (and update._edgecolors, ._linestyles with gapcolors and inverse linestyles). This would mean that what you get out of e.g. .get_colors would 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.

@rcomer rcomer added the Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues label Dec 23, 2022
@rcomer rcomer mentioned this issue Dec 31, 2022
5 tasks
@story645 story645 removed the Good first issue Open a pull request against these issues if there are no active ones! label Jan 1, 2023
@QuLogic QuLogic added this to the v3.8.0 milestone Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0