Skip to content

imshow extent keyword (documentation?) #990

@jomade

Description

@jomade

The imshow documentation as of version 1.1.0 contains the following statement:

*extent*: [ None | scalars (left, right, bottom, top) ]
   Data limits for the axes.  The default assigns zero-based row,
   column indices to the *x*, *y* centers of the pixels.

Which is kind of correct but misleading in two cases (and why is there stars around x and y? - there is no other x and y in the doc as far as I can see):

Case 1

Extent does not expect a list of indices as described in the text, but only two numbers per dimension (as given in the heading).
I would propose to move the description how data is displayed (with zero based row and column indices) to the top of the documentation

By default the data is displayed with range(M) and range(N) as axis 
coordinates for the row and column centers of the pixels, respectively. See 
use of *extent* keyword to adjust axis coordinates.

Case 2

The documentation suggests (at least to me) that extent is to specify for the pixel centers and not the borders.
For illustration try:

figure()
imshow(np.array([[1,2,3],[4,5,6]]), interpolation='nearest')

vs

figure()
imshow(np.array([[1,2,3],[4,5,6]]), interpolation='nearest', extent=(0,2,0,1))

So
imshow(X, extent=(0, N, 0, M))
will not give you default behaviour.
The default behaviour can be achieved if half a pixel size is added on each side:
imshow(X, extent=(0-0.5, N+0.5, 0-0.5, M+0.5))

I'm not sure if this is intended behaviour or not.

It would be nice to be able to produce and image from the pixel centers given as keyword arguments as
imshow(X, row_axis=range(M), column_axis=range(N))
or something like that.

However, if it is intended behaviour: I would propose the following documentation for the extent keyword:
extent: [ None | scalars (left, right, bottom, top) ]
Data limits for the axes. The limits range from the beginning of the first to the end of the
last pixel. Thus the extent specification for the default behaviour is:
imshow(X, extent=(-0.5, N+0.5, -0.5, M+0.5)).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions