Skip to content

Backport PR #11565 on branch v2.2.x #11574

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
Jul 5, 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
41 changes: 27 additions & 14 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,7 @@ def imsave(*args, **kwargs):
return _imsave(*args, **kwargs)


def matshow(A, fignum=None, **kw):
def matshow(A, fignum=None, **kwargs):
"""
Display an array as a matrix in a new figure window.

Expand All @@ -2389,21 +2389,34 @@ def matshow(A, fignum=None, **kw):

Tick labels for the xaxis are placed on top.

With the exception of *fignum*, keyword arguments are passed to
:func:`~matplotlib.pyplot.imshow`. You may set the *origin*
kwarg to "lower" if you want the first row in the array to be
at the bottom instead of the top.
Parameters
----------
A : array-like(M, N)
The matrix to be displayed.

fignum : None or int or False
If *None*, create a new figure window with automatic numbering.

If *fignum* is an integer, draw into the figure with the given number
(create it if it does not exist).

If 0 or *False*, use the current axes if it exists instead of creating
a new figure.

.. note::

Because of how `.Axes.matshow` tries to set the figure aspect
ratio to be the one of the array, strange things may happen if you
reuse an existing figure.

*fignum*: [ None | integer | False ]
By default, :func:`matshow` creates a new figure window with
automatic numbering. If *fignum* is given as an integer, the
created figure will use this figure number. Because of how
:func:`matshow` tries to set the figure aspect ratio to be the
one of the array, if you provide the number of an already
existing figure, strange things may happen.
Returns
-------
image : `~matplotlib.image.AxesImage`

Other Parameters
----------------
**kwargs : `~matplotlib.axes.Axes.imshow` arguments

If *fignum* is *False* or 0, a new figure window will **NOT** be created.
"""
A = np.asanyarray(A)
if fignum is False or fignum is 0:
Expand All @@ -2413,7 +2426,7 @@ def matshow(A, fignum=None, **kw):
fig = figure(fignum, figsize=figaspect(A))
ax = fig.add_axes([0.15, 0.09, 0.775, 0.775])

im = ax.matshow(A, **kw)
im = ax.matshow(A, **kwargs)
sci(im)

return im
Expand Down