0

I want to use the output of imshow + savefig from Python pyplot in a HTML canvas to plot on defined positions of the image (a spectrogram). For this I need to know the exact pixel position of the lower left and upper right of the imshow area inside the exported png file:

fig = plt.figure(figsize=(12,8))
...
plt.imshow(y,origin='lower',aspect='auto',cmap='YlOrRd')
...
fig.tight_layout()
...
fig.savefig('myimg.png') 

enter image description here

Is this even possible and if yes, how?

1 Answer 1

1

You can get the points by:

locs = fig.transFigure.transform(plt.gca().get_position().get_points()).
print(locs)

(The origin will be the lower left corner of the figure.)

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.