From: <ef...@us...> - 2007-09-04 05:53:57
|
Revision: 3772 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3772&view=rev Author: efiring Date: 2007-09-03 22:53:56 -0700 (Mon, 03 Sep 2007) Log Message: ----------- Errorbar limit symbols patch by Manuel Metz Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/lines.py Added Paths: ----------- trunk/matplotlib/examples/errorbar_limits.py Added: trunk/matplotlib/examples/errorbar_limits.py =================================================================== --- trunk/matplotlib/examples/errorbar_limits.py (rev 0) +++ trunk/matplotlib/examples/errorbar_limits.py 2007-09-04 05:53:56 UTC (rev 3772) @@ -0,0 +1,40 @@ +''' +Illustration of upper and lower limit symbols on errorbars +''' + +from math import pi +from numpy import array, arange, sin +import pylab as P + +fig = P.figure() +x = arange(10.0) +y = sin(arange(10.0)/20.0*pi) + +P.errorbar(x,y,yerr=0.1,capsize=3) + +y = sin(arange(10.0)/20.0*pi) + 1 +P.errorbar(x,y,yerr=0.1, uplims=True) + +y = sin(arange(10.0)/20.0*pi) + 2 +upperlimits = array([1,0]*5) +lowerlimits = array([0,1]*5) +P.errorbar(x, y, yerr=0.1, uplims=upperlimits, lolims=lowerlimits) + +P.xlim(-1,10) + +fig = P.figure() +x = arange(10.0)/10.0 +y = (x+0.1)**2 + +P.errorbar(x, y, xerr=0.1, xlolims=True) +y = (x+0.1)**3 + +P.errorbar(x+0.6, y, xerr=0.1, xuplims=upperlimits, xlolims=lowerlimits) + +y = (x+0.1)**4 +P.errorbar(x+1.2, y, xerr=0.1, xuplims=True) + +P.xlim(-0.2,2.4) +P.ylim(-0.1,1.3) + +P.show() Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2007-09-03 22:16:19 UTC (rev 3771) +++ trunk/matplotlib/lib/matplotlib/axes.py 2007-09-04 05:53:56 UTC (rev 3772) @@ -3522,10 +3522,13 @@ def errorbar(self, x, y, yerr=None, xerr=None, fmt='-', ecolor=None, capsize=3, - barsabove=False, **kwargs): + barsabove=False, lolims=False, uplims=False, + xlolims=False, xuplims=False, **kwargs): """ ERRORBAR(x, y, yerr=None, xerr=None, - fmt='b-', ecolor=None, capsize=3, barsabove=False) + fmt='b-', ecolor=None, capsize=3, barsabove=False, + lolims=False, uplims=False, + xlolims=False, xuplims=False) Plot x versus y with error deltas in yerr and xerr. Vertical errorbars are plotted if yerr is not None @@ -3554,6 +3557,11 @@ barsabove, if True, will plot the errorbars above the plot symbols - default is below + lolims, uplims, xlolims, xuplims: These arguments can be used + to indicate that a value gives only upper/lower limits. In + that case a caret symbol is used to indicate this. lims-arguments + may be of the same type as xerr and yerr. + kwargs are passed on to the plot command for the markers. So you can add additional key=value pairs to control the errorbar markers. For example, this code makes big red @@ -3579,18 +3587,18 @@ if not self._hold: self.cla() # make sure all the args are iterable arrays - if not iterable(x): x = npy.asarray([x]) + if not iterable(x): x = npy.array([x]) else: x = npy.asarray(x) - if not iterable(y): y = npy.asarray([y]) + if not iterable(y): y = npy.array([y]) else: y = npy.asarray(y) if xerr is not None: - if not iterable(xerr): xerr = npy.asarray([xerr]) + if not iterable(xerr): xerr = npy.array([xerr]) else: xerr = npy.asarray(xerr) if yerr is not None: - if not iterable(yerr): yerr = npy.asarray([yerr]) + if not iterable(yerr): yerr = npy.array([yerr]) else: yerr = npy.asarray(yerr) l0 = None @@ -3607,6 +3615,18 @@ if 'lw' in kwargs: lines_kw['lw']=kwargs['lw'] + if not iterable(lolims): lolims = npy.array([lolims]*len(x), bool) + else: lolims = npy.asarray(lolims, bool) + + if not iterable(uplims): uplims = npy.array([uplims]*len(x), bool) + else: uplims = npy.asarray(uplims, bool) + + if not iterable(xlolims): xlolims = npy.array([xlolims]*len(x), bool) + else: xlolims = npy.asarray(xlolims, bool) + + if not iterable(xuplims): xuplims = npy.array([xuplims]*len(x), bool) + else: xuplims = npy.asarray(xuplims, bool) + if capsize > 0: plot_kw = { 'ms':2*capsize, @@ -3626,9 +3646,20 @@ barcols.append( self.hlines(y, left, right, **lines_kw ) ) if capsize > 0: - caplines.extend( self.plot(left, y, 'k|', **plot_kw) ) - caplines.extend( self.plot(right, y, 'k|', **plot_kw) ) + if xlolims.any(): + caplines.extend( self.plot(left[xlolims], y[xlolims], ls='None', marker=mlines.CARETLEFT, **plot_kw) ) + xlolims = ~xlolims + caplines.extend( self.plot(left[xlolims], y[xlolims], 'k|', **plot_kw) ) + else: + caplines.extend( self.plot(left, y, 'k|', **plot_kw) ) + if xuplims.any(): + caplines.extend( self.plot(right[xuplims], y[xuplims], ls='None', marker=mlines.CARETRIGHT, **plot_kw) ) + xuplims = ~xuplims + caplines.extend( self.plot(right[xuplims], y[xuplims], 'k|', **plot_kw) ) + else: + caplines.extend( self.plot(right, y, 'k|', **plot_kw) ) + if yerr is not None: if len(yerr.shape) == 1: lower = y-yerr @@ -3639,9 +3670,21 @@ barcols.append( self.vlines(x, lower, upper, **lines_kw) ) if capsize > 0: - caplines.extend( self.plot(x, lower, 'k_', **plot_kw) ) - caplines.extend( self.plot(x, upper, 'k_', **plot_kw) ) + if lolims.any(): + caplines.extend( self.plot(x[lolims], lower[lolims], ls='None', marker=mlines.CARETDOWN, **plot_kw) ) + lolims = ~lolims + caplines.extend( self.plot(x[lolims], lower[lolims], 'k_', **plot_kw) ) + else: + caplines.extend( self.plot(x, lower, 'k_', **plot_kw) ) + + if uplims.any(): + caplines.extend( self.plot(x[uplims], upper[uplims], ls='None', marker=mlines.CARETUP, **plot_kw) ) + uplims = ~uplims + caplines.extend( self.plot(x[uplims], upper[uplims], 'k_', **plot_kw) ) + else: + caplines.extend( self.plot(x, upper, 'k_', **plot_kw) ) + if not barsabove and fmt is not None: l0, = self.plot(x,y,fmt,**kwargs) Modified: trunk/matplotlib/lib/matplotlib/lines.py =================================================================== --- trunk/matplotlib/lib/matplotlib/lines.py 2007-09-03 22:16:19 UTC (rev 3771) +++ trunk/matplotlib/lib/matplotlib/lines.py 2007-09-04 05:53:56 UTC (rev 3772) @@ -21,7 +21,9 @@ from transforms import lbwh_to_bbox, LOG10 from matplotlib import rcParams -TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN = range(4) +# special-purpose marker identifiers: +(TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN, + CARETLEFT, CARETRIGHT, CARETUP, CARETDOWN) = range(8) def unmasked_index_ranges(mask, compressed = True): ''' @@ -97,7 +99,7 @@ point_hits = (cx - x)**2 + (cy - y)**2 <= radius**2 #if any(point_hits): print "points",xr[candidates] candidates = candidates & ~point_hits[:-1] & ~point_hits[1:] - + # For those candidates which remain, determine how far they lie away # from the line. px,py = xr+u*dx,yr+u*dy @@ -147,6 +149,10 @@ TICKRIGHT : '_draw_tickright', TICKUP : '_draw_tickup', TICKDOWN : '_draw_tickdown', + CARETLEFT : '_draw_caretleft', + CARETRIGHT : '_draw_caretright', + CARETUP : '_draw_caretup', + CARETDOWN : '_draw_caretdown', 'None' : '_draw_nothing', ' ' : '_draw_nothing', '' : '_draw_nothing', @@ -1201,6 +1207,62 @@ renderer.draw_line(gc, x, y, x-offset2, y+offset1) renderer.draw_line(gc, x, y, x-offset2, y-offset1) + def _draw_caretdown(self, renderer, gc, xt, yt): + offset = 0.5*renderer.points_to_pixels(self._markersize) + offset1 = 1.5*offset + if self._newstyle: + path = agg.path_storage() + path.move_to(-offset, offset1) + path.line_to(0, 0) + path.line_to(+offset, offset1) + renderer.draw_markers(gc, path, None, xt, yt, self.get_transform()) + else: + for (x,y) in zip(xt, yt): + renderer.draw_line(gc, x-offset, y+offset1, x, y) + renderer.draw_line(gc, x, y, x+offset, y+offset1) + + def _draw_caretup(self, renderer, gc, xt, yt): + offset = 0.5*renderer.points_to_pixels(self._markersize) + offset1 = 1.5*offset + if self._newstyle: + path = agg.path_storage() + path.move_to(-offset, -offset1) + path.line_to(0, 0) + path.line_to(+offset, -offset1) + renderer.draw_markers(gc, path, None, xt, yt, self.get_transform()) + else: + for (x,y) in zip(xt, yt): + renderer.draw_line(gc, x-offset, y-offset1, x, y) + renderer.draw_line(gc, x, y, x+offset, y-offset1) + + def _draw_caretleft(self, renderer, gc, xt, yt): + offset = 0.5*renderer.points_to_pixels(self._markersize) + offset1 = 1.5*offset + if self._newstyle: + path = agg.path_storage() + path.move_to(offset1, -offset) + path.line_to(0, 0) + path.line_to(offset1, offset) + renderer.draw_markers(gc, path, None, xt, yt, self.get_transform()) + else: + for (x,y) in zip(xt, yt): + renderer.draw_line(gc, x+offset1, y-offset, x, y) + renderer.draw_line(gc, x, y, x+offset1, y+offset) + + def _draw_caretright(self, renderer, gc, xt, yt): + offset = 0.5*renderer.points_to_pixels(self._markersize) + offset1 = 1.5*offset + if self._newstyle: + path = agg.path_storage() + path.move_to(-offset1, -offset) + path.line_to(0, 0) + path.line_to(-offset1, offset) + renderer.draw_markers(gc, path, None, xt, yt, self.get_transform()) + else: + for (x,y) in zip(xt, yt): + renderer.draw_line(gc, x-offset1, y-offset, x, y) + renderer.draw_line(gc, x, y, x-offset1, y+offset) + def _draw_x(self, renderer, gc, xt, yt): offset = 0.5*renderer.points_to_pixels(self._markersize) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |