Skip to content

[Bug]: Incorrect type stub for ErrorbarContainer's lines attribute. #28467

@pavyamsiri

Description

@pavyamsiri

Bug summary

The type stub for ErrorbarContainer in lib/matplotlib/container.pyi is incorrect.

image

It is also inconsistent with the online documentation.

image

Code for reproduction

from matplotlib import pyplot as plt


fig = plt.figure()
axis = fig.add_subplot(111)

container = axis.errorbar([0, 1, 2], [-0.5, 0.2, 0.3], yerr=[0.01, 0.02, 0.01])
print(container.lines)
for idx, elem in enumerate(container.lines):
    print(f"Element {idx}: {elem} | Type = {type(elem)}")

plt.show()
plt.close()

Actual outcome

image

Expected outcome

Assuming the type stub is correct:

  1. The first element should be a Line2D which is correct
  2. The second element should be a Line2D which is incorrect as it is actually an empty tuple
  3. The third element should be a LineCollection which is incorrect as it is a tuple containing a single LineCollection.

Additional information

I'm not sure if the type stub was always incorrect or it became incorrect over time however it should be fixed as it causes spurious type checker errors.

Obviously we would need to fix the type stub annotation however I am unsure about the true types as it seems that the return types are dynamic dependent on the input arguments to plt.errorbar.

Operating system

Debian

Matplotlib Version

3.8.4

Matplotlib Backend

QtAgg

Python version

3.12.4

Jupyter version

Not applicable

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy