Problem when adding text without any plot


I don’t know if this can be considered as a bug, the behaviour is not wrong but maybe can be improved. If I want to plot a marker and a text on top of it:

xxx = -250.
yyy = 20.
fig, ax = plt.subplots()
ax.plot(xxx, yyy, "r*")
ax.text(xxx, yyy, "red star")

this works, but now let’s say I want to only add the text at the same location,

fig, ax = plt.subplots()
ax.text(xxx, yyy, "I'm here")

this won’t work because the created figure will be too large.

ValueError: Image size of 84055x4388 pixels is too large. It must be less than 2^16 in each direction.`

Maybe the ax limits could be determined as if there were a marker at the location of the text?

That will only happen if you use bbox_inches='tight' or the inline backend (which uses bbox_inches='tight'. For most backends, the text is just off the page. We do not relimit when text is added, and while it is suggested from time to time due to issues like this, the overall consensus has been to not do so.

FWIW, I think the real bug here is the decision by ipython to use bbox_inches='tight' by default in the inline backend. But that has been around so long I doubt we will get that changed either.

1 Like

Thanks a lot, that really makes sense.