Skip to content

Singular keyword arguments in contour don't raise exceptions #1963

Closed

Description

@astrofrog

I have confused myself several times (and have seen it happen many times with other people) by something like this not working, but also not raising a warning or exception:

plt.contour(image, color='green', linestyle='dotted')

The fact that the keywords are not plural in this case is quite pedantic, but the real issue is that there are not even any warnings or errors, so users are left having no idea why this doesn't work, and are left frustrated when they do find out.

So I would suggest either:

  • raise an exception for non-used keyword arguments (not ideal because it still makes it very pedantic)
  • emit a warning and fix the keyword to the plural version
  • simply accept the singular keywords and just pass them to the plural ones, raising an error if the plural one is defined too.

Activity

  1. dmcdougall commented on Jun 16, 2013

    @dmcdougall
    Member

    Note that, whatever solution is implemented, we'd have to do this for all the plotting routines that take plural kwargs.

  2. added this to the milestone on Aug 17, 2014
  3. petehuang commented on Dec 30, 2016

    @petehuang
    Contributor

    Consistency concern is valid for more than just contour, see the api doc for pyplot http://matplotlib.org/api/pyplot_api.html

    • For color: color and c, color
    • For linestyle: linestyles or linestyle or ls or linestyle or linestyles or dashes
    • For linewidth: linewidths or linewidth or lw or linewidth or linewidths or lw
    • For edgecolor: edgecolor or ec or edgecolor or edgecolors
    • For faceolor: facecolor or fc or facecolor or facecolors

    and others, I'm sure

    Will require deciding combinations to keep and applying consistently across all. The easiest would be to just take the union of all the currently valid variants across methods for a particular keyword (e.g., edgecolor or edgecolors or ec).

    I recommend labeling with Difficulty: Medium and Documentation

  4. modified the milestones: , on Oct 3, 2017
  5. QuLogic commented on Apr 22, 2020

    @QuLogic
    Member

    See also #2369 for thoughts on what to do with extra (though not typo'd) keyword arguments.

  6. github-actions commented on Sep 1, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  7. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Sep 1, 2023
  8. jklymak commented on Sep 1, 2023

    @jklymak
    Member

    I think this is still a valid concern. Probably requires some discussion, however I'd be in favour of aliasing these

  9. anntzer commented on Sep 1, 2023

    @anntzer
    Contributor

    Now that ContourSet has been modified to actually be an artist, we should just route most kwargs to Artist.set() and let that handle standard aliases and error out as usual on unknown properties.

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

    API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …keepItems to be ignored by the “Stale” Github Actiontopic: contour

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions