Re: [matplotlib-devel] auto range limits for spines: please kick the tires
Andrew Straw wrote: Gary Ruben wrote: This looks nice Andrew, I haven't tried it, but I wonder whether it's possible to add a keyword arg to suppress the 0's at the origin which are cut through by the axes in the zeroed case (and/or possibly shift the 0 on the horizontal axis left). The same thing is happening in the (1,2) case on the vertical axis. Hi Gary, John also suggested something like this. I don't think it's impossible, but it's outside the scope of the work I have done and beyond my immediate familiarity with the code base. I think it would involve looking at the tick label bounding boxes, finding overlaps, and then deciding which label was less important and removing it. I don't think it would be impossible, and maybe not even hard, but I haven't investigated at all. Thanks for keeping it on the queue. I did something like this for the Sage project, but I did it on the tick formatter level. I just made a tick formatter that omitted specified positions. I've attached the Selective Formatter class. If anyone has comments, I'd appreciate them! Basically, I just replaced the formatter with the selective formatter, which passed things on to the previous formatter if the tick label was allowed. It would be great if spines supported this sort of thing natively, but the flexibility of tick formatters seems like a nice place to handle it as well. Thanks, Jason from matplotlib.ticker import Formatter class SelectiveFormatter(Formatter): This matplotlib formatter selectively omits some tick values and passes the rest on to a specified formatter. EXAMPLES: This example is almost straight from a matplotlib example. :: sage: from sage.plot.plot import SelectiveFormatter sage: import matplotlib.pyplot as plt sage: import numpy sage: fig=plt.figure() sage: ax=fig.add_subplot(111) sage: t = numpy.arange(0.0, 2.0, 0.01) sage: s = numpy.sin(2*numpy.pi*t) sage: line=ax.plot(t, s) sage: formatter=SelectiveFormatter(ax.xaxis.get_major_formatter(),skip_values=[0,1]) sage: ax.xaxis.set_major_formatter(formatter) sage: fig.savefig(os.path.join(SAGE_TMP, 'test.png')) def __init__(self, formatter,skip_values): Initialize a SelectiveFormatter object. INPUT: - formatter -- the formatter object to which we should pass labels - skip_values -- a list of values that we should skip when formatting the tick labels EXAMPLES:: sage: from sage.plot.plot import SelectiveFormatter sage: import matplotlib.pyplot as plt sage: import numpy sage: fig=plt.figure() sage: ax=fig.add_subplot(111) sage: t = numpy.arange(0.0, 2.0, 0.01) sage: s = numpy.sin(2*numpy.pi*t) sage: line=ax.plot(t, s) sage: formatter=SelectiveFormatter(ax.xaxis.get_major_formatter(),skip_values=[0,1]) sage: ax.xaxis.set_major_formatter(formatter) sage: fig.savefig(os.path.join(SAGE_TMP, 'test.png')) self.formatter=formatter self.skip_values=skip_values def set_locs(self, locs): Set the locations for the ticks that are not skipped. EXAMPLES:: sage: from sage.plot.plot import SelectiveFormatter sage: import matplotlib.ticker sage: formatter=SelectiveFormatter(matplotlib.ticker.Formatter(),skip_values=[0,200]) sage: formatter.set_locs([i*100 for i in range(10)]) self.formatter.set_locs([l for l in locs if l not in self.skip_values]) def __call__(self, x, *args, **kwds): Return the format for tick val *x* at position *pos* EXAMPLES:: sage: from sage.plot.plot import SelectiveFormatter sage: import matplotlib.ticker sage: formatter=SelectiveFormatter(matplotlib.ticker.FixedFormatter(['a','b']),skip_values=[0,2]) sage: [formatter(i,1) for i in range(10)] ['', 'b', '', 'b', 'b', 'b', 'b', 'b', 'b', 'b'] if x in self.skip_values: return '' else: return self.formatter(x, *args, **kwds) -- This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] auto range limits for spines: please kick the tires
Andrew Straw straw...@astraw.com writes: if you update from svn and play around with the demo, especially by panning and zooming in the figures, you'll get an idea of what I've done. Neat! One small thing: in Figure 2 (the four subplots with differently placed spines) if I zoom and pan subplot 4, I can make its spines appear in subplots 2 and 3. Curiously enough, they don't show up in subplot 1. -- Jouni K. Seppänen http://www.iki.fi/jks -- This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] auto range limits for spines: please kick the tires
This looks nice Andrew, I haven't tried it, but I wonder whether it's possible to add a keyword arg to suppress the 0's at the origin which are cut through by the axes in the zeroed case (and/or possibly shift the 0 on the horizontal axis left). The same thing is happening in the (1,2) case on the vertical axis. Gary Andrew Straw wrote: I have implemented something I'm calling smart bounds for the axis spines, and have just committed it to svn r8048. I modified examples/pylab_examples/spine_placement_demo.py to illustrate the basic idea -- the spines and ticks should be able to automatically limit themselves to the data range. There are some subtleties beyond that in terms of the algorithmic details, but I think if you update from svn and play around with the demo, especially by panning and zooming in the figures, you'll get an idea of what I've done. I've attached two images from such a session. The key API addition is this: spine.set_smart_bounds(True) Doing so turns on the smart bounds mode in the spine and the axis. Anyhow, I'd be happy to receive any feedback on this new feature. -Andrew -- This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] auto range limits for spines: please kick the tires
Gary Ruben wrote: This looks nice Andrew, I haven't tried it, but I wonder whether it's possible to add a keyword arg to suppress the 0's at the origin which are cut through by the axes in the zeroed case (and/or possibly shift the 0 on the horizontal axis left). The same thing is happening in the (1,2) case on the vertical axis. Hi Gary, John also suggested something like this. I don't think it's impossible, but it's outside the scope of the work I have done and beyond my immediate familiarity with the code base. I think it would involve looking at the tick label bounding boxes, finding overlaps, and then deciding which label was less important and removing it. I don't think it would be impossible, and maybe not even hard, but I haven't investigated at all. Thanks for keeping it on the queue. -Andrew -- This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] auto range limits for spines: please kick the tires
On Mon, Dec 21, 2009 at 3:46 PM, Andrew Straw straw...@astraw.com wrote: John also suggested something like this. I don't think it's impossible, but it's outside the scope of the work I have done and beyond my immediate familiarity with the code base. I think it would involve looking at the tick label bounding boxes, finding overlaps, and then deciding which label was less important and removing it. I don't think it would be impossible, and maybe not even hard, but I haven't investigated at all. Thanks for keeping it on the queue. One easy-ish approach would be to do this at the Axes layer, which knows all the Axis contained within. We could have some property like hide_tick_overlaps and have a zorder on the axis, so if an axis is above another, and any of the lower axis ticks overlap any of the above ticks, then the lower ticks would be rendered invisible giving the user some control of which get shown. This would probably need to be a draw time operation, with something like a before_draw_hook handling the visibility and an after_draw_hook restoring the default visibility. -- This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel