Use plt.imshow to create the figure, and plt.show to display it:

from matplotlib import pyplot as plt
plt.imshow(data, interpolation='nearest')
plt.show()

For Jupyter notebooks, add this line before importing matplotlib:

%matplotlib inline 

For interactive plots in Jupyter [demo], install ipyml pip install ipympl, then use:

%matplotlib widget 
Answer from Steve Tjoa on Stack Overflow
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-109.php
Python NumPy: Convert a numpy array to an image - w3resource
August 29, 2025 - Create a function that saves a NumPy array as an image file using PIL, then reloads it to verify integrity.
Discussions

Converting between PIL Image and 2d pixel array?
Are you trying to translate a image into ascii art? More on reddit.com
🌐 r/learnpython
5
3
May 11, 2022
How to convert RGB array to image?
After reading your comments, Quoted from this comment Nevermind, i fixed the code with chatgtp: *ChatGPT, also see rule #5 Then this comment im using it anyways because it works https://imgur.com/a/42M2LbK Finally this comment How would that produce the image I want? Just run it first? I've already solved it with chatGTP. *ChatGPT, a crappy solution Your solution doesn't make any sense Your manner is bad (you don't even try it or thank u/Strict-Simple ). More on reddit.com
🌐 r/learnpython
16
0
May 6, 2023
Numpy array to image data
so I have a 2d numpy array of float values that I am trying to “convert” to an image data block so it can be used for example in a material. pseudo code import numpy as np import bpy array = np.array((1, 2, 3), (4, 5, … More on blenderartists.org
🌐 blenderartists.org
1
0
February 8, 2024
How to convert array to image in python? - Stack Overflow
For each word , i will have one or more arrays. ... And i want to save the images for each key in the dictionary. ... What error do you get (or not)? What shape is i? I would use matplotlib's imshow function for this. In Python almost all libraries use numpy arrays to represent images - you ... More on stackoverflow.com
🌐 stackoverflow.com
February 26, 2019
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-a-numpy-array-to-an-image
Convert a NumPy array to an image - GeeksforGeeks
July 15, 2025 - The Image.fromarray() function is used for this task, which takes a NumPy array as input and creates a PIL Image object. This allows the array to be manipulated as a standard image, making it suitable for tasks like displaying, saving or further ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-images-to-numpy-array
How to Convert images to NumPy array? - GeeksforGeeks
July 15, 2025 - The code then prints the image’s type, format (PNG), color mode (RGB) and dimensions (width, height). Example 2: In this example, we use the Keras API functions img_to_array() and array_to_img() to convert a PIL image to a NumPy array and then convert it back to an image.
🌐
scikit-image
scikit-image.org › skimage-tutorials › lectures › 00_images_are_arrays.html
Images are numpy arrays — Image analysis in Python
Images are represented in scikit-image using standard numpy arrays. This allows maximum inter-operability with other libraries in the scientific Python ecosystem, such as matplotlib and scipy. Let’s see how to build a grayscale image as a 2D array:
🌐
Delft Stack
delftstack.com › "delft stack" › "howto" › "python numpy howtos" › "how to save numpy array as image in python"
How to Save NumPy Array as Image in Python | Delft Stack
February 2, 2024 - It is part of the imageio library, which is a popular Python library for reading and writing images in multiple formats. ... uri: This is the file path or URI where the image file will be saved. It should include the file extension to specify the desired image format (e.g., output.png). im: The image data that you want to save. This can be a NumPy array or any other image data format supported by imageio.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › convert-a-numpy-array-to-an-image
Convert a NumPy array to an image
August 9, 2023 - Image is the module. fromarray is the function used to convert the array into image.
🌐
Saturn Cloud
saturncloud.io › blog › converting-numpy-arrays-to-images-using-cv2-and-pil
Converting Numpy Arrays to Images using CV2 and PIL | Saturn Cloud Blog
May 1, 2026 - We then fill the left half of the array with orange and the right half with blue. Finally, we use cv2.imwrite() to save the array as an image. The Python Imaging Library (PIL) is another powerful library for opening, manipulating, and saving many different image file formats.
🌐
Medium
medium.com › @whyamit101 › step-by-step-guide-to-convert-numpy-array-to-pil-image-f7f8492cd785
Step-by-Step Guide to Convert NumPy Array to PIL Image | by why amit | Medium
February 9, 2025 - The shape of the array is (100, 100), meaning it’s a 100x100 pixel image. No RGB channels—just simple brightness values. ... Now comes the exciting part. We’ll use Image.fromarray() again, but with a small twist—this time, we’ll specify the mode as 'L'. The 'L' mode tells PIL to treat the image as grayscale.
🌐
Guiwitz
guiwitz.github.io › PyImageCourse_beginner › 02-Images_as_arrays.html
2. Images as arrays — Image processing with Python for beginners
Now we need to make sure that we create a noise-image that has the correct dimensions. Those are: ... You can essentially use all common mathematical operations with arrays of same size. The last important topic concerns logical operations such as \(a > 3\). In basic Python we can use these kind of statements:
🌐
Delft Stack
delftstack.com › "delft stack" › "howto" › "python matplotlib howto's" › "how to convert a numpy array to pil image in python"
How to Convert a NumPy Array to PIL Image in Python | Delft Stack
March 13, 2025 - This tutorial explains how to convert a NumPy array to a PIL image using the Image.fromarray() function from the PIL package. Learn step-by-step methods for handling both RGB and grayscale images, and discover how to customize image properties ...
🌐
Reddit
reddit.com › r/learnpython › converting between pil image and 2d pixel array?
r/learnpython on Reddit: Converting between PIL Image and 2d pixel array?
May 11, 2022 -

I need to do the following:

  1. Import an image.

  2. Convert image to a 2D array of pixel values (rgb tuples, bytes, whatever it doesn't matter).

  3. Manipulate that 2D array (needs to be 2D as I'm using a library that requires a 2D array of data).

  4. Convert the newly changed 2D array back into an image.

  5. Save the image.

Anyone know how I can accomplish this? PIL Image documentation has some functions to get data but it's all 1D arrays, and I'm not sure how to get them into 2D arrays and then re-convert it back into an image again.

🌐
Reddit
reddit.com › r/learnpython › how to convert rgb array to image?
r/learnpython on Reddit: How to convert RGB array to image?
May 6, 2023 -

So I tried to convert a raw RGB array to an image with this simple code:

import numpy as np

from PIL import Image

Canvas = np.array([[255, 0, 0], [0, 255, 0], [0, 0, 0], [0, 0, 0]])

img = Image.fromarray(Canvas, 'RGB')

img = img.save("canvas.png")

I have no idea how to set the size of the image as a resolution of 2x2 because this code does not create the correct resolution

The first pixel in Canvas should be red, second pixel should be green, the third and fourth pixels should be black

All I want is a 2x2 resolution image where the top-left pixel is red and the top-right pixel is green, then both bottom pixels should be black, but my code is just producing the wrong image resolution with the wrong pixel locations. What is the issue?

🌐
Blender Artists
blenderartists.org › technical support › python support
Numpy array to image data - Python Support - Blender Artists Community
February 8, 2024 - so I have a 2d numpy array of float ... 8, 9)) img = bpy.data.images.new(name=“myimg”, width=array.shape[0], height=array.shape[1]) pixels = np.zeros(array.shape[0] * array.shape[1] * 4, dtype=“float32”) for i in range(len(array.shape[0])): for j in range(len(array.shape[1])): value = array[i, j] ...
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to convert python numpy array to image
5 Best Ways to Convert Python NumPy Array to Image - Be on the Right Side of Change
February 20, 2024 - PIL (Python Imaging Library) and its fork Pillow are widely used for opening, manipulating, and saving many different image file formats. The Image.fromarray() function converts a NumPy array to a PIL image object, which can then be saved to a file.
🌐
Pythoninformer
pythoninformer.com › python-libraries › numpy › numpy-and-images
PythonInformer - Image processing with pillow and NumPy
October 2, 2022 - Now let's fill the array with orange pixels (red=255, green=128, blue=0). We use slices to do this, the three values are broadcast across all the rows and columns of the array: ... The PIL function Image.fromarray function creates a PIL image from a NumPy array.
🌐
Medium
asofficial14786.medium.com › create-a-image-by-using-numpy-arrays-and-matplotlib-fdada4732b66
Create a Image by using Numpy ,Arrays and Matplotlib | by Ankit Shukla | Medium
July 31, 2023 - Here's a simple example to create a black square image: import numpy as np import matplotlib.pyplot as plt #----Image Creation----# # Set Image size ie. (height and width in pixels) image_height = 200 image_width = 200 # Creating a black image using a NumPy array my_image = np.zeros((image_height, image_width, 3), dtype=np.uint8) # Show the black image using matplotlib plt.imshow(my_image) plt.axis('off') # It helps when Turn off axes to remove the axis ticks and labels plt.show()
🌐
Stack Overflow
stackoverflow.com › questions › 54873038 › how-to-convert-array-to-image-in-python
How to convert array to image in python? - Stack Overflow
February 26, 2019 - For each word , i will have one or more arrays. ... And i want to save the images for each key in the dictionary. ... What error do you get (or not)? What shape is i? I would use matplotlib's imshow function for this. In Python almost all libraries use numpy arrays to represent images - you do not need to "convert" them as such.