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

3
  • Does this answer your question? scipy: savefig without frames, axes, only content Commented Nov 19, 2020 at 22:00
  • Would you like to store the annotation on the image, or as metadata? Commented Nov 19, 2020 at 22:15
  • The annotation on the image. Commented Nov 20, 2020 at 18:00

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.