简体   繁体   中英

How can I display 2d array as image (jpg, png) in Python?

I have

rows, cols = (5, 5)
arr = [[0 for i in range(cols)] for j in range(rows)]

and want to get enter image description here

It would be very convenient if the image had a dynamic resolution for each array.

Additionally, it is not clear what to do if I want a beautiful design - where to store and how to interact with the image template so that it can be dynamically changed and an array placed on it.

enter image description here

Are there any ready-made libraries for my wishes? Or is this not usually done in python at all? Then how to automate it? It just feels like I'm reinventing the bike.

You can try to show images by using matplotlib.

rows, cols = (5, 5)
arr = [[0 for i in range(cols)] for j in range(rows)]

import matplotlib.pyplot as plt
plt.figure()
plt.imshow(arr)
plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM