How to change the axis values of a matplotlib imshow() graph in Python

Calling matplotlib.axes._axes.Axes.imshow() returns the image of a graph in the form of a matplotlib.images.AxesImage object. Changing the axis values of these objects results in a different range of values being displayed on the axis of the graph in the image.

Solution for How to change the axis values of a matplotlib imshow() graph in Python : You can use the extent keyword to change the axis values of a matplotlib.imshow() graph Call matplotlib.pyplot.subplots() to get a tuple containing a figure and an axes object.

With the axes returned in the previous step as matplotlib.Axes, call matplotlib.Axes.imshow(hist, extent=values) with hist as the data to plot, and values as a list of data-coordinates in the form [left, right, bottom, top] to plot the data within and set the axis values to.

Call matplotlib.Axes.set_aspect(x) with the previously returned axes as matplotlib.Axes and x as an integer to adjust the image aspect.


how-to-change-the-axis-values-of-a-matplotlib-imshow-graph-in-python