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

Skip to content

[DOC] Enhance API reference index #26671

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 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/_static/mpl.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ table.property-table td {
margin: 0 0.5em;
}

/* Make the code examples in the API reference index the same height. */
.api-interface-example pre {
min-height: 6.5rem;
}

/* Make inheritance images have a scroll bar if necessary. */
div.graphviz {
border: 1px solid lightgrey;
Expand Down
56 changes: 42 additions & 14 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,69 @@ API Reference
Matplotlib interfaces
---------------------

Matplotlib provides two different interfaces:

- **Axes interface**: create a `.Figure` and one or more `~.axes.Axes` objects
(typically using `.pyplot.subplots`), then *explicitly* use methods on these objects
to add data, configure limits, set labels etc.
- **pyplot interface**: consists of functions in the `.pyplot` module. Figure and Axes
are manipulated through these functions and are only *implicitly* present in the
background.

See :ref:`api_interfaces` for a more detailed description of both and their recommended
use cases.
Matplotlib has two interfaces. See :ref:`api_interfaces` for a more detailed
description of both and their recommended use cases.

.. grid:: 1 1 2 2
:padding: 0 0 1 1
:padding: 0
:gutter: 2

.. grid-item-card::
:shadow: none
:class-footer: api-interface-footer

**Axes interface** (object-based, explicit)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

create a `.Figure` and one or more `~.axes.Axes` objects, then *explicitly* use
methods on these objects to add data, configure limits, set labels etc.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

API:

- `~.pyplot.subplots`: create Figure and Axes
- :mod:`~matplotlib.axes`: add data, limits, labels etc.
- `.Figure`: for figure-level methods

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Example:
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if Example and API need to be explicitly written - I can go either way on this. What I mean is the example and api roadmapping should definitely be here, but I dunno about the title.

Copy link
Member Author

Choose a reason for hiding this comment

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

Slight preference to keep them. It's more explicit what the sections are about, in particular if you have only a quick glance at it. I think the cards are still compact enough so that we can afford the extra vertical space.


.. code-block:: python
:class: api-interface-example

fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_title("Sample plot")
plt.show()


.. grid-item-card::
:shadow: none
:class-footer: api-interface-footer

**pyplot interface** (function-based, implicit)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

consists of functions in the `.pyplot` module. Figure and Axes are manipulated
through these functions and are only *implicitly* present in the background.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

API:

- `matplotlib.pyplot`

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Example:

.. code-block:: python
:class: api-interface-example

plt.plot(x, y)
plt.title("Sample plot")
plt.show()


.. _api-index:

Expand Down