Skip to content

[Bug]: ax.text() Is Not Rendered If X Specified With ax.plot() #25127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Matthew1471 opened this issue Feb 1, 2023 · 6 comments
Closed

[Bug]: ax.text() Is Not Rendered If X Specified With ax.plot() #25127

Matthew1471 opened this issue Feb 1, 2023 · 6 comments
Labels
Community support Users in need of help.

Comments

@Matthew1471
Copy link

Matthew1471 commented Feb 1, 2023

Bug summary

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-interfaces

import matplotlib.pyplot as plt

fig = 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.

Operating system

Windows

Matplotlib Version

3.6.3

Matplotlib Backend

TkAgg

Python version

3.9.7

Jupyter version

N/A

Installation

pip

@Matthew1471 Matthew1471 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() Feb 1, 2023
@jklymak
Copy link
Member

jklymak commented 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!

@jklymak jklymak closed this as not planned Won't fix, can't repro, duplicate, stale Feb 2, 2023
@jklymak jklymak added the Community support Users in need of help. label Feb 2, 2023
@Matthew1471
Copy link
Author

Matthew1471 commented 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
Copy link
Member

timhoffm commented Feb 2, 2023

text doesn't change the ylim of the axes.

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
Copy link
Member

story645 commented Feb 2, 2023

Should we have an optional keyword argument that does relim?

+1 cause like ax.text can also be used to plot word scatters

@jklymak
Copy link
Member

jklymak commented 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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community support Users in need of help.
Projects
None yet
Development

No branches or pull requests

5 participants