-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
DOC: simplify API index #19727
Changes from all commits
0e26ab8
94ced26
e80f6b8
3c9d40b
8029382
961de9b
71fa500
e46ebc1
783f606
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,46 @@ | ||
API Overview | ||
============ | ||
API | ||
=== | ||
|
||
.. toctree:: | ||
:hidden: | ||
|
||
api_changes | ||
|
||
.. contents:: :local: | ||
For recent changes, see :doc:`api_changes`. | ||
|
||
See also the :doc:`api_changes`. | ||
When using the library you will typically create | ||
:doc:`Figure <figure_api>` and :doc:`Axes <axes_api>` objects and | ||
call their methods to add content and modify the apprearance. | ||
|
||
Usage patterns | ||
-------------- | ||
|
||
Below we describe several common approaches to plotting with Matplotlib. | ||
|
||
The pyplot API | ||
^^^^^^^^^^^^^^ | ||
|
||
`matplotlib.pyplot` is a collection of command style functions that make | ||
Matplotlib work like MATLAB. Each pyplot function makes some change to a | ||
figure: e.g., creates a figure, creates a plotting area in a figure, plots | ||
some lines in a plotting area, decorates the plot with labels, etc. | ||
- :doc:`figure_api`: axes creation, figure-level content | ||
- :doc:`axes_api`: most plotting methods, Axes labels, access to | ||
axis styling, etc. | ||
|
||
`.pyplot` is mainly intended for interactive plots and simple cases of | ||
programmatic plot generation. | ||
Example: We create a Figure ``fig`` and Axes ``ax``. Then we call | ||
methods on them to plot data, add axis labels and a figure title. | ||
|
||
.. plot:: | ||
:include-source: | ||
:align: center | ||
|
||
Further reading: | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
- The `matplotlib.pyplot` function reference | ||
- :doc:`/tutorials/introductory/pyplot` | ||
- :ref:`Pyplot examples <pyplots_examples>` | ||
x = np.arange(0, 4, 0.05) | ||
y = np.sin(x*np.pi) | ||
|
||
.. _api-index: | ||
fig, ax = plt.subplots(figsize=(3,2), constrained_layout=True) | ||
ax.plot(x, y) | ||
ax.set_xlabel('t [s]') | ||
ax.set_ylabel('S [V]') | ||
ax.set_title('Sine wave') | ||
fig.set_facecolor('lightsteelblue') | ||
|
||
The object-oriented API | ||
^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
At its core, Matplotlib is object-oriented. We recommend directly working | ||
with the objects, if you need more control and customization of your plots. | ||
|
||
In many cases you will create a `.Figure` and one or more | ||
`~matplotlib.axes.Axes` using `.pyplot.subplots` and from then on only work | ||
on these objects. However, it's also possible to create `.Figure`\ s | ||
explicitly (e.g. when including them in GUI applications). | ||
|
||
Further reading: | ||
|
||
- `matplotlib.axes.Axes` and `matplotlib.figure.Figure` for an overview of | ||
plotting functions. | ||
- Most of the :ref:`examples <examples-index>` use the object-oriented approach | ||
(except for the pyplot section) | ||
|
||
The pylab API (disapproved) | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. automodule:: pylab | ||
:no-members: | ||
|
||
Modules | ||
------- | ||
|
||
Matplotlib consists of the following submodules: | ||
Alphabetical list of modules: | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this unreleased? I get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, this should have been
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops searched the internet - didn't think to search our source code... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry this does not seem to work. I've otherwise only used it for Seems we have to live with the long list for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
@@ -147,3 +126,54 @@ Matplotlib. The following toolkits are included: | |
toolkits/axes_grid1.rst | ||
toolkits/axisartist.rst | ||
toolkits/axes_grid.rst | ||
|
||
|
||
.. _usage_patterns: | ||
|
||
Usage patterns | ||
-------------- | ||
|
||
Below we describe several common approaches to plotting with Matplotlib. | ||
|
||
The pyplot API | ||
^^^^^^^^^^^^^^ | ||
|
||
`matplotlib.pyplot` is a collection of functions that make | ||
Matplotlib work like MATLAB. Each pyplot function makes some change to a | ||
figure: e.g., creates a figure, creates a plotting area in a figure, plots | ||
some lines in a plotting area, decorates the plot with labels, etc. | ||
|
||
`.pyplot` is mainly intended for interactive plots and simple cases of | ||
programmatic plot generation. | ||
|
||
Further reading: | ||
|
||
- The `matplotlib.pyplot` function reference | ||
- :doc:`/tutorials/introductory/pyplot` | ||
- :ref:`Pyplot examples <pyplots_examples>` | ||
|
||
.. _api-index: | ||
|
||
The object-oriented API | ||
^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
At its core, Matplotlib is object-oriented. We recommend directly working | ||
with the objects, if you need more control and customization of your plots. | ||
|
||
In many cases you will create a `.Figure` and one or more | ||
`~matplotlib.axes.Axes` using `.pyplot.subplots` and from then on only work | ||
on these objects. However, it's also possible to create `.Figure`\ s | ||
explicitly (e.g. when including them in GUI applications). | ||
|
||
Further reading: | ||
|
||
- `matplotlib.axes.Axes` and `matplotlib.figure.Figure` for an overview of | ||
plotting functions. | ||
- Most of the :ref:`examples <examples-index>` use the object-oriented approach | ||
(except for the pyplot section) | ||
|
||
The pylab API (disapproved) | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. automodule:: pylab | ||
:no-members: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could try with
but I'm not sure if that will look good.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.