> 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:

----

import numpy as np
import matplotlib as mpl
import matplotlib.ticker as mticker
import matplotlib.transforms as mtransforms

class LooseMaxNLocator(mticker.MaxNLocator):

    def __init__(self, margin = 0.05, **kwargs):
        mticker.MaxNLocator.__init__(self, **kwargs)
        self._margin = margin

    def autoscale(self):
        dmin, dmax = self.axis.get_data_interval()
        if self._symmetric:
            maxabs = max(abs(dmin), abs(dmax))
            dmin = -maxabs
            dmax = maxabs
        dmin, dmax = mtransforms.nonsingular(dmin, dmax, expander = 0.05)
        margin = self._margin * (dmax - dmin)
        vmin = dmin - margin
        vmax = dmax + margin
        bin_boundaries = self.bin_boundaries(vmin, vmax)
        vmin = min(vmin, max(bin_boundaries[bin_boundaries <= dmin]))
        vmax = max(vmax, min(bin_boundaries[bin_boundaries >= dmax]))
        return np.array([vmin, vmax])

----

The *margin* argument controls the looseness.  For a given axis *ax*, you
instantiate and apply the locator with something like

    ax.xaxis.set_major_locator(LooseMaxNLocator(nbins=7, steps=[1, 2, 5, 10]))

and likewise for the Y axis.  I believe that if the plot has already been
drawn, you have to somehow force an autoscaling.

I wrote that about 1.5 years ago for an earlier version of matplotlib, and I
don't know how compatible it is with the current ticker.py code.  In
particular, you might need to override *view_limits* instead of *autoscale*.
Anyway, I hope it's useful to you.


------------------------------------------------------------------------------
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