ax.text() is not rendered if x values are supplied to ax.plot()
Code for reproduction
# Straight from the example : https://matplotlib.org/stable/users/explain/api_interfaces.html#api-interfacesimportmatplotlib.pyplotaspltfig=plt.figure()
ax=fig.subplots()
# Text works!#ax.plot([0, 0.5, 1, 0.2])# Text no works!ax.plot([1, 2, 3, 4], [0, 0.5, 1, 0.2])
# Text drawing.ax.text(0, 0, 'Hello!')
plt.show()
Actual outcome
Text is not displayed.
Expected outcome
Text is displayed.
Additional information
I narrowed it down to plot with x values means text is not displayed.
changed the title [-][Bug]: Text Does Not Draw If X Specified With Plot[/-][+][Bug]: ax.text() Is Not Rendered If X Specified With ax.plot()[/+]on Feb 1, 2023
text doesn't change the ylim of the axes like plot does, so it is there, just off the axes. This is expected behaviour. If you want it to show up then ax.set_ylim(0, 1.2). Further discussion can be had at https://discourse.matplotlib.org. Thanks!
ax.set_ylim(0, 1.2) does not cause the text to show either.
Oh I see that ax.set_xlim(1, 4) does when text is set to ax.text(1, 0, 'Hello!') as the values are in reference to the data's actual values not as in 0 is the co-ordinate of the first pixel near the data value (missed that bit of the manual).
Should we have an optional keyword argument that does relim? It seems handy in some cases. Not only is manual limit setting by the user cumbersome and error-prone, it also deactivates future auto-scaling, which may not be desired.
If you want to put text relative to a point, see ax.annotate.
We have been through the discussion about if text is "data" or "decoration" a couple of times and in the past have come down on the "decoration" side of things which says we should not take text into account in the auto-limit code. I will make a new issue with thoughts on how to make this happen.
Activity
jklymak commented on Feb 2, 2023
text doesn't change the ylim of the axes like plot does, so it is there, just off the axes. This is expected behaviour. If you want it to show up then ax.set_ylim(0, 1.2). Further discussion can be had at https://discourse.matplotlib.org. Thanks!
Matthew1471 commented on Feb 2, 2023
ax.set_ylim(0, 1.2) does not cause the text to show either.
Oh I see that ax.set_xlim(1, 4) does when text is set to ax.text(1, 0, 'Hello!') as the values are in reference to the data's actual values not as in 0 is the co-ordinate of the first pixel near the data value (missed that bit of the manual).
Thank you for your help.
timhoffm commented on Feb 2, 2023
Should we have an optional keyword argument that does relim? It seems handy in some cases. Not only is manual limit setting by the user cumbersome and error-prone, it also deactivates future auto-scaling, which may not be desired.
story645 commented on Feb 2, 2023
+1 cause like ax.text can also be used to plot word scatters
jklymak commented on Feb 2, 2023
You could autolim on the text anchor, but cannot autolim on the text extent without getting stuck in loops like we did for scatter fixed-size markers.
tacaswell commented on Feb 2, 2023
If you want to put text relative to a point, see ax.annotate.
We have been through the discussion about if text is "data" or "decoration" a couple of times and in the past have come down on the "decoration" side of things which says we should not take text into account in the auto-limit code. I will make a new issue with thoughts on how to make this happen.