Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Doc] Added images of hatches to hatch API page#29644

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
story645 merged 1 commit intomatplotlib:mainfromstory645:hatches_api
Mar 4, 2025

Conversation

story645
Copy link
Member

@story645story645 commentedFeb 18, 2025
edited
Loading

PR summary

Adds an image of the hatches to the hatch docs.closes#27196

  • 1st commit cleans up/implements requested changes from[Doc] Updated Hatches API page #27370
  • 2nd commit adds a hatch mpl_type that points to the API page (down the line, this should probably be its own page like colors)

PR checklist

@story645story645 mentioned this pull requestFeb 18, 2025
2 tasks
@story645story645 changed the title[Doc] Updated Hatches API page[Doc] Added images of hatches to hatch API pageFeb 18, 2025
@timhoffm
Copy link
Member

timhoffm commentedFeb 18, 2025
edited
Loading

I believe the mpl_type link should point to thehatch style reference.

Amending the matplotlib.hatch API page is okish. I'd like to point out though that the hatch classes defined there cannot be used by the user. AFAICS the only public API to create hatches is through hatch patterns. In that sensematplotlib.hatch is an implementation detail, and we could even make it private. IMHO documentation on the API page should rather connect the visual to the classes, e.g.

grafik

import matplotlib.pyplot as pltfrom matplotlib.patches import Rectanglefig, ax = plt.subplots()pattern_to_class = {    '/': 'NorthEastHatch',    '\\': 'SouthEastHatch',    '|': 'VerticalHatch',    '-': 'HorizontalHatch',    '+': 'VerticalHatch + HorizontalHatch',    'x': 'NorthEastHatch + SouthEastHatch',    'o': 'SmallCircles',    'O': 'LargeCircles',    '.': 'SmallFilledCircles',    '*': 'Stars',}for i, (hatch, classes) in enumerate(pattern_to_class.items()):    ax.add_patch(Rectangle((0.1, i+0.5), 0.8, 0.8, fill=False, hatch=hatch*2))    ax.text(1.3, i+0.9, f"'{hatch}'", family='monospace', va='center')    ax.text(2, i+0.9, pattern_to_class[hatch], family='monospace', va='center', color='tab:blue')ax.set(xlim=(0, 5), ylim=(0, i+1.5), yinverted=True)ax.set_axis_off()
story645 reacted with thumbs up emoji

@story645
Copy link
MemberAuthor

So like your table, gonna adopt that.

In that sense matplotlib.hatch is an implementation detail, and we could even make it private.

I think the reason not to is for helper classes for custom hatches#20690

timhoffm reacted with thumbs up emoji

@timhoffm
Copy link
Member

FYI: I've added a minor position tweak to the above code.

story645 reacted with thumbs up emoji

@story645
Copy link
MemberAuthor

story645 commentedFeb 18, 2025
edited
Loading

Um, I just used annotate

fori, (hatch,classes)inenumerate(pattern_to_class.items()):r=Rectangle((0.1,i+0.5),0.8,0.8,fill=False,hatch=hatch*2)ax.add_patch(r)h=ax.annotate(f"'{hatch}'",xy=(1.2,.5),xycoords=r,family='monospace',va='center',ha='left')ax.annotate(pattern_to_class[hatch],xy=(1.5,.5),xycoords=h,family='monospace',va='center',ha='left',color='tab:blue')ax.set(xlim=(0,5),ylim=(0,i+1.5),yinverted=True)ax.set_axis_off()

image

@story645
Copy link
MemberAuthor

Ok, I have a it's possibly documented somewhere question, but does the plot directive not work in the API docs? I pushed changes in the latest commit just in case I'm doing something silly.

@github-actionsgithub-actionsbot added the Documentation: examplesfiles in galleries/examples labelFeb 19, 2025
@timhoffm
Copy link
Member

Interesting. I don't think we have the plot directive in any other module docstring, but we have it in method docstrings and there it works, e.g.https://output.circle-artifacts.com/output/job/4778f46c-549d-46ab-8d66-29dd2131e7e8/artifacts/0/doc/build/html/api/_as_gen/matplotlib.axes.Axes.margins.html#matplotlib.axes.Axes.margins.

Just as a note Sphinx 8.2 was released yesterday. It could be that there is a regression, but again, the method docstring works (I've intentionally picked your doc build here in the link above.

@story645
Copy link
MemberAuthor

So the answer is I was doing something silly - plot_formats is a config variable and not an option parameter 🤦‍♀️

@timhoffm
Copy link
Member

And that doesn't lead to an error or at least warning? AFAIR Sphinx built clearly.

@story645
Copy link
MemberAuthor

And that doesn't lead to an error or at least warning? AFAIR Sphinx built clearly.

Nope 😭


.. plot:: _embedded_plots/hatch_classes.py
:include-source: false
:alt: 8 squares, each showing the pattern corresponding to the hatch symbol: symbol '/' makes right leaning diagonals, '\\' makes left leaning diagonals, '|' makes vertical lines, '-' makes horizontal lines, '+' makes a grid, 'X' makes a grid rotated 90 degrees, 'o' makes small unfilled circles, 'O' makes large unfilled circles, '.' makes small filled circles, and '*' makes a start with 5 points
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Linting won't pass cause of the alt text but alt txt can't span multiple lines so the fix for this is probably the sdg that lets me stash this in the file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Are you sure? Docutils defines directive options asfield lists and there they write

:Indentation: Since the field marker may be quite long, the second   and subsequent lines of the field body do not have to line up   with the first line, but they must be indented relative to the   field name marker, and they must line up with each other.

I'd, assume this should be automatically handled by the docutils parser. If not we may check whether we can modify our plot directive.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I've tried every variant of indentation I could think of. Now I'm wondering if it's maybe getting regestered as code (it gets formatted weird, so let me try putting the alt text before other options

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That also didn't work :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We don't have any multiline plot-alt option. Though there is one figure-alt at

..figure::/_static/FigureNotebook.png
:alt:Image of figure generated in Jupyter Notebook with notebook
backend, including a toolbar.
:width:400

You could try to break lines on existing plot directives in docstrings and rst and see how that goes.

Or just shorten the text to "A visualization of the 8 builtin hatch patterns", which is of course less helpful but IMHO not the end of the world. 🤷

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

At that point, I was thinking maybe put each hatch in its class docstring, but at that point I'm tilting into repr on hatchclasses which doesn't make sense unless we go the full registry route

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Content is good to go. You can self-merge after finding a way to deal with the line length.

Co-authored-by: Md Ashhar <mdashhar01@gmail.com>Co-authored-by: hannah <story645@gmail.com>Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>added a hatch mpl_type that links to the hatch reference docs
@story645story645 marked this pull request as ready for reviewMarch 4, 2025 04:09
@story645story645 merged commit52f659f intomatplotlib:mainMar 4, 2025
39 of 41 checks passed
@QuLogicQuLogic added this to thev3.11.0 milestoneMar 5, 2025
@story645story645 deleted the hatches_api branchMay 23, 2025 20:42
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

[Doc]: List supported hatches and link to/embed hatch reference on hatches API page
4 participants
@story645@timhoffm@QuLogic@pat8901

[8]ページ先頭

©2009-2025 Movatter.jp