Mis a jour le 2024-03-17, 13:3

Images

Lecture d'une image :
Pour sauvegarder une image avec matplotlib, avec seulement l'image :
pyplot.figure(figsize = (im.shape[1] / pyplot.rcParams['savefig.dpi'], im.shape[0] / pyplot.rcParams['savefig.dpi']))
pyplot.axis('off')
pyplot.gcf().subplots_adjust(left = 0, bottom = 0, right = 1, top = 1, wspace = 0, hspace = 0)
pyplot.imshow(im)
pyplot.savefig('myImage.png')
  
attention : il faut donner les dimensions dans l'ordre inverse (largeur = nombre de colonnes, puis hauteur = nombre de lignes d'où le im.shape[1] puis im.shape[0]).
Pour positionner une image dans un rectangle de taille donnée à une position donnée :
pyplot.axis('off')
pyplot.xlim(0, 1) # pour indiquer les dimensions
pyplot.ylim(0, 1) # pour indiquer les dimensions
pyplot.imshow(im, extent = [0, 0.2, 0.6, 0.8]) # xmin, xmax, ymin, ymax
  

Copyright python-simple.com
programmer en python, tutoriel python, graphes en python, Aymeric Duclert