-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
lib/matplotlib/axes/_axes.py
Outdated
|
||
Notes | ||
----- | ||
|
||
**Masked arrays** |
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.
does numpydoc not support lower-level headings?
Masked arrays
~~~~~~~~~~~~~
(dunno)
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.
Nope. If you try this, numpydoc simply swallows the lower-level headings.
I think structuring with bold paragraphs is the best one can do.
lib/matplotlib/axes/_axes.py
Outdated
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. | ||
|
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.
as there's no heading there I'm not sure this anchor is correct (see above re lower headings)
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.
This does work the id is attached to the paragraph:
<p id="axes-pcolor-grid-orientation"><strong>Grid orientation</strong></p>
lib/matplotlib/axes/_axes.py
Outdated
@@ -5268,62 +5268,69 @@ 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 of a 2-D array using quadrilaterals. |
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.
Not convinced "using quadrilaterals" really helps here (and yes I know how pcolor is implemented).
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.
I think we need some sort of addition to differentiate it from imshow
and matshow
. A better wording is welcome.
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.
Its explained below - I think the differentiation is useful. OTOH to me the main difference w/ imshow
is that the lateral and vertical spacing can be non-even (as opposed to distorted grids.)
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.
Alternatively I could do "Create a pseudocolor plot with a non-regular rectangular grid." Is that more helpful?
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.
I like that wording!
lib/matplotlib/axes/_axes.py
Outdated
@@ -5268,62 +5268,69 @@ 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 of a 2-D array using quadrilaterals. |
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.
Its explained below - I think the differentiation is useful. OTOH to me the main difference w/ imshow
is that the lateral and vertical spacing can be non-even (as opposed to distorted grids.)
lib/matplotlib/axes/_axes.py
Outdated
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 quadrilatals. |
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.
Typo: quadrilaterals
@@ -5338,39 +5345,46 @@ def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None, | |||
Other Parameters | |||
---------------- | |||
antialiaseds : bool, optional, default: False |
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.
wow, is this really the parameter name? Thats terrible!
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, 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.
lib/matplotlib/axes/_axes.py
Outdated
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). | ||
The grid orientation follows the MATLAB convention: an array *C* with |
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.
I don't particularly like this note, and find it confusing as written. Can we improve it while here?
"""
An array *C* with shape (nrows, columns) is plotted with the column number *X*
and the row number as *Y*.
"""
suffices in my opinion. I don't understand why anyone would think that y[j]
doesn't correspond to C[j, i]
so the only ambiguous orientation is if C
is organized as C[j, i]
or C[i, j]
.
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.
Significantly shortend to:
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.
Removed also the whole example stuff as it's more confusing than helpflul.
lib/matplotlib/axes/_axes.py
Outdated
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``. | ||
**Difference to MATLAB pcolor()** |
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.
again:
Handling of pcolor end-cases
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.
lib/matplotlib/axes/_axes.py
Outdated
@@ -5268,62 +5268,69 @@ 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 of a 2-D array using quadrilaterals. |
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.
I like that wording!
@meeseeksdev backport to v2.2.x |
...we aren't backporting *.py files...
|
That does only hold for the branch v2.2-doc. I'm quite strongly for backporting pure docstring updates to 2.2.x. It will be around for quite some time and definitively deserves the docstring improvements. We can discuss if I should backport this to v2.2.x or v2.2-doc. But I really want to backport this somehow. |
I'm not at all the final say on these things, so please feel free to argue up the chain... But I think 2.2.x is just for regressions and other important bug fixes. I don't think we want to also be merging in a bunch of doc string changes. I agree they are hugely helpful, but folks have managed to muddle through with the old docs so I personally don't think its critical that they be backported. But I don't actually do the backporting... |
…n-v2.2.x Backport PR #11317 on branch v2.2.x
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 |
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.
I can't run the tests wth this line: SyntaxError: invalid escape sequence \
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.
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?
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.
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.
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.
@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+.
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.
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 😉...
PR Summary
As part of #10148: Docstring update for
Axes.pcolor
.