MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / matshow

Function matshow

lib/matplotlib/pyplot.py:2773–2831  ·  view source on GitHub ↗

Display a 2D array as a matrix in a new figure window. The origin is set at the upper left hand corner. The indexing is ``(row, column)`` so that the first index runs vertically and the second index runs horizontally in the figure: .. code-block:: none A[0, 0] ⋯ A[0

(A: ArrayLike, fignum: None | int = None, **kwargs)

Source from the content-addressed store, hash-verified

2771
2772
2773def matshow(A: ArrayLike, fignum: None | int = None, **kwargs) -> AxesImage:
2774 """
2775 Display a 2D array as a matrix in a new figure window.
2776
2777 The origin is set at the upper left hand corner.
2778 The indexing is ``(row, column)`` so that the first index runs vertically
2779 and the second index runs horizontally in the figure:
2780
2781 .. code-block:: none
2782
2783 A[0, 0] ⋯ A[0, M-1]
2784 ⋮ ⋮
2785 A[N-1, 0] ⋯ A[N-1, M-1]
2786
2787 The aspect ratio of the figure window is that of the array,
2788 unless this would make an excessively short or narrow figure.
2789
2790 Tick labels for the xaxis are placed on top.
2791
2792 Parameters
2793 ----------
2794 A : 2D array-like
2795 The matrix to be displayed.
2796
2797 fignum : None or int
2798 If *None*, create a new, appropriately sized figure window.
2799
2800 If 0, use the current Axes (creating one if there is none, without ever
2801 adjusting the figure size).
2802
2803 Otherwise, create a new Axes on the figure with the given number
2804 (creating it at the appropriate size if it does not exist, but not
2805 adjusting the figure size otherwise). Note that this will be drawn on
2806 top of any preexisting Axes on the figure.
2807
2808 Returns
2809 -------
2810 `~matplotlib.image.AxesImage`
2811
2812 Other Parameters
2813 ----------------
2814 **kwargs : `~matplotlib.axes.Axes.imshow` arguments
2815
2816 """
2817 A = np.asanyarray(A)
2818 if fignum == 0:
2819 ax = gca()
2820 else:
2821 if fignum is not None and fignum_exists(fignum):
2822 # Do not try to set a figure size.
2823 figsize = None
2824 else:
2825 # Extract actual aspect ratio of array and make appropriately sized figure.
2826 figsize = figaspect(A)
2827 fig = figure(fignum, figsize=figsize)
2828 ax = fig.add_axes((0.15, 0.09, 0.775, 0.775))
2829 im = ax.matshow(A, **kwargs)
2830 sci(im)

Callers

nothing calls this directly

Calls 7

figaspectFunction · 0.90
gcaFunction · 0.85
fignum_existsFunction · 0.85
figureFunction · 0.85
sciFunction · 0.85
add_axesMethod · 0.80
matshowMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…