plt.imshow() expects integers.

However, I noticed that even though two arrays of integers can look identical, they might have different types of integers.

In my case, when looking at integer type in the "right" array (i.e. the one where the colors display properly) I got: class 'numpy.uint8'

Whereas when looking at integer type in the array where the colors are inverted in plt.imshow() I got: class 'numpy.int64'

All I needed to do was to convert the array values to uint8:

image = image.astype(np.uint8)

Answer from Alexis Saint-Jean on Stack Overflow
🌐
GitHub
github.com › matplotlib › matplotlib › issues › 14293
imshow() producing "inverted" colors since 3.0.3 · Issue #14293 · matplotlib/matplotlib
May 21, 2019 - Bug report Bug summary Since 3.0.3 imshow() produces "inverted" colors, instead of just including the image as is. Code for reproduction from PIL import Image import matplotlib.pyplot as plt img = Image.open("map.png") plt.imshow(img) pl...
Author: matplotlib
Discussions

python - Reverse colormap in matplotlib - Stack Overflow
I would like to know how to simply reverse the color order of a given colormap in order to use it with plot_surface. More on stackoverflow.com
🌐 stackoverflow.com
How to invert an plot
Hello, I am beginner in using python for analysis. I am trying to get a plot of my results[3D Data]. I used Pyclesperanto for my analysis. When i try to visualize color map using the following code the the resulted plot is bottom to top of my data as shown in the picture. cle.imshow(distance_map, ... More on forum.image.sc
🌐 forum.image.sc
1
0
August 19, 2022
python - Invert colors when plotting a PNG file using matplotlib - Stack Overflow
For more details see this: ...v-use-bgr-color-format: 2020-02-18T06:07:36.337Z+00:00 ... @Kaaf thanks for the link. I knew that BGR was used by Windows, but that wasn't until the '80's. I still don't have a single example of it being used before then. 2020-02-18T13:32:57.41Z+00:00 ... As others have pointed out, the problem is that numpy arrays are in BGR format, but matplotlib expects the arrays to be ordered in a different way. ... Alternatively, you can use scipy.misc.imshow(... More on stackoverflow.com
🌐 stackoverflow.com
April 25, 2014
matplotlib - imshow inverts colors after using astype(float) - Stack Overflow
I'm using matplotlib imshow to visualize data from cifar-10. After reading in cifar10 data I've noticed that the image rendered from imshow is different after I use .astype(float). For example, More on stackoverflow.com
🌐 stackoverflow.com
September 28, 2017
🌐
Iditect
iditect.com › faq › python › invert-image-displayed-by-imshow-in-matplotlib.html
Invert image displayed by imshow in matplotlib
To invert the colors of an image displayed by imshow in matplotlib, you can use the cmap parameter to specify a colormap that inverts the color values. One commonly used colormap for inverting colors is the 'gray_r' colormap, which is the reverse grayscale colormap.
🌐
Image.sc
forum.image.sc › usage & issues
How to invert an plot - Usage & Issues - Image.sc Forum
August 19, 2022 - Hello, I am beginner in using python for analysis. I am trying to get a plot of my results[3D Data]. I used Pyclesperanto for my analysis. When i try to visualize color map using the following code the the resulted plot is bottom to top of my data as shown in the picture. cle.imshow(distance_map, ...
🌐
Stack Overflow
stackoverflow.com › questions › 35420749 › imshow-inverts-colors-after-using-astypefloat
matplotlib - imshow inverts colors after using astype(float) - Stack Overflow
September 28, 2017 - dir = 'resources/datasets/cifar-10-batches-py' import cPickle fo = open(dir + '/data_batch_1', 'rb') dict = cPickle.load(fo) fo.close() X=dict['data'].reshape((10000, 3, 32, 32)).transpose(0, 2, 3, 1).astype(float) Y=dict['labels'] plt.imshow(X[2,]) plt.show() ... A good explanation of how matplotlib decides on the colormap is given in this post.
Find elsewhere
🌐
Reddit
reddit.com › r/opencv › [question] why is the image displayed colors appear inverted?
r/opencv on Reddit: [Question] why is the image displayed colors appear inverted?
March 26, 2024 -

I am starting to get into computer vision, I installed opencv and matplotlib to test, but when I try to see the images, the images appear as if the colors are inverted, but the only thing I do is to read and display the image.

Try several things like: img = cv.imread(image_four, cv.IMREAD_COLOR) or img = cv.cvtColor(img, cv.COLOR_BGR2RGB) but the colors are still displayed wrong

I am using windows 11 and python 3.11

🌐
YouTube
youtube.com › watch
invert image displayed by imshow in matplotlib - YouTube
Get Free GPT4.1 from https://codegive.com/83d6878Okay, let's dive into how to invert the colors of an image displayed using `imshow` in Matplotlib, along wit...
Published: June 18, 2025
🌐
GitHub
gist.github.com › stefanv › 4146612
Reverse colormap · GitHub
Reverse colormap. GitHub Gist: instantly share code, notes, and snippets.
🌐
Matplotlib
discourse.matplotlib.org › community › matplotlib-users
reverse axis on colorbar, and showing under- and over-colors - matplotlib-users - Matplotlib
October 26, 2010 - Hi, My searching for reverse in the documentation and gallery came up empty, so I'll try it here: I have an image with cloud pressures, 1000 at the surface, 200 at the top of the atmosphere. I'd like to reverse the axis, i.e. 1000 at the bottom of the scale, 200 at the top.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-reverse-a-colormap-using-matplotlib-in-python
How to reverse a Colormap using Matplotlib in Python? - GeeksforGeeks
December 14, 2021 - Matplotlib has many built-in Colormaps. Colormaps are nothing but the dictionary which maps the integer data/numbers into colors. Colormaps are used to differentiate or distinguish the data in a particular plot.
🌐
Skytowner
skytowner.com › explore › inverting_color_maps_in_matplotlib
Inverting color maps in Matplotlib
To invert a color map in Matplotlib, attach the _r suffix to the color map.
🌐
Delft Stack
delftstack.com › home › howto › matplotlib › reverse colormap python
How to Create Reverse Colormap in Python Matplotlib | Delft Stack
February 2, 2024 - We can reverse a colormap by adding _r at the end of the colormap’s name in Matplotlib.
🌐
Matplotlib
discourse.matplotlib.org › community › matplotlib-users
Dark or inverted color scheme - matplotlib-users - Matplotlib
May 25, 2012 - Is there a simple way to essentially invert the default plotting color scheme so that the figure background is black and all text, ticks, axes, axis labels, etc are white? I think what I want is to redefine the RGB definitions of the standard color values 'b', 'y', 'k', etc so that I can make ...
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-reverse-the-colormap-of-an-image-to-scalar-values-in-matplotib
How to reverse the colormap of an image to scalar values in Matplotib?
March 25, 2026 - You can also reverse colormaps using the suffix '_r' ? import matplotlib.pyplot as plt import numpy as np # Create sample data data = np.random.rand(10, 10) # Method 1: Using .reversed() plt.subplot(1, 2, 1) plt.imshow(data, cmap=plt.cm.viridis.reversed()) plt.title("Using .reversed()") plt.colorbar() # Method 2: Using '_r' suffix plt.subplot(1, 2, 2) plt.imshow(data, cmap='viridis_r') plt.title("Using '_r' suffix") plt.colorbar() plt.tight_layout() plt.show()
🌐
GitHub
github.com › matplotlib › matplotlib › issues › 22052
[Bug]: invert_yaxis function cannot invert the "over value" in colorbar axes · Issue #22052 · matplotlib/matplotlib
December 24, 2021 - The "over value" and the "under value" of colormap are not correctly shown when using ax.invert_yaxis (invert_xaxis if the colorbar is horizontal) function. import numpy as np import matplotlib.pyplot as plt im=plt.imshow(np.arange(10000).reshape(100,100),vmax=9000,vmin=1000) cb=plt.colorbar(im,extend='both') cb.ax.invert_yaxis() The "over value" and the "under value" could be shown in the right location by the way.