Skip to content

pyplot.annotate() API deprecation #15142

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
amaeckelberghe opened this issue Aug 27, 2019 · 8 comments
Closed

pyplot.annotate() API deprecation #15142

amaeckelberghe opened this issue Aug 27, 2019 · 8 comments
Labels
Documentation Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Milestone

Comments

@amaeckelberghe
Copy link

amaeckelberghe commented Aug 27, 2019

Bug report

Bug summary

I wanted to update my code that annotates a plot by changed the deprecated keyword argument s to text as described in the documentation of matplotlib v3.1.1. However it fails to recognise text as an argument and requests s instead.

Code for reproduction

import matplotlib
import matplotlib.pyplot as plt


print(matplotlib.__version__)
print(matplotlib.get_backend())
matplotlib.pyplot.plot()
matplotlib.pyplot.annotate('without keyword', xy=(0.5, 0.75))
matplotlib.pyplot.annotate(s='keyword "s"', xy=(0.5, 0.5))
matplotlib.pyplot.annotate(text='keyword "test"', xy=(0.5, 0.25))

Actual outcome

image

3.1.1
TkAgg
Traceback (most recent call last):
  File "<input>", line 9, in <module>
TypeError: annotate() missing 1 required positional argument: 's'

Expected outcome

I would expect that the keyword we should use in version 3.1.1 would be 'text' since in the documentation (https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.annotate.html) it says:

Parameters: text : str The text of the annotation. s is a deprecated synonym for this parameter.

Matplotlib version

  • Operating system: Windows
  • Matplotlib version: 3.1.1
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.7.4

I installed matplotlib through pip

@timhoffm
Copy link
Member

This issue is discussed in #15049.

@ImportanceOfBeingErnest ImportanceOfBeingErnest added this to the v3.1.2 milestone Aug 27, 2019
@ImportanceOfBeingErnest ImportanceOfBeingErnest added Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. Documentation labels Aug 27, 2019
@ImportanceOfBeingErnest
Copy link
Member

Marking as release critical, because the documentation cannot state a parameter text, if that parameter does not exist.

@timhoffm
Copy link
Member

The way forward (two possible solutions) is #15049 (comment).

@tacaswell tacaswell modified the milestones: v3.1.2, v3.3.0 Oct 15, 2019
@tacaswell
Copy link
Member

Pushed to 3.3 as this issue does not break any existing code, but is an inconsistency that we should fix.

We should push out deprecating the s kwarg for at least one extra minor release after we clean this up.

@timhoffm
Copy link
Member

Fixed via the final removal of the deprecation #16491.

Luckily there was no further feedback on the inconsistency in 3.1, so we don't have to be too afraid that this will still be present in 3.2 and only be resolved in 3.3.

@SeaDude
Copy link

SeaDude commented Apr 8, 2020

What is the fix for us end users? Following this tutorial here...

I receive the error...

TypeError                                 Traceback (most recent call last)
<ipython-input-27-165dd014e247> in <module>
      4 
      5 for idx, row in merged.iterrows():
----> 6     plt.annotate(s=row['province'], xy=row['coords'], horizontalalignment='center')

TypeError: annotate() missing 1 required positional argument: 'text'

When attempting to run...

# Add Labels
merged['coords'] = merged['geometry'].apply(lambda x: x.representative_point().coords[:])
merged['coords'] = [coords[0] for coords in merged['coords']]

for idx, row in merged.iterrows():
    plt.annotate(s=row['province'], xy=row['coords'], horizontalalignment='center')

Thank you!

@ksunden
Copy link
Member

ksunden commented Apr 8, 2020

@SeaDude See #15049, which is now merged, and ensures that the proper renaming is propegated (not yet released, but coming)

Alternatively, you can just take out the s=, as that is the first positional argument anyway

@tacaswell
Copy link
Member

What version of Matplotlib are you using?

You can also change plt.annotate to ax.annotate. The random switching between the OO and sate machine APIs in that tutorial is very weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

No branches or pull requests

6 participants