diff --git a/doc/_static/mpl.css b/doc/_static/mpl.css index e9d7d65f3e01..45ecb21d5511 100644 --- a/doc/_static/mpl.css +++ b/doc/_static/mpl.css @@ -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; diff --git a/doc/api/index.rst b/doc/api/index.rst index 1b098009faed..e55a0ed3c5b2 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -4,25 +4,23 @@ 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: @@ -30,15 +28,45 @@ use cases. - :mod:`~matplotlib.axes`: add data, limits, labels etc. - `.Figure`: for figure-level methods + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + Example: + + .. 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: