Skip to content

[pyplot] Restore getter and return-value semantics for limits, ticks, and legend #443

Description

@Alek99

Summary

Several pyplot functions with familiar Matplotlib getter/setter contracts are implemented only as setters returning None. Most seriously, calling plt.xlim() or plt.ylim() with no arguments mutates the axes by freezing the current automatic domain as explicit. The wrappers also document keyword forms they do not accept. Tick getters are absent, and plt.legend() is annotated as returning None while returning a live Legend object.

Audited at 99eda6d.

Current behavior

plt.xlim and plt.ylim accept only *args, always call setters, and return None in python/xy/pyplot/__init__.py. Their docstrings advertise left=/right= forms that the wrappers reject.

With no arguments, Axes.set_xlim() reads the automatic range and writes it back as an explicit domain in python/xy/pyplot/_axes.py. Thus a getter-looking call changes later autoscaling behavior.

plt.xticks() and plt.yticks() also always call their setters and return None in pyplot/__init__.py, instead of returning the current locations and labels when called without arguments.

Finally, plt.legend() is annotated -> None while directly returning gca().legend(...) in pyplot/__init__.py.

Proposed direction

Implement explicit getter and setter branches with overloads, and align the exposed Axes setter return values where the shim claims Matplotlib compatibility. Getter branches must be observational: they cannot add explicit domains, replace locators/formatters, or invalidate the figure.

Acceptance criteria

  • plt.xlim() and plt.ylim() return the current limits without changing autoscale/explicit-domain state.
  • Positional, tuple, and documented keyword setter forms work and return the resulting limits.
  • plt.xticks() and plt.yticks() getter forms return current locations and label handles/objects within the documented compatibility scope without mutating tick state.
  • Tick setter forms retain their existing behavior and return a Matplotlib-compatible result.
  • plt.legend() has the correct return annotation and returns the live legend handle.
  • Reference tests compare getter, setter, return-value, and no-mutation behavior against Matplotlib.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions