Skip to content

contour ignores lw argument, no warning/error #13848

Open

Description

@lzkelley

Bug report

The command contour does not use lw arguments (unlike, e.g., plot), and does not report an error or warning. The linewidths argument works fine. A simple fix is to explicitly look for lw arguments and set linewidths to that. Happy to put in a PR for this, but I wanted to check first.

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
print(mpl.__version__)

fig, axes = plt.subplots(ncols=3)

for ax, lw, arg in zip(axes, [1.0, 4.0, 4.0], ['lw', 'lw', 'linewidths']):
    aa = np.random.normal(size=1000)
    bb = np.random.normal(size=aa.size)
    hist, xe, ye = np.histogram2d(aa, bb)
    kw = {arg: lw}
    ax.contour(hist, **kw)
    ax.set_title('{}: {}'.format(arg, lw))

plt.show()

Actual outcome

mpl

Matplotlib version

  • Matplotlib version: 3.0.2

Activity

  1. timhoffm commented on Apr 2, 2019

    @timhoffm
    Member

    Current master has a warning UserWarning: The following kwargs were not used by contour: 'lw'.

    That's at least good enough to no not surpise the user. I'm unclear if we need/want to take further action.

    Options are:

    • Leave as is.
    • Turn the warning into an error (some later version, maybe deprecate first).
    • Accept lw. But then we need to accept also other Line2D shortnames. And, the current parameter is linewidths but Line2D has linewidth.
  2. added
    API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …
    on Apr 2, 2019
  3. WeatherGod commented on Apr 2, 2019

    @WeatherGod
    Member
  4. timhoffm commented on Apr 2, 2019

    @timhoffm
    Member
  5. efiring commented on Apr 15, 2019

    @efiring
    Member

    I understand and have some sympathy for the consistency argument for allowing abbreviations, but the kwarg names that are accepted now are documented. Given that the master warns if unrecognized kwargs are given, I think that adding kwarg abbreviations for contour (and by extension, all collections) is low priority, if it is even worth the added complexity of code and documentation at all--which I doubt. One could equally argue that having the abbreviations for plot is a mistake, adding unnecessary complexity and violating the 'preferably only one obvious way' idea of Python.

  6. github-actions commented on Nov 3, 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. QuLogic commented on Nov 3, 2023

    @QuLogic
    Member

    This has been warning since #7728, which is from 2017. At this point, I wouldn't be against making it a hard error even.

    However, now ContourSet is derived from Collection, so theoretically, it could start passing any unused keyword arguments down.

  8. github-actions commented on Jun 9, 2025

    @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!

  9. timhoffm commented on Jun 10, 2025

    @timhoffm
    Member

    Not tested, but set() claims to accept lw https://matplotlib.org/stable/api/contour_api.html#matplotlib.contour.QuadContourSet.set
    If it does, it'd be reasonable that the constructor does too.

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, …topic: contour

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions