FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

pyplot.annotate() API deprecation · Issue #15142 · matplotlib/matplotlib · GitHub

pyplot.annotate() API deprecation #15142

Closed

Description

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

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

Activity

  1. timhoffm commented on Aug 27, 2019

    Member

    This issue is discussed in #15049.

  2. ImportanceOfBeingErnest commented on Aug 27, 2019

    Member

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

  3. timhoffm commented on Aug 29, 2019

    Member

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

  4. modified the milestones: v3.1.2, v3.3.0 on Oct 15, 2019
  5. tacaswell commented on Oct 15, 2019

    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.

  6. timhoffm commented on Feb 16, 2020

    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.

  7. SeaDude commented on 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!

  8. ksunden commented on Apr 8, 2020

    Member

    @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

  9. tacaswell commented on Apr 8, 2020

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationRelease criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL