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

Skip to content

Improve docstring of Axes.pcolor #11317

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
May 28, 2018
Merged
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
155 changes: 74 additions & 81 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5268,62 +5268,73 @@ def _pcolorargs(funcname, *args, allmatch=False):
def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
vmax=None, **kwargs):
"""
Create a pseudocolor plot of a 2-D array.
Create a pseudocolor plot with a non-regular rectangular grid.

Call signatures::
Call signature::

pcolor(C, **kwargs)
pcolor(X, Y, C, **kwargs)
pcolor([X, Y,] C, **kwargs)

pcolor can be very slow for large arrays; consider
using the similar but much faster
:func:`~matplotlib.pyplot.pcolormesh` instead.
*X* and *Y* can be used to specify the corners of the quadrilaterals.

.. hint::

``pcolor()`` can be very slow for large arrays. In most
cases you should use the the similar but much faster
`~.Axes.pcolormesh` instead. See there for a discussion of the
differences.

Parameters
----------
C : array_like
An array of color values.
A scalar 2-D array. The values will be color-mapped.

X, Y : array_like, optional
If given, specify the (x, y) coordinates of the colored
quadrilaterals; the quadrilateral for ``C[i,j]`` has corners at::

(X[i, j], Y[i, j]),
(X[i, j+1], Y[i, j+1]),
(X[i+1, j], Y[i+1, j]),
(X[i+1, j+1], Y[i+1, j+1])
The coordinates of the quadrilateral corners. The quadrilateral
for ``C[i,j]`` has corners at::

Ideally the dimensions of ``X`` and ``Y`` should be one greater
than those of ``C``; if the dimensions are the same, then the last
row and column of ``C`` will be ignored.
(X[i+1, j], Y[i+1, j]) (X[i+1, j+1], Y[i+1, j+1])
+--------+
| C[i,j] |
+--------+
(X[i, j], Y[i, j]) (X[i, j+1], Y[i, j+1]),

Note that the column index corresponds to the
x-coordinate, and the row index corresponds to y; for
details, see the :ref:`Grid Orientation
<axes-pcolor-grid-orientation>` section below.
x-coordinate, and the row index corresponds to y. For
details, see the :ref:`Notes <axes-pcolor-grid-orientation>`
section below.

If either or both of ``X`` and ``Y`` are 1-D arrays or column
vectors, they will be expanded as needed into the appropriate 2-D
arrays, making a rectangular grid.
The dimensions of *X* and *Y* should be one greater than those of
*C*. Alternatively, *X*, *Y* and *C* may have equal dimensions, in
which case the last row and column of *C* will be ignored.

cmap : `~matplotlib.colors.Colormap`, optional, default: None
If `None`, default to rc settings.
If *X* and/or *Y* are 1-D arrays or column vectors they will be
expanded as needed into the appropriate 2-D arrays, making a
rectangular grid.

cmap : str or `~matplotlib.colors.Colormap`, optional
A Colormap instance or registered colormap name. The colormap
maps the *C* values to colors. Defaults to :rc:`image.cmap`.

norm : `matplotlib.colors.Normalize`, optional, default: None
An instance is used to scale luminance data to (0, 1).
If `None`, defaults to :func:`normalize`.
norm : `~matplotlib.colors.Normalize`, optional
The Normalize instance scales the data values to the canonical
colormap range [0, 1] for mapping to colors. By default, the data
range is mapped to the colorbar range using linear scaling.

vmin, vmax : scalar, optional, default: None
``vmin`` and ``vmax`` are used in conjunction with ``norm`` to
normalize luminance data. If either is `None`, it is autoscaled to
the respective min or max of the color array ``C``. If not `None`,
``vmin`` or ``vmax`` passed in here override any pre-existing
values supplied in the ``norm`` instance.
The colorbar range. If *None*, suitable min/max values are
automatically chosen by the `~.Normalize` instance (defaults to
the respective min/max values of *C* in case of the default linear
scaling).

edgecolors : {'none', None, color, color sequence}, optional
The color of the edges. Defaults to 'none'. Possible values:

edgecolors : {None, 'none', color, color sequence}
If None, the rc setting is used by default.
If 'none', edges will not be visible.
An mpl color or sequence of colors will set the edge color.
- 'none' or '': No edge.
- *None*: :rc:`patch.edgecolor` will be used. Note that currently
:rc:`patch.force_edgecolor` has to be True for this to work.
- An mpl color or sequence of colors will set the edge color.

The singular form *edgecolor* works as an alias.

alpha : scalar, optional, default: None
The alpha blending value, between 0 (transparent) and 1 (opaque).
Expand All @@ -5338,72 +5349,54 @@ def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
Other Parameters
----------------
antialiaseds : bool, optional, default: False
Copy link
Member

Choose a reason for hiding this comment

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

wow, is this really the parameter name? Thats terrible!

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, we have this pluralization scheme in some places, see e.g. LineCollection: colors, edgecolors, antialiaseds, ... Not really great and IMO not really necessary to pluralize, but it's the way it is now.

The default ``antialiaseds`` is False if the default
``edgecolors="none"`` is used. This eliminates artificial lines
The default *antialiaseds* is False if the default
*edgecolors*\ ="none" is used. This eliminates artificial lines
Copy link
Member

Choose a reason for hiding this comment

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

I can't run the tests wth this line: SyntaxError: invalid escape sequence \

Copy link
Member Author

Choose a reason for hiding this comment

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

Strange. This is the recommended way:

 Use a backslash escaped space to work around that: thisis\ *one*\ word.

The docs itself look fine:
https://matplotlib.org/devdocs/api/_as_gen/matplotlib.axes.Axes.pcolor.html?highlight=pcolor#matplotlib.axes.Axes.pcolor

Why is the test inspecting the docstring at all? Do we have some doctests somewhere that need to be run?

Copy link
Member

Choose a reason for hiding this comment

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

Its a syntax error for me on one machine, but not on another. Grrrr. Maybe I have a messed up install on the other machine (which I can't access right now, of course).

Appending a r""" docstring """ makes it work again on the other machine.

Copy link
Member

@QuLogic QuLogic May 29, 2018

Choose a reason for hiding this comment

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

@timhoffm The recommended way you cite is for Sphinx, while @jklymak's error is coming from Python. The backslash escape for Sphinx is on the text that it sees, which is either a reST file or a docstring (extracted to a reST file by auto-something), but in order to place the backslash in the docstring, you also need to escape it for Python. So you need to double-escape or make it a raw string.

As to why @jklymak only sees it on one machine, maybe it's tests.py vs pytest? The former turns these deprecation warnings into errors. Also, the warnings are only raised on Python 3.6+.

Copy link
Member

Choose a reason for hiding this comment

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

Ahh. Thanks @QuLogic : python tests.py does not work and gives the Syntax Error. py.test works. Thats what I get for just hitting ^R for the last time I ran the tests - obviously on one machine I mentally upgraded to py.test and the other I haven't 😉...

at patch boundaries, and works regardless of the value of alpha.
If ``edgecolors`` is not "none", then the default ``antialiaseds``
If *edgecolors* is not "none", then the default *antialiaseds*
is taken from :rc:`patch.antialiased`, which defaults to True.
Stroking the edges may be preferred if ``alpha`` is 1, but will
Stroking the edges may be preferred if *alpha* is 1, but will
cause artifacts otherwise.

**kwargs :

Any unused keyword arguments are passed along to the
`~matplotlib.collections.PolyCollection` constructor:
Additionally, the following arguments are allowed. They are passed
along to the `~matplotlib.collections.PolyCollection` constructor:

%(PolyCollection)s

See Also
--------
pcolormesh : for an explanation of the differences between
pcolor and pcolormesh.
imshow : If *X* and *Y* are each equidistant, `~.Axes.imshow` can be a
faster alternative.

Notes
-----
.. _axes-pcolor-grid-orientation:

``X``, ``Y`` and ``C`` may be masked arrays. If either C[i, j], or one
of the vertices surrounding C[i,j] (``X`` or ``Y`` at [i, j], [i+1, j],
[i, j+1], [i+1, j+1]) is masked, nothing is plotted.

The grid orientation follows the MATLAB convention: an array ``C`` with
shape (nrows, ncolumns) is plotted with the column number as ``X`` and
the row number as ``Y``, increasing up; hence it is plotted the way the
array would be printed, except that the ``Y`` axis is reversed. That
is, ``C`` is taken as ``C`` (y, x).

Similarly for :func:`meshgrid`::

x = np.arange(5)
y = np.arange(3)
X, Y = np.meshgrid(x, y)
**Masked arrays**

is equivalent to::
*X*, *Y* and *C* may be masked arrays. If either ``C[i, j]``, or one
of the vertices surrounding ``C[i,j]`` (*X* or *Y* at
``[i, j], [i+1, j], [i, j+1], [i+1, j+1]``) is masked, nothing is
plotted.

X = array([[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4],
[0, 1, 2, 3, 4]])

Y = array([[0, 0, 0, 0, 0],
[1, 1, 1, 1, 1],
[2, 2, 2, 2, 2]])

so if you have::

C = rand(len(x), len(y))
.. _axes-pcolor-grid-orientation:

then you need to transpose C::
**Grid orientation**

pcolor(X, Y, C.T)
The grid orientation follows the standard matrix convention: An array
*C* with shape (nrows, ncolumns) is plotted with the column number as
*X* and the row number as *Y*.

or::
**Handling of pcolor() end-cases**

pcolor(C.T)
``pcolor()`` displays all columns of *C* if *X* and *Y* are not
specified, or if *X* and *Y* have one more column than *C*.
If *X* and *Y* have the same number of columns as *C* then the last
column of *C* is dropped. Similarly for the rows.

MATLAB :func:`pcolor` always discards the last row and column of ``C``,
but Matplotlib displays the last row and column if ``X`` and ``Y`` are
not specified, or if ``X`` and ``Y`` have one more row and column than
``C``.
Note: This behavior is different from MATLAB's ``pcolor()``, which
always discards the last row and column of *C*.
"""
X, Y, C = self._pcolorargs('pcolor', *args, allmatch=False)
Ny, Nx = X.shape
Expand Down