Skip to content
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

[ENH]: dashed hatching pattern #27170

Open
pawjast opened this issue Oct 23, 2023 · 6 comments · May be fixed by #28072
Open

[ENH]: dashed hatching pattern #27170

pawjast opened this issue Oct 23, 2023 · 6 comments · May be fixed by #28072

Comments

@pawjast
Copy link

pawjast commented Oct 23, 2023

Problem

I've recently seen a plot with a dashed hatching style and was wondering if there's a case for adding such a style to matplotlib? Especially that we've got dotted hatching already available and this seems to be similar.

image

Source: https://twitter.com/DataVizStefan/status/1714930118781530248/photo/1

Proposed solution

I don't have the exact solution but matplotlib allows to create all sorts of fancy edge line styles so I'd imagine the technical ability of the library to implement this request is there.

https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html

@story645
Copy link
Member

this looks pretty and also reasonable, but also this is pushing more in the direction of custom hatch #20690

@pawjast
Copy link
Author

pawjast commented Oct 24, 2023

Yes, I can see it now. I didn't realize there's a similar request in the pipeline already.

@story645
Copy link
Member

Both? I think this in particular is clear enough that it could be an out of the box style, but I have no idea what the unambiguous short notation would be since -- is a more dense horizontal line.

@pawjast
Copy link
Author

pawjast commented Oct 24, 2023

How about "- " (dash/minus sign with a space)?
Or "_" (underscore)?

@story645
Copy link
Member

story645 commented Oct 24, 2023

How about "- " (dash/minus sign with a space)?

it won't work with our current parsing scheme, which allows infinite repetition of any character in the set '-+|/\xXoO.*'

def _validate_hatch_pattern(hatch):
valid_hatch_patterns = set(r'-+|/\xXoO.*')
if hatch is not None:
invalids = set(hatch).difference(valid_hatch_patterns)
if invalids:
valid = ''.join(sorted(valid_hatch_patterns))
invalids = ''.join(sorted(invalids))

but now I'm thinking this would also be nice in vertical and diagonal and thinking that "DashedHatch" might be a good place to prototype a custom hatch object since it's scoped pretty clean? Using any of the classes specified in https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/hatch.py#L14 as a model?

@ksunden
Copy link
Member

ksunden commented Oct 24, 2023

Any two character sequence is tough, and any sequence that includes an extant character is even tougher, as hatch patterns use repetitions to increase density, and do so irrespective of their ordering, etc. (They just do pattern.count("-")) Retaining desired behavior while allowing for multichar sequences is likely to cause confusion.

I think _ could work, could also argue for =, though I think that would imply a slightly different mark.

I do think that some of the finer points of the example above may be challenging without a more extensive refactor of hatching (which isn't to say not its not worthwhile, but is to say it may be a larger task than originally expected)

  • The fact that the first dash in a line looks to be following the contour of the region rather than being on a fixed grid
    • Lines in the lower section are stacked on top of one another, while lines in the upper section are staggered, but not by any particular pattern.
  • That density seems to equate to shorter lines is a bit of a wrinkle (though I think this could be done in current frameworks)

I agree that the example looks nice and if we could capture that it would be good, I just expect that what we would implement now would be potentially more rigid looking:

e.g. here is what I got by just hacking the dash pattern in the svg backend (not threading it through anywhere, etc, just was trying to get an idea, was using the branch from #27158 as my starting point because the example there is analogous to the example here in a way):

test

Note how all the dashes/gaps are aligned vertically.. I suspect that many of the "easy" ways to implement this idea will have that in common. I'm less concerned with the fact that this example does not scale the lines/gaps inversely to density, I think that is relatively easy to do .

@rcomer rcomer linked a pull request May 12, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants