On Fri, Feb 12, 2010 at 2:24 PM, Stan West <stan.w...@nrl.navy.mil> wrote:
>> From: C M [mailto:cmpyt...@gmail.com]
>> Sent: Wednesday, February 03, 2010 21:59
>>
>> I'm using autoscale_view for the y axis, but find with a marker size >
>> about 10, it will autoscale the graphs such that some markers are
>> bisected by the edges of the frame.  I already have it set to:
>>
>>     self.subplot.autoscale_view(tight=False, scalex=False,
>> scaley=True)
>>
>> so I'd basically like "tight" here to be "even less tight".  For
>> example, for a graph of time in minutes along the y axis, I'd like the
>> bottom of the graph to actually be a bit below zero to catch events
>> that are 0.5 min, etc., without them being half-buried under the edge
>> of the graph.
>>
>> Can autoscale_view be altered a bit to allow for a more generous view?
>
> For a similar requirement, I made the following custom locator:

Thank you.  I've been playing around with a way to do this, and may
have something working now from my attempt to modify the
autoscale_view function in axes.py.  My own re-write is below. It's
barely different from what is in the original function.  It just gets
the two edges of the bounding box that contains all the lines and
moves them out a bit.

I would like to understand your approach better.  So far, I can't get
your code to produce the "margins" indicated--but I'm probably
applying it wrongly.  I don't know how to force an autoscale, for
example.  Your code is tough for me to understand because there are a
number of things you make use of that I'm not familiar with yet. I
could ask a number of questions but don't want to burden the list with
that unless people are up for it.

Thanks,
Che

#  autoscale_view function that allows looser edges.

    def loose_autoscale_view(self, subplot, margin, 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.

        """
        # if image data only just use the datalim
        if not self.subplot._autoscaleon: return
        if scalex:
            xshared = self.subplot._shared_x_axes.get_siblings(self.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 * margin
            x1 = bb.intervalx[1]+xdiff * margin
        if scaley:
            yshared = self.subplot._shared_y_axes.get_siblings(self.subplot)
            dl = [ax.dataLim for ax in yshared]
            bb = mtransforms.BboxBase.union(dl)
            y0 = bb.intervaly[0]-(bb.intervaly[1]* margin)
            y1 = bb.intervaly[1]* (1+margin)

        if (tight or (len(self.subplot.images)>0 and
                      len(self.subplot.lines)==0 and
                      len(self.subplot.patches)==0)):
            if scalex:
                self.subplot.set_xbound(x0, x1)
            if scaley:
                self.subplot.set_ybound(y0, y1)
            return

        if scalex:
            XL = self.subplot.xaxis.get_major_locator().view_limits(x0, x1)
            self.subplot.set_xbound(XL)
        if scaley:
            YL = self.subplot.yaxis.get_major_locator().view_limits(y0, y1)
            self.subplot.set_ybound(YL)

#Then it would be called with:

        self.loose_autoscale_view(self.subplot, 0.02, tight=False,
scalex=True, scaley=True)

#where self.subplot is my axes object.  (self is a panel class)

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to