I’m not sure if this is going to work to solve an issue I’m having, but I’d like to try it before asking a much more complex question. I have a function, loose_autoscale_view(), that is based on the autoscale_view function in mpl but allows margin arguments to push the margins out a bit more.
I’d like to try to alter it to allow certain lines belonging to an axis to not be taken into consideration when autoscaling. I can alter it to accept a list of lines to be excluded, but then I don’t know how to exclude them when calculating the autoscaling. I think the key line in the function is this one:
bb = mtransforms.BboxBase.union(dl)
because that union gets the sub-BBoxes for all the lines…so is there a way to exclude some? Or is there a better approach?
Thanks. The function is below.
-Che
def loose_autoscale_view(self, subplot, xmargin, ymargin, tight=False, scalex=True, scaley=True):
“”"
autoscale the view limits using the data limits. You can
selectively autoscale only a single axis, eg, the xaxis by
setting *scaley* to *False*. The autoscaling preserves any
axis direction reversal that has already been done.
I have added a way to make it not quite so tight using xmargin and ymargin.
"""
# if image data only just use the datalim
#if not self.subplot._autoscaleon: return
if scalex:
xshared = subplot._shared_x_axes.get_siblings(subplot)
dl = [ax.dataLim for ax in xshared]
bb = mtransforms.BboxBase.union(dl)
xdiff = bb.intervalx[1] - bb.intervalx[0]
x0 = bb.intervalx[0]-xdiff * xmargin
x1 = bb.intervalx[1]+xdiff * xmargin
if scaley:
yshared = subplot._shared_y_axes.get_siblings(subplot)
dl = [ax.dataLim for ax in yshared]
bb = mtransforms.BboxBase.union(dl)
y0_untampered = bb.intervaly[0]-(bb.intervaly[1])
y0 = bb.intervaly[0]-(bb.intervaly[1]* ymargin)
y1_untampered = bb.intervaly[1]
y1 = bb.intervaly[1]* (1+ymargin)
if (tight or (len(subplot.images)>0 and
len(subplot.lines)==0 and
len(subplot.patches)==0)):
if scalex:
subplot.set_xbound(x0, x1)
if scaley:
subplot.set_ybound(y0, y1)
return
if scalex:
XL = subplot.xaxis.get_major_locator().view_limits(x0, x1)
subplot.set_xbound(XL)
if scaley:
YL = subplot.yaxis.get_major_locator().view_limits(y0, y1)
subplot.set_ybound(YL)