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

Skip to content

Commit 33ee6ee

Browse files
committed
Merge pull request #421 from efiring/matshow_extent
matshow: behave well with origin kwarg
2 parents 850f097 + 29ec51b commit 33ee6ee

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8214,19 +8214,16 @@ def matshow(self, Z, **kwargs):
82148214
*Z* anything that can be interpreted as a 2-D array
82158215
82168216
kwargs all are passed to :meth:`~matplotlib.axes.Axes.imshow`.
8217-
:meth:`matshow` sets defaults for *extent*, *origin*,
8218-
*interpolation*, and *aspect*; use care in overriding the
8219-
*extent* and *origin* kwargs, because they interact. (Also,
8220-
if you want to change them, you probably should be using
8221-
imshow directly in your own version of matshow.)
8217+
:meth:`matshow` sets defaults for *origin*,
8218+
*interpolation*, and *aspect*; if you want row zero to
8219+
be at the bottom instead of the top, you can set the *origin*
8220+
kwarg to "lower".
82228221
82238222
Returns: an :class:`matplotlib.image.AxesImage` instance.
82248223
'''
8225-
Z = np.asarray(Z)
8224+
Z = np.asanyarray(Z)
82268225
nr, nc = Z.shape
8227-
extent = [-0.5, nc-0.5, nr-0.5, -0.5]
8228-
kw = {'extent': extent,
8229-
'origin': 'upper',
8226+
kw = {'origin': 'upper',
82308227
'interpolation': 'nearest',
82318228
'aspect': 'equal'} # (already the imshow default)
82328229
kw.update(kwargs)

lib/matplotlib/pyplot.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,8 +1710,10 @@ def matshow(A, fignum=None, **kw):
17101710
17111711
Tick labels for the xaxis are placed on top.
17121712
1713-
With the exception of fignum, keyword arguments are passed to
1714-
:func:`~matplotlib.pyplot.imshow`.
1713+
With the exception of *fignum*, keyword arguments are passed to
1714+
:func:`~matplotlib.pyplot.imshow`. You may set the *origin*
1715+
kwarg to "lower" if you want the first row in the array to be
1716+
at the bottom instead of the top.
17151717
17161718
17171719
*fignum*: [ None | integer | False ]
@@ -1724,6 +1726,7 @@ def matshow(A, fignum=None, **kw):
17241726
17251727
If *fignum* is *False* or 0, a new figure window will **NOT** be created.
17261728
"""
1729+
A = np.asanyarray(A)
17271730
if fignum is False or fignum is 0:
17281731
ax = gca()
17291732
else:

0 commit comments

Comments
 (0)