-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I believe the mpl_type link should point to the hatch 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 sense
|
So like your table, gonna adopt that.
I think the reason not to is for helper classes for custom hatches #20690 |
FYI: I've added a minor position tweak to the above code. |
Um, I just used annotate for i, (hatch, classes) in enumerate(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() |
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. |
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. |
So the answer is I was doing something silly - plot_formats is a config variable and not an option parameter 🤦♀️ |
And that doesn't lead to an error or at least warning? AFAIR Sphinx built clearly. |
Nope 😭 |
3e9afc4
to
a83e368
Compare
lib/matplotlib/hatch.py
Outdated
|
||
.. 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 as field 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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :/
There was a problem hiding this comment.
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
matplotlib/galleries/users_explain/figure/figure_intro.rst
Lines 70 to 73 in 7ede092
.. 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. 🤷
There was a problem hiding this comment.
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
There was a problem hiding this 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.
a83e368
to
8aa8c61
Compare
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
PR summary
Adds an image of the hatches to the hatch docs. closes #27196
PR checklist