-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Examples not shown in API docs for many methods. #10974
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
Comments
The part of the sphinx docs that describe this feature are here: The part that configures this is the Lines 115 to 129 in d54e2e3
There is an automated generation, as described in the next chapter, Still trying to understand it. |
Right, and the "*.example" files are being generated, but they aren't being populated. Possibly (probably) because most examples don't |
Right. If you look at the examples, those functions which are correctly linked from the examples to the docs are orange in the code and can be clicked, Hence plt.contourf will have a gallery below it, while Axes.contour doesn't, because those methods are not recognized, |
Oh great, so Not sure what to do about it, except see if sphinx could add a check for a convention like |
And then.. what about On the other hand it is probably good not to have every single function linked, e.g. |
So I guess for most methods this should just be done manually... |
Maybe one can turn this around? Somehow tag the gallery examples with the API functions they are prominently using. Then backref the examples from the api functions. Essentially like gallery does it, except that the connections are not automatically created but are defined by us. Probably one would have to hack into the pyplot functions and related Axes methods should have the same set of examples. |
That's in principle a good idea. Now it seems that sphinx-gallery simply renders everything in those files as comments are just converted to text. So it might be hard to actually do this kind of tagging. On the other hand this brings me to the idea, could it be possible to just mention the base function somewhere? This should trigger the linking. For example, suppose at the bottom of the example, there is a code sample like
Would this be enough for it be included in both galleries? |
The comments in those files are just rest text so can include all the rst directives we like. But there is no machinery right now to do the reference in this direction that I know of. Seems like a great feature request for Sphinx-gallery. |
As discussed above, a global setting would not work. However, if one could configure this within the example, that would be great and even add links to the code. Seems like an alternative great feature request for Sphinx-gallery. 😄 |
I tried the above suggestion in this PR. It would look like this, see here for live preview: This will ensure that the documentation is properly linked and indeed if you then go to the axes.Axes.imshow documentation you see there being the linked example at the bottom. One drawback: It does not seem to work with functions which do not have their own doc page. In this case, although |
👍 👍 on this as a great way to go. Now we just have to populate a critical mass of examples... At the very least we can ask new PRs to do this. As an aside, I think there should be a |
The only disadvantage to that method is we need to have |
This is a good workaround for now. In the long run, I'd still want a sphinx-gallery feature to be able to define linking of arbitrary code pattens to documentation (and reverse). |
This is not so much about sphinx-gallery. I don't think it can do anything here. What one might expect from sphinx-gallery is the option to hide this attached Reference section but still use it somehow. Even if possible, this would however still involve a manual procedure of adding the functions/methods/classes to each example individually. In order to produce an automatic linkage, one would need to look at |
It this solution also supplies links to the API doc in the example. I wouldn’t want to hide the References. |
@ImportanceOfBeingErnest IMHO this is exactly about sphinx. I would want something like:
This should link Of course, this is manual since in general you cannot know what type a variable is unless you run the code. Still, it would allow linking of methods in the same way that's already available for functions. |
Correct. To me it looks like this linkage is done by |
As also discussed in #11019 and #10148, the idea is now to create a reference section below examples to include the modules, functions, methods and classes that can serve as backreferences. Here is a table of the current status.
[*] Might not be needed, as mplot3d section has examples inside the docs Please feel invited to contribute. (Maybe this can also the new-contributor-friendly label?) |
It seems sphinx-gallery has a PR in for this. Not merged yet, as far as I can see: |
As far as I can see, that PR would allow to put a reference like :meth: This is somehow the same as mentionning the actual method explicitely as code, like it's beeing done in the work here. So instead of
You would then be able to write
which is somehow the same manual work that needs to be done. I did btw. not continue to spend much effort into this because @anntzer mentionned at some point that he might have a better idea to do some automatic parsing. Not sure what the status of that is. |
Agreed that the manual work is the same, but I think its less strange to have this list than a code block. And flake8 doesn't like having the import at the bottom of the page. |
Better parsing is coming, but I'm also starting a new job so that project is a bit on the back burner for now... (sorry, didn't keep the schedule :) probably won't have the time to work seriously on it before this fall) |
I think we can close this as being acted on... |
Bug report
As discussed w @ImportanceOfBeingErnest #10148
All API sources seem to have
.. include:: matplotlib.patches.Wedge.examples
including many that don't have any examples shown (i.e. https://matplotlib.org/_sources/api/_as_gen/matplotlib.axes.Axes.plot.rst.txt)These allow examples that are in the gallery to be linked to the API so users can easily see how to use the method (i.e. https://matplotlib.org/api/_as_gen/matplotlib.patches.Wedge.html#examples-using-matplotlib-patches-wedge)
Not sure how
matplotlib.patches.Wedge.examples
gets generated. There is one generated formatplotlib.axes.Axes.plot.examples
but it is empty. I somewhat suspect the issue is the extra level of nesting. Either we should find the config option or open an issue at Sphinx Gallery to get the extra level traversed?The text was updated successfully, but these errors were encountered: