Skip to content

add a ratchet option to dataLim update functions and associated autoscale functions #18431

@ianhi

Description

@ianhi

Problem

I think this was best stated by @mwaskom in #17331 (comment)

What I really want from explicit limits / autoscaling is something closer to a ratchet: I want to set limits that won't hide to-be-added data that lie outside of the limits but will also not contract when to-be-added data lie inside the limits (minus the margin).

I am regularly running into this when making interactive plots. Trying to mix plot elements that may update with others that may not and some artists work with ax.relim while others do not. So it would be awesome if in addition to ratcheting behavior for set_{x,y}lim it was also implemented for the bbox dataLim updating methods.

Proposed Solution

add ratchet_x and ratchet_y options to:
ax.relim
ax.autoscale_view
and the bbox updating methods:

def update_from_data_xy(self, xy, ignore=None, updatex=True, updatey=True):

def update_from_path(self, path, ignore=None, updatex=True, updatey=True):

void update_path_extents(PathIterator &path, agg::trans_affine &trans, extent_limits &extents)

inline void update_limits(double x, double y, extent_limits &e)

I think the only place where the logic would actually need to be changed is in the update_limits function
and ratchet options to
ax.set_xlim
ax.set_ylim

Additional context and prior art

A user can get this behavior in python by themselves like this:

cur_ylims = ax.get_ylim()
ax.relim()
new_lims = [ax.dataLim.y0, ax.dataLim.y0+ax.dataLim.height]
ax.set_ylim(min(new_lims[0], cur_ylims[0]), max(new_lims[1], cur_ylims[1]))
ax.set_ylim(new_lims)

but this is likely less performant than if this was driven all the way down into the matplotlib c++ (I think?) and is not very convenient.

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