Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC: simplify API index #19727

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

Merged
merged 9 commits into from
Mar 24, 2021
Merged

DOC: simplify API index #19727

merged 9 commits into from
Mar 24, 2021

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Mar 17, 2021

PR Summary

This yields a much quicker ingress to the useful parts of the API page, and a quick example to orient the reader...

API

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@jklymak jklymak force-pushed the doc-api-frontpage branch from 2716870 to 0e26ab8 Compare March 17, 2021 21:59
@jklymak
Copy link
Member Author

jklymak commented Mar 18, 2021

@jklymak jklymak added this to the v3.5.0 milestone Mar 18, 2021
@timhoffm
Copy link
Member

We had API in the top menu until https://matplotlib.org/3.1.0/. I think it was removed intentionally, but don't remember the discussion.

@jklymak
Copy link
Member Author

jklymak commented Mar 18, 2021

Yes, it was removed here: https://github.com/matplotlib/matplotlib/pull/15489/files I don't see much discussion of dropping API...

Comment on lines 19 to 21
(Note that there is also a parallel `matplotlib.pyplot` API interface
that is considered useful for interactive work; see
:ref:`usage patterns <usage_patterns>`, below).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(Note that there is also a parallel `matplotlib.pyplot` API interface
that is considered useful for interactive work; see
:ref:`usage patterns <usage_patterns>`, below).
Alternatively, there is also a parallel `matplotlib.pyplot` API interface
that is considered useful for interactive work; see
:ref:`usage patterns <usage_patterns>`, below.

Copy link
Member

Choose a reason for hiding this comment

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

But I'm not sure we should mention the distinction here at all. Particularly also because the following example uses the object-based approach, but still needs to use pyplot for Figure and Axes creation. It's quite confusing that the non-pyplot approach still needs pyplot. So, I'd not go into the details here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure - I struggled a bit with how to work this in, or if I should. It is such a common point of confusion that someone wrote a whole section and stuck it at the top of the API docs, so it seemed at least referring to it near the top would be useful, but I'm happy to leave it out.


The pylab API (disapproved)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
fig, ax = plt.subplots(figsize=(3,2), constrained_layout=True)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fig, ax = plt.subplots(figsize=(3,2), constrained_layout=True)
fig, ax = plt.subplots()

Keep it simple without parameters. While constrained_layout is nice, IMHO this is not the place to teach it (and the benefit for this simple plot is small).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but then the figure is too large, in my opinion.

Copy link
Member

Choose a reason for hiding this comment

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

You could try with

.. plot::
   :scale: 50 %

but I'm not sure if that will look good.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I wish there was a two-column view.... We could just include the code and the figure as an image as well. I do think the example is useful, though, to make it concrete what we are talking about.

Copy link
Member Author

Choose a reason for hiding this comment

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

By default, the ylabel is cutoff, so some formatting is necessary anyway.. Might as well keep what is above. I don't think we need to explain every incantation everywhere it appears.

ax.plot(x, y)
ax.set_xlabel('t [s]')
ax.set_ylabel('S [V]')
fig.suptitle('Sine wave')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fig.suptitle('Sine wave')
ax.set_title('Sine wave')
fig.patch.set_color('lightsteelblue')

One would not use fig.suptitle with a single Axes. This looks a bit odd because the title is centered on the figure not the Axes. There are actually not too many reasonable uses for figure methods in this simple example. Coloring the background may be one of the better ones.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are we trying to soft deprecate fig.set_facecolor? I understand not wanting duplicate ways of doing the same thing, but asking folks to modify a property like this is a discoverability issue.


Modules
-------

Matplotlib consists of the following submodules:
Alphabetical list of submodules:

.. toctree::
:maxdepth: 1
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
:maxdepth: 1
:maxdepth: 1
:multicol-toc:

Maybe.
grafik

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this unreleased? I get /Users/jklymak/matplotlib/doc/api/index.rst:45: WARNING: Error in "toctree" directive: unknown option: "multicol-toc". on sphinx 3.5.3

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, this should have been :class: multicol-toc.

multicol-toc is just a CSS class we have added to our mpl.css.

Copy link
Member Author

@jklymak jklymak Mar 21, 2021

Choose a reason for hiding this comment

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

oops searched the internet - didn't think to search our source code...

Copy link
Member

Choose a reason for hiding this comment

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

Sorry this does not seem to work. .. toctree: does not support a :class: attribute.

I've otherwise only used it for .. contents: so far. The above screenshot was a hacked CSS in the browser, because I didn't want to wait for a docs build.

Seems we have to live with the long list for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ha! I thought I was going crazy... Certainly adding a class directive to toctree seems like a good idea, but seems like an upstream issue.

@jklymak jklymak force-pushed the doc-api-frontpage branch from 308bc7b to 71fa500 Compare March 20, 2021 17:34
@tacaswell
Copy link
Member

I'm good with this as it is now, but did not catch up on the full discussion so am holding off on merging.

@jklymak jklymak requested a review from timhoffm March 24, 2021 20:32
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Certainly an improvement. Thanks @jklymak!

@timhoffm timhoffm merged commit 1937d0b into matplotlib:master Mar 24, 2021
@jklymak jklymak deleted the doc-api-frontpage branch March 24, 2021 23:21
@jklymak
Copy link
Member Author

jklymak commented Mar 24, 2021

Thanks both!

@jklymak jklymak mentioned this pull request Aug 29, 2023
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 this pull request may close these issues.

3 participants