Skip to content
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

textcords='axes fraction' does not work for some axes ranges #1311

Closed
tacaswell opened this issue Sep 25, 2012 · 5 comments
Closed

textcords='axes fraction' does not work for some axes ranges #1311

tacaswell opened this issue Sep 25, 2012 · 5 comments

Comments

@tacaswell
Copy link
Member

For some axes ranges, annotations will not be drawn

ax = gca()
ax.set_ylim([0,.3])
ax.annotate('.5',(.1,.5),textcoords='axes fraction' ,weight='bold',fontsize=14 )
ax.annotate('.1',(.1,.1),textcoords='axes fraction' ,weight='bold',fontsize=14 )
draw() # only .1 will show up
ax.set_ylxm([0,3])
draw() # both will show up

May be related to issues #1310 and #403

In [17]: matplotlib.version
Out[17]: '1.2.0rc2'

QT4Agg with PyQT4

edited to add links

@WeatherGod
Copy link
Member

Confirmed... that is really weird.

at ax.set_ylim([0, .4993630573]), is the highest value at which the annotation does not appear (at least, at that many decimal places). I did not bother doing more.

@mdf-github
Copy link

I have a similar issue with the 'axes fraction' and 'figure fraction' when using annotate() in log-log plots. The annotations disappear when the log scales are introduced, but they're fine when using regular scales.

Here's a sample of my code.

plt.clf()
samplevalues = [100,1000,5000,10^4]
ax = plt.subplot(111)
ax.plot(samplevalues,samplevalues,'o',color='black')
ax.annotate('hi',(0.5,0.5), textcoords='axes fraction')
ax.set_xscale('log')
ax.set_yscale('log')
plt.show()

I'm using matplotlib 0.99.3. Commenting out the set_xcale('log') parts will make the annotation appear. Thanks @tacaswell for alerting me to this bug!

@cimarronm
Copy link
Contributor

I don't think the original issue is a bug. The problem with the example code is that the xy cooridantes (not text coordinates) are given but textcoords are specified as axes fraction instead of xycoords. If you specify it as xycoords='axes fraction' then it works as expected and I would argue is the proper functionality.

ax = gca()
ax.set_ylim([0,.3])
ax.annotate('.5',(.1,.5),xycoords='axes fraction' ,weight='bold',fontsize=14 )
ax.annotate('.1',(.1,.1),xycoords='axes fraction' ,weight='bold',fontsize=14 )
draw() # both show up

@cimarronm
Copy link
Contributor

As for the second example, the same holds true, and is not a bug. If you replace with xycoords it shows the intended behavior.

plt.clf()
samplevalues = [100,1000,5000,10^4]
ax = plt.subplot(111)
ax.plot(samplevalues,samplevalues,'o',color='black')
ax.annotate('hi',(0.5,0.5), xycoords='axes fraction')
ax.set_xscale('log')
ax.set_yscale('log')
plt.show()

The main misunderstanding here is that there are two xy points in an annotation: 1) a data point being annotated (xy which xycoords specifies the units) and 2) an optional text coordinates (xytext which textcoords specifies the units).

@tacaswell
Copy link
Member Author

Well, that is embarrassing....

Looking at this again, what is going on in my OP is that the annotation is the equivalent of ax.annotate('.5',xy=(.1,.5), xytext=(1, .5), textcoords='axes fraction' , xycoords='data') which decides that the annotation does not need to get drawn if the point being marked falls outside of the viewing window, which seems like the correct behavior.

There probably should be a warning if the user sets textcoords but not xytext.

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jan 20, 2014
When calling with certain kwarg combinations (no`xytext`, but
with `textcoords`) unexpected, but correct behavior can result.

See matplotlib#1311 ht to @cimarronm for sorting out what was wrong.
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jan 20, 2014
When calling with certain kwarg combinations (no`xytext`, but
with `textcoords`) unexpected, but correct behavior can result.

See matplotlib#1311 ht to @cimarronm for sorting out what was wrong.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants