-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Improve docstring of Axes.imshow #10982
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
See #10442 for making filternorm a bool. |
In line 5177
is incorrect in two ways.
|
lib/matplotlib/axes/_axes.py
Outdated
corner of the axes. If None, default to rc `image.origin`. | ||
corner of the axes. The convention 'upper' is typically used for | ||
matrices; 'lower' is typically used for image data. Defaults to | ||
:rc:`image.origin`. |
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.
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.
What are data arrays? numpy also uses the 'upper' convention:
>>> print(np.array([[1, 2], [3, 4]]))
[[1, 2],
[3, 4]]
For now, I don't have a good example for 'lower', so I just say
The convention 'upper' is typically used for matrices and images.
and don't give an example for lower.
beed2b6
to
dbd28f6
Compare
Description for extent corrected. |
dbd28f6
to
28ade6a
Compare
This is still not correct. The default origin is "upper" via the rcParams. Hence the lower left pixel is at (0,rows) (see left-most plot above). To achieve this plot by setting an extent you need In case the origin is "lower", the sentence is correct. (c.f. the right two plots above). To be on the safe side here, maybe the only option is to clearly state both possible cases.
I guess ideally there should be a link to an example showing all possible cases. |
I'm inclined to avoid the word "matrix" altogether since the |
28ade6a
to
b0c5c56
Compare
@ImportanceOfBeingErnest hopefully extent is now more understandable. Also with a motivation, why this is a bit tricky. An example would be great, but that's beyond this PR. |
There's already a PR for an example for origin/extent: #10947 |
Can this be coincidence? That's perfect! I didn't see that at all. It definitely needs to be linked to (in both, origin and extent). |
lib/matplotlib/axes/_axes.py
Outdated
when interpolation is one of: 'sinc', 'lanczos' or 'blackman'. | ||
|
||
resample | ||
Undocumented. |
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.
can we sort out what resample
does?
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 couldn't. I can track down its use to _image_interpolation.h l.987. but that C code doesn't speak to me. It appears to be written by @mdboom. Maybe he could enlighten us?
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.
It is documented in the resample C wrapper.
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.
Thanks. I've copied the doc. Still I'm not 100% clear what this does:
- When will resampling (no matter if full or partial) occur.
- what are the output and the input images?
lib/matplotlib/axes/_axes.py
Outdated
integer coordinates and their center coordinates range from 0 to | ||
columns-1 horizontally and from 0 to rows-1 vertically. | ||
|
||
Note that the meaning of *top* and *bottom* depend on *origin* |
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 is not quite right, I would say that 'origin' controls how the image is filled in, but not the meaning of 'top' and 'bottom'.
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.
Changed to:
Note that the relation of top and bottom to data coordinates depends on origin.
"controls how the image is filled in" is true but does not help for describing the default values.
f05bea3
to
3f985bd
Compare
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.
Still not happy with the changes to the extent docstring. Sorry for being difficult on this.
lib/matplotlib/axes/_axes.py
Outdated
integer coordinates and their center coordinates range from 0 to | ||
columns-1 horizontally and from 0 to rows-1 vertically. | ||
|
||
Note that the relation of *top* and *bottom* to data coordinates |
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.
The meaning of 'top' and 'bottom' in data coordinates does not change, what changes is the orientation of the array in the bounding box.
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.
The bounding box edges are exactly where expected in dataspace.
lib/matplotlib/axes/_axes.py
Outdated
vertical axis. | ||
|
||
- If origin is set to "upper", the center of the lower left | ||
pixel is at (0, rows) , this corresponds to an extent |
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 suggest something like:
- If origin is set to "upper" then the default extents is (...)
- If origin is set to "lower" then the default extents is (...)
If the axes auto-scales the limits than this arranges such that the value in X[0, 0] is at (0, 0) in data-coordinates in both cases. In the case of "upper" the (0, 0) is in the upper left and the y-axis increases downward. In the case of "lower", the (0, 0) is in the lower left and the y-axis increases upward.
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.
Maybe this needs a comment "having 'bottom > top' or 'left > right' may invert the drawn image"?
lib/matplotlib/axes/_axes.py
Outdated
The location, in data-coordinates, of the lower-left and | ||
upper-right corners. If `None`, the image is positioned such that | ||
the pixel centers fall on zero-based (row, column) indices. | ||
upper-right corners. |
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.
'... of the image's bounding box'
No worries, it‘s this API being difficult, not you.
|
7b85456
to
801226d
Compare
There's now only a basic mention of the interaction between |
db056fd
to
feeb1a3
Compare
This PR will also fix #10323 once it's merged. |
feeb1a3
to
1e12880
Compare
Changed to more common notation |
@tacaswell Now that #10947 is merged and linked, I hope that the documentation on extent is right and this PR is good to go. |
axes. | ||
aspect : {'equal', 'auto'} or float, optional | ||
Controls the aspect ratio of the axes. The aspect is of particular | ||
relevance for images since it may distort the image, i.e. pixel |
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.e. pixels will not be square....
lib/matplotlib/axes/_axes.py
Outdated
If 'equal', and `extent` is None, changes the axes aspect ratio to | ||
match that of the image. If `extent` is not `None`, the axes | ||
aspect ratio is changed to match that of the extent. | ||
This parameter is just a shortcut for explicitly calling |
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.
strike "just"....
lib/matplotlib/axes/_axes.py
Outdated
`X` must be an array of integers that index directly into | ||
the lookup table of the `cmap`. | ||
norm : `~matplotlib.colors.Normalize`, optional | ||
If scalar data is used, the Normalize instance scales the |
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.
"... scalar data are used" (data is usually plural)....
lib/matplotlib/axes/_axes.py
Outdated
corner of the axes. If None, default to rc `image.origin`. | ||
corner of the axes. The convention 'upper' is typically used for | ||
matrices and images. | ||
Defaults to :rc:`image.origin`. |
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 have no idea what image.origin defaults to. I think we could/should say what the default of the default is.
lib/matplotlib/axes/_axes.py
Outdated
The location, in data-coordinates, of the lower-left and | ||
upper-right corners. If `None`, the image is positioned such that | ||
the pixel centers fall on zero-based (row, column) indices. | ||
By default, pixels have a size of (1, 1). They are centered on |
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 found this first sentence strange.
"""By default the extent of the image is one data unit per pixel, centered on integer co-ordinates. So the horizontal axis ranges from 0 to N-1, and the vertical axes from 0 to M-1. Specifying extent displays a subset of the data in this co-ordinate system.
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 extent of the image is one data unit per pixel, centered on integer co-ordinates.
To me, that sounds even more strange. Extent is a range, which cannot be "one data unit per pixel". Also the extent is not centered, the pixels are.
Specifying extent displays a subset of the data in this co-ordinate system.
That sounds like clipping, which is not true. Extent scales the data.
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.
Oops my mistake. What a confusing name for the kwarg. Regardless it still isn’t very clear.
How about pixels columns are linearly mapped between extent[0] and extent[3] and rows between ... by default these extents are ....
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.
Wouldn't bother with columns and linear mapping to explain streching. Here's my current committed version:
The bounding box in data coordinates that the image will fill.
The image is stretched individually along x and y to fill the box.The default extent is determined by the following conditions.
Pixels have unit size in data coordinates. Their centers are on
integer coordinates, and their center coordinates range from 0 to
columns-1 horizontally and from 0 to rows-1 vertically.
I'll give @tacaswell another day to comment if he wants, and then we can merge. Its a big improvement, and can be refined again if necessary. |
lib/matplotlib/axes/_axes.py
Outdated
See also the `filternorm` and `filterrad` parameters. | ||
If `interpolation` is 'none', then no interpolation is performed | ||
See also the *filternorm* and *filterrad* parameters. | ||
If *interpolation* is 'none', then no interpolation is performed | ||
on the Agg, ps and pdf backends. Other backends will fall back to | ||
'nearest'. | ||
|
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.
A totally minor suggestion: At this point it could make sense to link to the interpolation_methods example.
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.
Sure. Added. Revisiting the interpolation docstring revealed that it was not good anyway. So improved that as well.
Thanks a lot @timhoffm - if anyone still has issues w/ this, we can have a new PR 😉.... |
PR Summary
As part of #10148: Docstring update for
Axes.imshow
.resample
was not documented. From the code, I couldn't really find out what it does.shape
andimlim
are unused and should probably be removed (would do that in a separate PR once this is merged).filternorm
should probably be a bool all throughout the class hirarchy (separate PR as well).X
forZ
as is the case in matshow?Z
makes a bit more sense, however, technically this would be a breaking change if a user has used it as kwargimshow(X=data)