0

I have loaded an image, converted it to an array and annotated it (56.01). Now I want to save it back as an image. How can I do that?

With this code, the image is annotated. But I want to remove the axes and save it as an image.

from matplotlib import image
import matplotlib.pyplot as plt


ax=plt.gca()

# load image as pixel array
data = image.imread('yellow.jpg')

ax.annotate('56.05',xy=(1000, 500), xycoords='data')


# display the array of pixels as an image
plt.imshow(data)
plt.savefig('imagenet1.png', bbox_inches='tight', dpi = 1000)
plt.show()

ANNOTATED ARRAY

enter image description here

I WANT THIS, BUT THE ANNOTATION IS NOT HERE enter image description here

Aizzaac
  • 3,146
  • 8
  • 29
  • 61

1 Answers1

1

You want to annotate after calling imshow, and hide the x and y axes. Alternatively you could plot things in whatever order you want as long as you provided them with a logical zorder parameter.

from matplotlib import image
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

# load image as pixel array
data = image.imread('yellow.jpg')

# display the array of pixels as an image
ax.imshow(data)
ax.annotate('56.05', xy=(1000, 500), xycoords='data')
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
fig.savefig('imagenet1.png', bbox_inches='tight', dpi=1000)
fig.show()
Guimoute
  • 4,407
  • 3
  • 12
  • 28