Skip to content

[ENH]: Improve rememberability of position rectangles wrt. start-end vs. start-delta #22515

Open
@anntzer

Description

@anntzer

Problem

It is always a bit hard for me to remember whether add_axes takes (left, bottom, right, top) or (left, bottom, width, height) (especially because needing to manually place axes is not so common -- but sometimes you do need it). Perhaps a solution would be to support both, or possibly some additional APIs, based on keyword (not all of them may be worth adding, I'm just trying to be exhaustive):

fig.add_axes([l, b, w, h])  # current API
fig.add_axes(rect=[l, b, w, h])  # current API
# add some simple aliases
fig.add_axes(lbwh=[l, b, w, h])
fig.add_axes(xxyy=[x0, x1, y0, y1])
fig.add_axes(xyxy=[x0, y0, x1, y1])
fig.add_axes(corners=[(x0, y0), (x1, y1)])  # cf. discussion on grouping arguments to vector().

(Note that all these can probably be implemented "relatively" easily via setters, i.e. default of rect=None, pass the kwargs to the setters, and at the end of of __init__, check that one of the position-specifying args has been passed.)

Alternatively, add_axes also supports taking a Bbox, so one can write

fig.add_axes(Bbox([(x0, y0), (x1, y1)]))  # Perhaps that's the most rememberable for me...
fig.add_axes(Bbox.from_extents(x0, y0, x1, y1))
fig.add_axes(Bbox.from_bounds(x0, y0, w, h))

but note that the name bounds ("start-delta") is not consistent with Axes.set_xbound/Axes.set_ybound (and the more rarely used Spine.set_bounds), which both use the "start-end" convention :(

Proposed solution

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions