Skip to content

Document how to write a References section in examples #19232

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
timhoffm opened this issue Jan 4, 2021 · 4 comments · Fixed by #19774
Closed

Document how to write a References section in examples #19232

timhoffm opened this issue Jan 4, 2021 · 4 comments · Fixed by #19774
Assignees

Comments

@timhoffm
Copy link
Member

timhoffm commented Jan 4, 2021

This should go into https://matplotlib.org/devdocs/devel/documenting_mpl.html#writing-examples-and-tutorials

Also:

@ianhi
Copy link
Contributor

ianhi commented Jan 4, 2021

Consider adding the possibility for linking between examples. Is this technically only a ".. seealso::" directive?

I think ideally there would be a minigallery defined by the example. Though im not sure sphinx-gallery supports that.

@rajpratyush
Copy link
Contributor

@timhoffm does this issue needs work?

@timhoffm
Copy link
Member Author

Yes it does.

There are multiple things to do here:

The trivial thing would be to just write down what we're currently doing. See, e.g. https://matplotlib.org/devdocs/gallery/lines_bars_and_markers/fill.html#references.

However this is more like a hack with several drawbacks, which is why I'm a bit hesitant to document it as the recommended solution

  • You need to put import matplotlib in
  • You get the Out[] line.
  • You have to mention pyplot as well as Axes to get references in both docs.

Also, I had the impression that this way of writing code and let sphinx gallery discover it does not always work, but I cannot point at an example right now.

The good solution would be to write a sphinx directive

.. gallery-reference::
   matplotlib.axes.Axes.fill
   matplotlib.pyplot.fill
   matplotlib.axes.Axes.axis
   matplotlib.pyplot.axis

That'd possibly be need to be done upstream in sphinx-gallery.

@timhoffm
Copy link
Member Author

Proposal: Switch to

###############################################################################
#
# .. admonition:: References
#
#    The use of the following functions, methods, classes and modules is shown
#    in this example:
#
#    - `matplotlib.axes.Axes.fill` / `matplotlib.pyplot.fill`
#    - `matplotlib.axes.Axes.axis` / `matplotlib.pyplot.axis`

Which results in

grafik

This works without defining any new directives.

For comparison: Current look

grafik

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