From: <jd...@us...> - 2009-04-17 20:40:42
|
Revision: 7050 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7050&view=rev Author: jdh2358 Date: 2009-04-17 20:40:29 +0000 (Fri, 17 Apr 2009) Log Message: ----------- use 0 for default in rec join outer join if no default given Modified Paths: -------------- trunk/matplotlib/doc/sphinxext/gen_gallery.py trunk/matplotlib/examples/misc/rec_join_demo.py trunk/matplotlib/lib/matplotlib/backend_bases.py trunk/matplotlib/lib/matplotlib/mlab.py Modified: trunk/matplotlib/doc/sphinxext/gen_gallery.py =================================================================== --- trunk/matplotlib/doc/sphinxext/gen_gallery.py 2009-04-17 20:20:07 UTC (rev 7049) +++ trunk/matplotlib/doc/sphinxext/gen_gallery.py 2009-04-17 20:40:29 UTC (rev 7050) @@ -38,7 +38,7 @@ print print "generating gallery: ", data = [] - for subdir in ('api', 'pylab_examples', 'widgets'): + for subdir in ('api', 'pylab_examples', 'widgets', 'mplot3d'): origdir = os.path.join('build', rootdir, subdir) thumbdir = os.path.join(outdir, rootdir, subdir, 'thumbnails') if not os.path.exists(thumbdir): Modified: trunk/matplotlib/examples/misc/rec_join_demo.py =================================================================== --- trunk/matplotlib/examples/misc/rec_join_demo.py 2009-04-17 20:20:07 UTC (rev 7049) +++ trunk/matplotlib/examples/misc/rec_join_demo.py 2009-04-17 20:40:29 UTC (rev 7050) @@ -6,8 +6,8 @@ r.sort() r1 = r[-10:] -# Create a new array -r2 = np.empty(12, dtype=[('date', '|O4'), ('high', np.float), +# Create a new array +r2 = np.empty(12, dtype=[('date', '|O4'), ('high', np.float), ('marker', np.float)]) r2 = r2.view(np.recarray) r2.date = r.date[-17:-5] @@ -19,9 +19,9 @@ print "r2:" print mlab.rec2txt(r2) -defaults = {'marker':-1, 'close':np.NaN, 'low':-4444.} +defaults = {'marker':-1, '_close':np.NaN, 'low':-4444.} for s in ('inner', 'outer', 'leftouter'): - rec = mlab.rec_join(['date', 'high'], r1, r2, - jointype=s, defaults=defaults) + rec = mlab.rec_join(['date', 'high'], r1, r2, + jointype=s, defaults=defaults) print "\n%sjoin :\n%s" % (s, mlab.rec2txt(rec)) Modified: trunk/matplotlib/lib/matplotlib/backend_bases.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backend_bases.py 2009-04-17 20:20:07 UTC (rev 7049) +++ trunk/matplotlib/lib/matplotlib/backend_bases.py 2009-04-17 20:40:29 UTC (rev 7050) @@ -1058,7 +1058,7 @@ under = self.figure.hitlist(ev) enter = [a for a in under if a not in self._active] leave = [a for a in self._active if a not in under] - print "within:"," ".join([str(x) for x in under]) + #print "within:"," ".join([str(x) for x in under]) #print "entering:",[str(a) for a in enter] #print "leaving:",[str(a) for a in leave] # On leave restore the captured colour @@ -1520,6 +1520,10 @@ - 'pick_event' - 'resize_event' - 'scroll_event' + - 'figure_enter_event', + - 'figure_leave_event', + - 'axes_enter_event', + - 'axes_leave_event' For the location events (button and key press/release), if the mouse is over the axes, the variable ``event.inaxes`` will be Modified: trunk/matplotlib/lib/matplotlib/mlab.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mlab.py 2009-04-17 20:20:07 UTC (rev 7049) +++ trunk/matplotlib/lib/matplotlib/mlab.py 2009-04-17 20:40:29 UTC (rev 7050) @@ -2303,6 +2303,17 @@ newrec = np.empty(common_len + left_len + right_len, dtype=newdtype) + if defaults is not None: + for thiskey in defaults: + if thiskey not in newdtype.names: + warnings.warn('rec_join defaults key="%s" not in new dtype names "%s"'%( + thiskey, newdtype.names)) + + for name in newdtype.names: + dt = newdtype[name] + if dt.kind in ('f', 'i'): + newrec[name] = 0 + if jointype != 'inner' and defaults is not None: # fill in the defaults enmasse newrec_fields = newrec.dtype.fields.keys() for k, v in defaults.items(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-04-18 16:02:57
|
Revision: 7052 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7052&view=rev Author: leejjoon Date: 2009-04-18 16:02:56 +0000 (Sat, 18 Apr 2009) Log Message: ----------- offsetbox minor update Modified Paths: -------------- trunk/matplotlib/examples/axes_grid/simple_anchored_artists.py trunk/matplotlib/lib/matplotlib/offsetbox.py trunk/matplotlib/lib/mpl_toolkits/axes_grid/anchored_artists.py Removed Paths: ------------- trunk/matplotlib/examples/pylab_examples/axes_divider.py trunk/matplotlib/examples/pylab_examples/axes_grid.py Modified: trunk/matplotlib/examples/axes_grid/simple_anchored_artists.py =================================================================== --- trunk/matplotlib/examples/axes_grid/simple_anchored_artists.py 2009-04-17 20:40:58 UTC (rev 7051) +++ trunk/matplotlib/examples/axes_grid/simple_anchored_artists.py 2009-04-18 16:02:56 UTC (rev 7052) @@ -11,7 +11,8 @@ at2 = AnchoredText("Figure 1(b)", loc=3, prop=dict(size=8), frameon=True, - bbox_to_anchor=(0., 1.) + bbox_to_anchor=(0., 1.), + bbox_transform=ax.transAxes ) at2.patch.set_boxstyle("round,pad=0.,rounding_size=0.2") ax.add_artist(at2) Deleted: trunk/matplotlib/examples/pylab_examples/axes_divider.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/axes_divider.py 2009-04-17 20:40:58 UTC (rev 7051) +++ trunk/matplotlib/examples/pylab_examples/axes_divider.py 2009-04-18 16:02:56 UTC (rev 7052) @@ -1,674 +0,0 @@ - -import matplotlib.axes as maxes -import matplotlib.transforms as mtransforms - -import matplotlib.cbook as cbook - -import new - - -class Size(object): - - @classmethod - def from_any(self, size, fraction_ref=None): - if cbook.is_numlike(size): - return Size.Fixed(size) - elif cbook.is_string_like(size): - if size[-1] == "%": - return Size.Fraction(fraction_ref, float(size[:-1])/100.) - - raise ValueError("") - - - - class _Base(object): - pass - - class Fixed(_Base): - def __init__(self, fixed_size): - self._fixed_size = fixed_size - - def get_size(self, renderer): - rel_size = 0. - abs_size = self._fixed_size - return rel_size, abs_size - - class Scalable(_Base): - def __init__(self, scalable_size): - self._scalable_size = scalable_size - - def get_size(self, renderer): - rel_size = self._scalable_size - abs_size = 0. - return rel_size, abs_size - - - class AxesX(_Base): - def __init__(self, axes, aspect=1.): - self._axes = axes - self._aspect = aspect - - def get_size(self, renderer): - l1, l2 = self._axes.get_xlim() - rel_size = abs(l2-l1)*self._aspect - abs_size = 0. - return rel_size, abs_size - - class AxesY(_Base): - def __init__(self, axes, aspect=1.): - self._axes = axes - self._aspect = aspect - - def get_size(self, renderer): - l1, l2 = self._axes.get_ylim() - rel_size = abs(l2-l1)*self._aspect - abs_size = 0. - return rel_size, abs_size - - - class MaxExtent(_Base): - def __init__(self, artist_list, w_or_h): - self._artist_list = artist_list - - if w_or_h not in ["width", "height"]: - raise ValueError() - - self._w_or_h = w_or_h - - def add_artist(self, a): - self._artist_list.append(a) - - def get_size(self, renderer): - rel_size = 0. - w_list, h_list = [], [] - for a in self._artist_list: - bb = a.get_window_extent(renderer) - w_list.append(bb.width) - h_list.append(bb.height) - dpi = a.get_figure().get_dpi() - if self._w_or_h == "width": - abs_size = max(w_list)/dpi - elif self._w_or_h == "height": - abs_size = max(h_list)/dpi - - return rel_size, abs_size - - class Fraction(_Base): - def __init__(self, size, fraction): - self._size = size - self._fraction = fraction - - def get_size(self, renderer): - r, a = self._size.get_size(renderer) - rel_size = r*self._fraction - abs_size = a*self._fraction - return rel_size, abs_size - - class Padded(_Base): - def __init__(self, size, pad): - self._size = size - self._pad = pad - - def get_size(self, renderer): - r, a = self._size.get_size(renderer) - rel_size = r - abs_size = a + self._pad - return rel_size, abs_size - - - -class AxesLocator(object): - def __init__(self, axes_divider, nx, ny, nx1=None, ny1=None): - - self._axes_divider = axes_divider - - _xrefindex = axes_divider._xrefindex - _yrefindex = axes_divider._yrefindex - - self._nx, self._ny = nx - _xrefindex, ny - _yrefindex - - if nx1 is None: - nx1 = nx+1 - if ny1 is None: - ny1 = ny+1 - - self._nx1 = nx1 - _xrefindex - self._ny1 = ny1 - _yrefindex - - - def __call__(self, axes, renderer): - - _xrefindex = self._axes_divider._xrefindex - _yrefindex = self._axes_divider._yrefindex - - return self._axes_divider.locate(self._nx + _xrefindex, self._ny + _yrefindex, - self._nx1 + _xrefindex, self._ny1 + _yrefindex, - renderer) - - -class Divider(object): - - def __init__(self, fig, pos, horizontal, vertical, aspect=None, anchor="C"): - self._fig = fig - self._pos = pos - self._horizontal = horizontal - self._vertical = vertical - self._anchor = anchor - self._aspect = aspect - self._xrefindex = 0 - self._yrefindex = 0 - - - @staticmethod - def _calc_k(l, total_size, renderer): - - rs_sum, as_sum = 0., 0. - - for s in l: - rs, as = s.get_size(renderer) - rs_sum += rs - as_sum += as - - if rs_sum != 0.: - k = (total_size - as_sum) / rs_sum - return k - else: - return 0. - - - @staticmethod - def _calc_offsets(l, k, renderer): - - offsets = [0.] - - for s in l: - rs, as = s.get_size(renderer) - offsets.append(offsets[-1] + rs*k + as) - - return offsets - - - def set_position(self, pos): - self._pos = pos - - def get_position(self): - return self._pos - - def set_anchor(self, anchor): - """ - *anchor* - - ===== ============ - value description - ===== ============ - 'C' Center - 'SW' bottom left - 'S' bottom - 'SE' bottom right - 'E' right - 'NE' top right - 'N' top - 'NW' top left - 'W' left - ===== ============ - - """ - if anchor in mtransforms.Bbox.coefs.keys() or len(anchor) == 2: - self._anchor = anchor - else: - raise ValueError('argument must be among %s' % - ', '.join(mtransforms.BBox.coefs.keys())) - - - def set_horizontal(self, h): - self._horizontal = h - - def get_horizontal(self): - return self._horizontal - - def set_vertical(self, v): - self._vertical = v - - def get_vertical(self): - return self._vertical - - - def get_anchor(self): - return self._anchor - - - def set_aspect(self, aspect=False): - """ - *aspect* : True or False - """ - self._aspect = aspect - - def get_aspect(self): - return self._aspect - - - def locate(self, nx, ny, nx1=None, ny1=None, renderer=None): - - - figW,figH = self._fig.get_size_inches() - x, y, w, h = self.get_position() - - k_h = self._calc_k(self._horizontal, figW*w, renderer) - k_v = self._calc_k(self._vertical, figH*h, renderer) - - if self.get_aspect(): - k = min(k_h, k_v) - ox = self._calc_offsets(self._horizontal, k, renderer) - oy = self._calc_offsets(self._vertical, k, renderer) - - ww = (ox[-1] - ox[0])/figW - hh = (oy[-1] - oy[0])/figH - pb = mtransforms.Bbox.from_bounds(x, y, w, h) - pb1 = mtransforms.Bbox.from_bounds(x, y, ww, hh) - pb1_anchored = pb1.anchored(self.get_anchor(), pb) - x0, y0 = pb1_anchored.x0, pb1_anchored.y0 - - else: - ox = self._calc_offsets(self._horizontal, k_h, renderer) - oy = self._calc_offsets(self._vertical, k_v, renderer) - x0, y0 = x, y - - - if nx1 is None: - nx1=nx+1 - if ny1 is None: - ny1=ny+1 - - x1, w1 = x0 + ox[nx]/figW, (ox[nx1] - ox[nx])/figW - y1, h1 = y0 + oy[ny]/figH, (oy[ny1] - oy[ny])/figH - - return mtransforms.Bbox.from_bounds(x1, y1, w1, h1) - - - def new_locator(self, nx, ny, nx1=None, ny1=None): - return AxesLocator(self, nx, ny, nx1, ny1) - - -class SubplotDivider(Divider): - - def __init__(self, fig, *args, **kwargs): - """ - *fig* is a :class:`matplotlib.figure.Figure` instance. - - *args* is the tuple (*numRows*, *numCols*, *plotNum*), where - the array of subplots in the figure has dimensions *numRows*, - *numCols*, and where *plotNum* is the number of the subplot - being created. *plotNum* starts at 1 in the upper left - corner and increases to the right. - - If *numRows* <= *numCols* <= *plotNum* < 10, *args* can be the - decimal integer *numRows* * 100 + *numCols* * 10 + *plotNum*. - """ - - self.figure = fig - - if len(args)==1: - s = str(args[0]) - if len(s) != 3: - raise ValueError('Argument to subplot must be a 3 digits long') - rows, cols, num = map(int, s) - elif len(args)==3: - rows, cols, num = args - else: - raise ValueError( 'Illegal argument to subplot') - - - total = rows*cols - num -= 1 # convert from matlab to python indexing - # ie num in range(0,total) - if num >= total: - raise ValueError( 'Subplot number exceeds total subplots') - self._rows = rows - self._cols = cols - self._num = num - - self.update_params() - - pos = self.figbox.bounds - horizontal = kwargs.pop("horizontal", []) - vertical = kwargs.pop("vertical", []) - aspect = kwargs.pop("aspect", None) - anchor = kwargs.pop("anchor", "C") - - if kwargs: - raise Exception("") - - Divider.__init__(self, fig, pos, horizontal, vertical, - aspect=aspect, anchor=anchor) - - - def get_position(self): - self.update_params() - return self.figbox.bounds - - - def update_params(self): - 'update the subplot position from fig.subplotpars' - - rows = self._rows - cols = self._cols - num = self._num - - pars = self.figure.subplotpars - left = pars.left - right = pars.right - bottom = pars.bottom - top = pars.top - wspace = pars.wspace - hspace = pars.hspace - totWidth = right-left - totHeight = top-bottom - - figH = totHeight/(rows + hspace*(rows-1)) - sepH = hspace*figH - - figW = totWidth/(cols + wspace*(cols-1)) - sepW = wspace*figW - - rowNum, colNum = divmod(num, cols) - - figBottom = top - (rowNum+1)*figH - rowNum*sepH - figLeft = left + colNum*(figW + sepW) - - self.figbox = mtransforms.Bbox.from_bounds(figLeft, figBottom, - figW, figH) - -class AxesDivider(Divider): - - - def __init__(self, axes): - self._axes = axes - self._xref = Size.AxesX(axes) - self._yref = Size.AxesY(axes) - Divider.__init__(self, fig=axes.get_figure(), pos=None, - horizontal=[self._xref], vertical=[self._yref], - aspect=None, anchor="C") - - def new_horizontal(self, size, pad=None, pack_start=False): - - if pad: - if not isinstance(pad, Size._Base): - pad = Size.from_any(pad, - fraction_ref=self._xref) - if pack_start: - self._horizontal.insert(0, pad) - self._xrefindex += 1 - else: - self._horizontal.append(pad) - - if not isinstance(size, Size._Base): - size = Size.from_any(size, - fraction_ref=self._xref) - - if pack_start: - self._horizontal.insert(0, pad) - self._xrefindex += 1 - locator = self.new_locator(nx=0, ny=0) - else: - self._horizontal.append(size) - locator = self.new_locator(nx=len(self._horizontal)-1, ny=0) - - ax = LocatableAxes(self._axes.get_figure(), - self._axes.get_position(original=True)) - locator = self.new_locator(nx=len(self._horizontal)-1, ny=0) - ax.set_axes_locator(locator) - - return ax - - def new_vertical(self, size, pad=None, pack_start=False): - - if pad: - if not isinstance(pad, Size._Base): - pad = Size.from_any(pad, - fraction_ref=self._yref) - if pack_start: - self._vertical.insert(0, pad) - self._yrefindex += 1 - else: - self._vertical.append(pad) - - if not isinstance(size, Size._Base): - size = Size.from_any(size, - fraction_ref=self._yref) - - if pack_start: - self._vertical.insert(0, pad) - self._yrefindex += 1 - locator = self.new_locator(nx=0, ny=0) - else: - self._vertical.append(size) - locator = self.new_locator(nx=0, ny=len(self._vertical)-1) - - ax = LocatableAxes(self._axes.get_figure(), - self._axes.get_position(original=True)) - ax.set_axes_locator(locator) - - return ax - - - def get_aspect(self): - if self._aspect is None: - aspect = self._axes.get_aspect() - if aspect == "auto": - return False - else: - return True - else: - return self._aspect - - def get_position(self): - if self._pos is None: - bbox = self._axes.get_position(original=True) - return bbox.bounds - else: - return self._pos - - def get_anchor(self): - if self._anchor is None: - return self._axes.get_anchor() - else: - return self._anchor - - - -class LocatableAxesBase: - def __init__(self, *kl, **kw): - - self._axes_class.__init__(self, *kl, **kw) - - self._locator = None - self._locator_renderer = None - - def set_axes_locator(self, locator): - self._locator = locator - - def get_axes_locator(self): - return self._locator - - def apply_aspect(self, position=None): - - if self.get_axes_locator() is None: - self._axes_class.apply_apsect(self, position) - else: - pos = self.get_axes_locator()(self, self._locator_renderer) - self._axes_class.apply_aspect(self, position=pos) - - - def draw(self, renderer=None, inframe=False): - - self._locator_renderer = renderer - - self._axes_class.draw(self, renderer, inframe) - - - -_locatableaxes_classes = {} -def locatable_axes_factory(axes_class): - - new_class = _locatableaxes_classes.get(axes_class) - if new_class is None: - new_class = new.classobj("Locatable%s" % (axes_class.__name__), - (LocatableAxesBase, axes_class), - {'_axes_class': axes_class}) - _locatableaxes_classes[axes_class] = new_class - - return new_class - -if hasattr(maxes.Axes, "get_axes_locator"): - LocatableAxes = maxes.Axes -else: - LocatableAxes = locatable_axes_factory(maxes.Axes) - - -def make_axes_locatable(axes): - if not hasattr(axes, "set_axes_locator"): - new_class = locatable_axes_factory(type(axes)) - axes.__class__ = new_class - - divider = AxesDivider(axes) - locator = divider.new_locator(nx=0, ny=0) - axes.set_axes_locator(locator) - - return divider - - -def get_demo_image(): - # prepare image - delta = 0.5 - - extent = (-3,4,-4,3) - import numpy as np - x = np.arange(-3.0, 4.001, delta) - y = np.arange(-4.0, 3.001, delta) - X, Y = np.meshgrid(x, y) - import matplotlib.mlab as mlab - Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) - Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) - Z = (Z1 - Z2) * 10 - - return Z, extent - -def demo_locatable_axes(): - import matplotlib.pyplot as plt - - fig1 = plt.figure(1, (6, 6)) - fig1.clf() - - ## PLOT 1 - # simple image & colorbar - ax = fig1.add_subplot(2, 2, 1) - - Z, extent = get_demo_image() - - im = ax.imshow(Z, extent=extent, interpolation="nearest") - cb = plt.colorbar(im) - plt.setp(cb.ax.get_yticklabels(), visible=False) - - - ## PLOT 2 - # image and colorbar whose location is adjusted in the drawing time. - # a hard way - - divider = SubplotDivider(fig1, 2, 2, 2, aspect=True) - - # axes for image - ax = LocatableAxes(fig1, divider.get_position()) - - # axes for coloarbar - ax_cb = LocatableAxes(fig1, divider.get_position()) - - h = [Size.AxesX(ax), # main axes - Size.Fixed(0.05), # padding, 0.1 inch - Size.Fixed(0.2), # colorbar, 0.3 inch - ] - - v = [Size.AxesY(ax)] - - divider.set_horizontal(h) - divider.set_vertical(v) - - ax.set_axes_locator(divider.new_locator(nx=0, ny=0)) - ax_cb.set_axes_locator(divider.new_locator(nx=2, ny=0)) - - fig1.add_axes(ax) - fig1.add_axes(ax_cb) - - ax_cb.yaxis.set_ticks_position("right") - - Z, extent = get_demo_image() - - im = ax.imshow(Z, extent=extent, interpolation="nearest") - plt.colorbar(im, cax=ax_cb) - plt.setp(ax_cb.get_yticklabels(), visible=False) - - plt.draw() - #plt.colorbar(im, cax=ax_cb) - - - ## PLOT 3 - # image and colorbar whose location is adjusted in the drawing time. - # a easy way - - ax = fig1.add_subplot(2, 2, 3) - divider = make_axes_locatable(ax) - - ax_cb = divider.new_horizontal(size="5%", pad=0.05) - fig1.add_axes(ax_cb) - - im = ax.imshow(Z, extent=extent, interpolation="nearest") - plt.colorbar(im, cax=ax_cb) - plt.setp(ax_cb.get_yticklabels(), visible=False) - - - ## PLOT 4 - # two images side by sied with fixed padding. - - ax = fig1.add_subplot(2, 2, 4) - divider = make_axes_locatable(ax) - - ax2 = divider.new_horizontal(size="100%", pad=0.05) - fig1.add_axes(ax2) - - ax.imshow(Z, extent=extent, interpolation="nearest") - ax2.imshow(Z, extent=extent, interpolation="nearest") - plt.setp(ax2.get_yticklabels(), visible=False) - plt.draw() - plt.show() - - -def demo_fixed_size_axes(): - import matplotlib.pyplot as plt - - fig2 = plt.figure(2, (6, 6)) - - # The first items are for padding and the second items are for the axes. - # sizes are in inch. - h = [Size.Fixed(1.0), Size.Fixed(4.5)] - v = [Size.Fixed(0.7), Size.Fixed(5.)] - - divider = Divider(fig2, (0.0, 0.0, 1., 1.), h, v, aspect=False) - # the width and height of the rectangle is ignored. - - ax = LocatableAxes(fig2, divider.get_position()) - ax.set_axes_locator(divider.new_locator(nx=1, ny=1)) - - fig2.add_axes(ax) - - ax.plot([1,2,3]) - - plt.draw() - plt.show() - #plt.colorbar(im, cax=ax_cb) - - - - - -if __name__ == "__main__": - demo_locatable_axes() - demo_fixed_size_axes() Deleted: trunk/matplotlib/examples/pylab_examples/axes_grid.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/axes_grid.py 2009-04-17 20:40:58 UTC (rev 7051) +++ trunk/matplotlib/examples/pylab_examples/axes_grid.py 2009-04-18 16:02:56 UTC (rev 7052) @@ -1,343 +0,0 @@ -import matplotlib.cbook as cbook - -import matplotlib.pyplot as plt - -from axes_divider import Size, SubplotDivider, LocatableAxes, Divider, get_demo_image - -class AxesGrid(object): - - def __init__(self, fig, rect, - nrows_ncols, - ngrids = None, - direction="row", - axes_pad = 0.02, - axes_class=None, - add_all=True, - share_all=False, - aspect=True, - label_mode="L", - colorbar_mode=None, - colorbar_location="right", - colorbar_pad=None, - colorbar_size="5%", - ): - - self._nrows, self._ncols = nrows_ncols - - if ngrids is None: - ngrids = self._nrows * self._ncols - else: - if (ngrids > self._nrows * self._ncols) or (ngrids <= 0): - raise Exception("") - - self.ngrids = ngrids - - self._axes_pad = axes_pad - - self._colorbar_mode = colorbar_mode - self._colorbar_location = colorbar_location - if colorbar_pad is None: - self._colorbar_pad = axes_pad - else: - self._colorbar_pad = colorbar_pad - - self._colorbar_size = colorbar_size - - if direction not in ["column", "row"]: - raise Exception("") - - self._direction = direction - - - if axes_class is None: - axes_class = LocatableAxes - - - self.axes_all = [] - self.axes_column = [[] for i in range(self._ncols)] - self.axes_row = [[] for i in range(self._nrows)] - - self.cbar_axes = [] - - h = [] - v = [] - if cbook.is_string_like(rect) or cbook.is_numlike(rect): - self._divider = SubplotDivider(fig, rect, horizontal=h, vertical=v, - aspect=aspect) - elif len(rect) == 3: - kw = dict(horizontal=h, vertical=v, aspect=aspect) - self._divider = SubplotDivider(fig, *rect, **kw) - elif len(rect) == 4: - self._divider = Divider(fig, rect, horizontal=h, vertical=v, - aspect=aspect) - else: - raise Exception("") - - - rect = self._divider.get_position() - - # reference axes - self._column_refax = [None for i in range(self._ncols)] - self._row_refax = [None for i in range(self._nrows)] - self._refax = None - - for i in range(self.ngrids): - - col, row = self.get_col_row(i) - - if share_all: - sharex = self._refax - sharey = self._refax - else: - sharex = self._column_refax[col] - sharey = self._row_refax[row] - - ax = axes_class(fig, rect, sharex=sharex, sharey=sharey) - - if share_all: - if self._refax is None: - self._refax = ax - else: - if sharex is None: - self._column_refax[col] = ax - if sharey is None: - self._row_refax[row] = ax - - self.axes_all.append(ax) - self.axes_column[col].append(ax) - self.axes_row[row].append(ax) - - cax = axes_class(fig, rect) - self.cbar_axes.append(cax) - - self.axes_llc = self.axes_column[0][-1] - - self._update_locators() - - if add_all: - for ax in self.axes_all+self.cbar_axes: - fig.add_axes(ax) - - self.set_label_mode(label_mode) - - - def _update_locators(self): - - h = [] - - h_ax_pos = [] - h_cb_pos = [] - for ax in self._column_refax: - if h: h.append(Size.Fixed(self._axes_pad)) - - h_ax_pos.append(len(h)) - - if ax: - sz = Size.AxesX(ax) - else: - sz = Size.AxesX(self.axes_llc) - h.append(sz) - - if self._colorbar_mode == "each" and self._colorbar_location == "right": - h.append(Size.from_any(self._colorbar_pad, sz)) - h_cb_pos.append(len(h)) - h.append(Size.from_any(self._colorbar_size, sz)) - - - v = [] - - v_ax_pos = [] - v_cb_pos = [] - for ax in self._row_refax[::-1]: - if v: v.append(Size.Fixed(self._axes_pad)) - v_ax_pos.append(len(v)) - if ax: - sz = Size.AxesY(ax) - else: - sz = Size.AxesY(self.axes_llc) - v.append(sz) - - - if self._colorbar_mode == "each" and self._colorbar_location == "top": - v.append(Size.from_any(self._colorbar_pad, sz)) - v_cb_pos.append(len(v)) - v.append(Size.from_any(self._colorbar_size, sz)) - - - for i in range(self.ngrids): - col, row = self.get_col_row(i) - #locator = self._divider.new_locator(nx=4*col, ny=2*(self._nrows - row - 1)) - locator = self._divider.new_locator(nx=h_ax_pos[col], - ny=v_ax_pos[self._nrows -1 - row]) - self.axes_all[i].set_axes_locator(locator) - - if self._colorbar_mode == "each": - if self._colorbar_location == "right": - locator = self._divider.new_locator(nx=h_cb_pos[col], - ny=v_ax_pos[self._nrows -1 - row]) - elif self._colorbar_location == "top": - locator = self._divider.new_locator(nx=h_ax_pos[col], - ny=v_cb_pos[self._nrows -1 - row]) - self.cbar_axes[i].set_axes_locator(locator) - - - if self._colorbar_mode == "single": - if self._colorbar_location == "right": - sz = Size.Fraction(Size.AxesX(self.axes_llc), self._nrows) - h.append(Size.from_any(self._colorbar_pad, sz)) - h.append(Size.from_any(self._colorbar_size, sz)) - locator = self._divider.new_locator(nx=-2, ny=0, ny1=-1) - elif self._colorbar_location == "top": - sz = Size.Fraction(Size.AxesY(self.axes_llc), self._ncols) - v.append(Size.from_any(self._colorbar_pad, sz)) - v.append(Size.from_any(self._colorbar_size, sz)) - locator = self._divider.new_locator(nx=0, nx1=-1, ny=-2) - for i in range(self.ngrids): - self.cbar_axes[i].set_visible(False) - self.cbar_axes[0].set_axes_locator(locator) - self.cbar_axes[0].set_visible(True) - elif self._colorbar_mode == "each": - for i in range(self.ngrids): - self.cbar_axes[i].set_visible(True) - else: - for i in range(self.ngrids): - self.cbar_axes[i].set_visible(False) - - self._divider.set_horizontal(h) - self._divider.set_vertical(v) - - - - def get_col_row(self, n): - if self._direction == "column": - col, row = divmod(n, self._nrows) - else: - row, col = divmod(n, self._ncols) - - return col, row - - - def __getitem__(self, i): - return self.axes_all[i] - - - def get_geometry(self): - return self._nrows, self._ncols - - def set_axes_pad(self, axes_pad): - self._axes_pad = axes_pad - - def get_axes_pad(self): - return self._axes_pad - - def set_aspect(self, aspect): - self._divider.set_aspect(aspect) - - def get_aspect(self): - return self._divider.get_aspect() - - def set_label_mode(self, mode): - if mode == "all": - for ax in self.axes_all: - [l.set_visible(True) for l in ax.get_xticklabels()] - [l.set_visible(True) for l in ax.get_yticklabels()] - elif mode == "L": - for ax in self.axes_column[0][:-1]: - [l.set_visible(False) for l in ax.get_xticklabels()] - [l.set_visible(True) for l in ax.get_yticklabels()] - ax = self.axes_column[0][-1] - [l.set_visible(True) for l in ax.get_xticklabels()] - [l.set_visible(True) for l in ax.get_yticklabels()] - for col in self.axes_column[1:]: - for ax in col[:-1]: - [l.set_visible(False) for l in ax.get_xticklabels()] - [l.set_visible(False) for l in ax.get_yticklabels()] - ax = col[-1] - [l.set_visible(True) for l in ax.get_xticklabels()] - [l.set_visible(False) for l in ax.get_yticklabels()] - elif mode == "1": - for ax in self.axes_all: - [l.set_visible(False) for l in ax.get_xticklabels()] - [l.set_visible(False) for l in ax.get_yticklabels()] - ax = self.axes_llc - [l.set_visible(True) for l in ax.get_xticklabels()] - [l.set_visible(True) for l in ax.get_yticklabels()] - - - -if __name__ == "__main__": - F = plt.figure(1, (9, 3.5)) - F.clf() - - F.subplots_adjust(left=0.05, right=0.98) - - grid = AxesGrid(F, 131, # similar to subplot(111) - nrows_ncols = (2, 2), - direction="row", - axes_pad = 0.05, - add_all=True, - label_mode = "1", - ) - - Z, extent = get_demo_image() - plt.ioff() - for i in range(4): - im = grid[i].imshow(Z, extent=extent, interpolation="nearest") - - # This only affects axes in first column and second row as share_all = False. - grid.axes_llc.set_xticks([-2, 0, 2]) - grid.axes_llc.set_yticks([-2, 0, 2]) - plt.ion() - - - grid = AxesGrid(F, 132, # similar to subplot(111) - nrows_ncols = (2, 2), - direction="row", - axes_pad = 0.0, - add_all=True, - share_all=True, - label_mode = "1", - colorbar_mode="single", - ) - - Z, extent = get_demo_image() - plt.ioff() - for i in range(4): - im = grid[i].imshow(Z, extent=extent, interpolation="nearest") - plt.colorbar(im, cax = grid.cbar_axes[0]) - plt.setp(grid.cbar_axes[0].get_yticklabels(), visible=False) - - # This affects all axes as share_all = True. - grid.axes_llc.set_xticks([-2, 0, 2]) - grid.axes_llc.set_yticks([-2, 0, 2]) - - plt.ion() - - - - grid = AxesGrid(F, 133, # similar to subplot(122) - nrows_ncols = (2, 2), - direction="row", - axes_pad = 0.1, - add_all=True, - label_mode = "1", - share_all = True, - colorbar_location="top", - colorbar_mode="each", - colorbar_size="7%", - colorbar_pad="2%", - ) - plt.ioff() - for i in range(4): - im = grid[i].imshow(Z, extent=extent, interpolation="nearest") - plt.colorbar(im, cax = grid.cbar_axes[i], - orientation="horizontal") - grid.cbar_axes[i].xaxis.set_ticks_position("top") - plt.setp(grid.cbar_axes[i].get_xticklabels(), visible=False) - - # This affects all axes as share_all = True. - grid.axes_llc.set_xticks([-2, 0, 2]) - grid.axes_llc.set_yticks([-2, 0, 2]) - - plt.ion() - plt.draw() Modified: trunk/matplotlib/lib/matplotlib/offsetbox.py =================================================================== --- trunk/matplotlib/lib/matplotlib/offsetbox.py 2009-04-17 20:40:58 UTC (rev 7051) +++ trunk/matplotlib/lib/matplotlib/offsetbox.py 2009-04-18 16:02:56 UTC (rev 7052) @@ -782,7 +782,8 @@ explicitly specify the bbox_to_anchor. """ - def __init__(self, loc, pad=0.4, borderpad=0.5, + def __init__(self, loc, + pad=0.4, borderpad=0.5, child=None, prop=None, frameon=True, bbox_to_anchor=None, bbox_transform=None): @@ -801,7 +802,6 @@ 'upper center' : 9, 'center' : 10, - pad : pad around the child for drawing a frame. given in fraction of fontsize. @@ -813,12 +813,15 @@ frameon : draw a frame box if True. - bbox_to_anchor : bbox to anchor. If None, use axes.bbox. + bbox_to_anchor : bbox to anchor. Use self.axes.bbox if None. + bbox_transform : with which the bbox_to_anchor will be transformed. + """ super(AnchoredOffsetbox, self).__init__() + self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform) self.set_child(child) self.loc = loc @@ -838,8 +841,6 @@ ) self.patch.set_boxstyle("square",pad=0) self._drawFrame = frameon - #self._parent_bbox = bbox_to_anchor - self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform) @@ -878,13 +879,14 @@ else: transform = self._bbox_to_anchor_transform if transform is None: - transform = BboxTransformTo(self.axes.bbox) + return self._bbox_to_anchor + else: + return TransformedBbox(self._bbox_to_anchor, + transform) + - return TransformedBbox(self._bbox_to_anchor, - transform) - def set_bbox_to_anchor(self, bbox, transform=None): """ set the bbox that the child will be anchored. @@ -892,12 +894,9 @@ *bbox* can be a Bbox instance, a list of [left, bottom, width, height], or a list of [left, bottom] where the width and height will be assumed to be zero. The bbox will be - transformed to display coordinate by the given transform. If - transform is None, axes.transAxes will be use. + transformed to display coordinate by the given transform. """ - if bbox is None: - self._bbox_to_anchor = None - elif isinstance(bbox, BboxBase): + if bbox is None or isinstance(bbox, BboxBase): self._bbox_to_anchor = bbox else: try: Modified: trunk/matplotlib/lib/mpl_toolkits/axes_grid/anchored_artists.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/axes_grid/anchored_artists.py 2009-04-17 20:40:58 UTC (rev 7051) +++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/anchored_artists.py 2009-04-18 16:02:56 UTC (rev 7052) @@ -78,45 +78,3 @@ -if __name__ == "__main__": - import matplotlib.pyplot as plt - from matplotlib.patches import Circle - - #import matplotlib.offsetbox - #matplotlib.offsetbox.DEBUG=False - - #ax = plt.subplot(1,1,1) - plt.clf() - plt.cla() - plt.draw() - ax = plt.gca() - ax.set_aspect(1.) - - at = AnchoredText("Figure 1a", - loc=2, frameon=True) - at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2") - ax.add_artist(at) - - ada = AnchoredDrawingArea(20, 20, 0, 0, - loc=1, pad=0., frameon=False) - p = Circle((10, 10), 10) - ada.da.add_artist(p) - ax.add_artist(ada) - - - as = AnchoredSizeBar(ax, 0.1, r"1$^{\prime}$", - loc=8, - pad=0.1, borderpad=0.5, sep=5, - frameon=False) - ax.add_artist(as) - - - ae = AnchoredEllipse(ax, width=0.1, height=0.15, angle=0., - loc=3, pad=0.5, borderpad=0.4, frameon=True) - - ax.add_artist(ae) - - plt.draw() - plt.show() - - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2009-04-19 14:29:17
|
Revision: 7055 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7055&view=rev Author: jdh2358 Date: 2009-04-19 14:29:07 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Merged revisions 7054 via svnmerge from https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v0_98_5_maint ........ r7054 | jdh2358 | 2009-04-19 09:26:12 -0500 (Sun, 19 Apr 2009) | 1 line force a copy of the colormap input data ........ Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/colors.py Property Changed: ---------------- trunk/matplotlib/ Property changes on: trunk/matplotlib ___________________________________________________________________ Modified: svnmerge-integrated - /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-7042 + /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-7054 Modified: trunk/matplotlib/lib/matplotlib/colors.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colors.py 2009-04-19 14:26:12 UTC (rev 7054) +++ trunk/matplotlib/lib/matplotlib/colors.py 2009-04-19 14:29:07 UTC (rev 7055) @@ -483,7 +483,9 @@ xa = np.array([X]) else: vtype = 'array' - xma = ma.asarray(X) + # force a copy here -- the ma.array and filled functions + # do force a cop of the data by default - JDH + xma = ma.array(X, copy=True) xa = xma.filled(0) mask_bad = ma.getmask(xma) if xa.dtype.char in np.typecodes['Float']: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-04-21 03:13:09
|
Revision: 7056 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7056&view=rev Author: leejjoon Date: 2009-04-21 03:12:53 +0000 (Tue, 21 Apr 2009) Log Message: ----------- Added axes_grid.inset_locator Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/doc/mpl_toolkits/axes_grid/index.rst trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/axes_divider.rst trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/index.rst trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/overview.rst trunk/matplotlib/examples/axes_grid/simple_axes_divider2.py trunk/matplotlib/examples/axes_grid/simple_axes_divider3.py trunk/matplotlib/lib/mpl_toolkits/axes_grid/__init__.py trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_divider.py trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_grid.py Added Paths: ----------- trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/ trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/axes_divider_api.rst trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/axes_grid_api.rst trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/axes_size_api.rst trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/index.rst trunk/matplotlib/examples/axes_grid/inset_locator_demo.py trunk/matplotlib/examples/axes_grid/inset_locator_demo2.py trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_size.py trunk/matplotlib/lib/mpl_toolkits/axes_grid/inset_locator.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-04-19 14:29:07 UTC (rev 7055) +++ trunk/matplotlib/CHANGELOG 2009-04-21 03:12:53 UTC (rev 7056) @@ -1,5 +1,8 @@ ====================================================================== +2009-04-20 Worked on axes_grid documentation. Added + axes_grid.inset_locator. - JJL + 2009-04-17 Initial check-in of the axes_grid toolkit. - JJL 2009-04-17 Added a support for bbox_to_anchor in Added: trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/axes_divider_api.rst =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/axes_divider_api.rst (rev 0) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/axes_divider_api.rst 2009-04-21 03:12:53 UTC (rev 7056) @@ -0,0 +1,18 @@ + +:mod:`mpl_toolkits.axes_grid.axes_divider` +========================================== + +.. autoclass:: mpl_toolkits.axes_grid.axes_divider.Divider + :members: + :undoc-members: + + +.. autoclass:: mpl_toolkits.axes_grid.axes_divider.AxesLocator + :members: + :undoc-members: + +.. autoclass:: mpl_toolkits.axes_grid.axes_divider.SubplotDivider + :members: + +.. autoclass:: mpl_toolkits.axes_grid.axes_divider.AxesDivider + :members: Added: trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/axes_grid_api.rst =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/axes_grid_api.rst (rev 0) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/axes_grid_api.rst 2009-04-21 03:12:53 UTC (rev 7056) @@ -0,0 +1,7 @@ + +:mod:`mpl_toolkits.axes_grid.axes_grid` +======================================= + +.. autoclass:: mpl_toolkits.axes_grid.axes_grid.AxesGrid + :members: + :undoc-members: Added: trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/axes_size_api.rst =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/axes_size_api.rst (rev 0) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/axes_size_api.rst 2009-04-21 03:12:53 UTC (rev 7056) @@ -0,0 +1,6 @@ +:mod:`mpl_toolkits.axes_grid.axes_size` +======================================= + +.. automodule:: mpl_toolkits.axes_grid.axes_size + :members: Fixed, Scaled, AxesX, AxesY, MaxWidth, MaxHeight, Fraction, Padded, from_any + Added: trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/index.rst =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/index.rst (rev 0) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/api/index.rst 2009-04-21 03:12:53 UTC (rev 7056) @@ -0,0 +1,14 @@ +.. _axes_grid-api-index: + +####################################### + The Matplotlib AxesGrid Toolkit API +####################################### + +:Release: |version| +:Date: |today| + +.. toctree:: + + axes_size_api.rst + axes_divider_api.rst + axes_grid_api.rst Modified: trunk/matplotlib/doc/mpl_toolkits/axes_grid/index.rst =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/index.rst 2009-04-19 14:29:07 UTC (rev 7055) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/index.rst 2009-04-21 03:12:53 UTC (rev 7056) @@ -10,7 +10,6 @@ AxesGrid toolkit provides a framework to adjust the position of multiple axes according to their aspects. -.. plot:: mpl_toolkits/axes_grid/figures/demo_axes_grid.py Documentation @@ -20,4 +19,4 @@ :maxdepth: 2 users/index.rst - + api/index.rst Modified: trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/axes_divider.rst =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/axes_divider.rst 2009-04-19 14:29:07 UTC (rev 7055) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/axes_divider.rst 2009-04-21 03:12:53 UTC (rev 7056) @@ -4,15 +4,17 @@ The axes_divider module provide helper classes to adjust the axes positions of set of images in the drawing time. -* *Size* This provides a classese of units that the size of each axes - will be determined. For example, you can specify a fixed size +* :mod:`~mpl_toolkits.axes_grid.axes_size` provides a classese of + units that the size of each axes will be determined. For example, + you can specify a fixed size -* *Divider* this is the class that is used calculates the axes - position. It divides the given renctangular area into several - areas. You intialize the divider by setting the horizontal and - vertical list of sizes that the division will be based on. You then - use the new_locator method, whose return value is a callable object - that can be used to set the axes_locator of the axes. +* :class:`~mpl_toolkits.axes_grid.axes_size.Divider` this is the class + that is used calculates the axes position. It divides the given + renctangular area into several areas. You intialize the divider by + setting the horizontal and vertical list of sizes that the division + will be based on. You then use the new_locator method, whose return + value is a callable object that can be used to set the axes_locator + of the axes. You first initialize the divider by specifying its grids, i.e., horiz and vert. @@ -25,10 +27,11 @@ divider = Divider(fig, rect, horiz, vert) where, rect is a bounds of the box that will be divided and h0,..h3, -v0,..v2 need to be an callable object that returns a tuple of two -floats. The first float is the relative size, and the second float is -the absolute size. Use of the subclasses contained in the Size class -is recommanded. Lets' consider a following grid. +v0,..v2 need to be an instance of classes in the +:mod:`~mpl_toolkits.axes_grid.axes_size`. They have *get_size* method +that returns a tuple of two floats. The first float is the relative +size, and the second float is the absolute size. Consider a following +grid. +-----+-----+-----+-----+ | v0 | | | | @@ -39,34 +42,34 @@ +-----+-----+-----+-----+ -* h0 => 2, 0 -* h1 => 0, 2 -* h2 => 0, 3 +* v0 => 0, 2 +* v1 => 2, 0 +* v2 => 3, 0 The height of the bottom row is always 2 (axes_divider internally assumes that the unit is inch). The first and the second rows with -height ration of 2:3. For example, if the total height of the grid 6, -the the first and second row will each occupy 2/(2+3) and 3/(2+3) of +height ratio of 2:3. For example, if the total height of the grid 6, +then the first and second row will each occupy 2/(2+3) and 3/(2+3) of (6-1) inches. The widths of columns (horiz) will be similarly determined. When aspect ratio is set, the total height (or width) will be adjusted accordingly. -The Size class is a container class that contains several sub-class +The :mod:`mpl_toolkits.axes_grid.axes_size` contains several classes that can be used to set the horiz and vert. For example, for the vertical configuration above will be:: - from Size import Fixed, Scaled + from mpl_toolkits.axes_grid.axes_size import Fixed, Scaled vert = [Fixed(2), Scaled(2), Scaled(3)] -After you set up the divider object, you -Then you create a locator instance which will be given to the axes.:: +After you set up the divider object, then you create a locator +instance which will be given to the axes.:: locator = divider.new_locator(nx=0, ny=1) ax.set_axes_locator(locator) The return value of the new_locator method is a instance of the -AxesLocator class. It is a callable object that will return the +AxesLocator class. It is a callable object that returns the location and size of the cell at the first column and the second row. You may create a locator that spans over multiple cells.:: Modified: trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/index.rst =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/index.rst 2009-04-19 14:29:07 UTC (rev 7055) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/index.rst 2009-04-21 03:12:53 UTC (rev 7056) @@ -10,3 +10,4 @@ .. toctree:: overview.rst + axes_divider.rst Modified: trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/overview.rst =================================================================== --- trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/overview.rst 2009-04-19 14:29:07 UTC (rev 7055) +++ trunk/matplotlib/doc/mpl_toolkits/axes_grid/users/overview.rst 2009-04-21 03:12:53 UTC (rev 7056) @@ -1,6 +1,6 @@ -================= -AxesGrid Overview -================= +======== +Overview +======== The matplotlib AxesGrid toolkit is a collection of helper classes, mainly to ease displaying (multiple) images in matplotlib. @@ -347,3 +347,44 @@ :include-source: +InsetLocator +============ + +:mod:`mpl_toolkits.axes_grid.inset_locator` provides helper classes +and functions to place your (inset) axes at the anchored position of +the parent axes, similarly to AnchoredArtis. + +Using :func:`mpl_toolkits.axes_grid.inset_locator.inset_axes`, you +can have inset axes whose size is either fixed, or a fixed proportion +of the parent axes. For example,:: + + inset_axes = inset_axes(parent_axes, + width="30%", # width = 30% of parent_bbox + height=1., # height : 1 inch + loc=3) + +creates an inset axes whose width is 30% of the parent axes and whose +height is fixed at 1 inch. + +You may creates your inset whose size is determined so that the data +scale of the inset axes to be that of the parent axes multiplied by +some factor. For example, :: + + inset_axes = zoomed_inset_axes(ax, + 0.5, # zoom = 0.5 + loc=1) + +creates an inset axes whose data scale is half of the parent axes. +Here is complete examples. + +.. plot:: mpl_toolkits/axes_grid/figures/inset_locator_demo.py + +For example, :func:`zoomed_inset_axes` can be used when you want the +inset represents the zoom-up of the small portion in the parent axes. +And :mod:`~mpl_toolkits/axes_grid/inset_locator` provides a helper +function :func:`mark_inset` to mark the location of the area +represented by the inset axes. + +.. plot:: mpl_toolkits/axes_grid/figures/inset_locator_demo2.py + :include-source: + Added: trunk/matplotlib/examples/axes_grid/inset_locator_demo.py =================================================================== --- trunk/matplotlib/examples/axes_grid/inset_locator_demo.py (rev 0) +++ trunk/matplotlib/examples/axes_grid/inset_locator_demo.py 2009-04-21 03:12:53 UTC (rev 7056) @@ -0,0 +1,45 @@ +import matplotlib.pyplot as plt + +from mpl_toolkits.axes_grid.inset_locator import inset_axes, zoomed_inset_axes +from mpl_toolkits.axes_grid.anchored_artists import AnchoredSizeBar + + +def add_sizebar(ax, size): + as = AnchoredSizeBar(ax.transData, + size, + str(size), + loc=8, + pad=0.1, borderpad=0.5, sep=5, + frameon=False) + ax.add_artist(as) + + +fig = plt.figure(1, [5.5, 3]) + +# first subplot +ax = fig.add_subplot(1,2,1) +ax.set_aspect(1.) + +axins = inset_axes(ax, + width="30%", # width = 30% of parent_bbox + height=1., # height : 1 inch + loc=3) + +plt.xticks(visible=False) +plt.yticks(visible=False) + + +# second subplot +ax = fig.add_subplot(1,2,2) +ax.set_aspect(1.) + +axins = zoomed_inset_axes(ax, 0.5, loc=1) # zoom = 0.5 + +plt.xticks(visible=False) +plt.yticks(visible=False) + +add_sizebar(ax, 0.5) +add_sizebar(axins, 0.5) + +plt.draw() +plt.show() Added: trunk/matplotlib/examples/axes_grid/inset_locator_demo2.py =================================================================== --- trunk/matplotlib/examples/axes_grid/inset_locator_demo2.py (rev 0) +++ trunk/matplotlib/examples/axes_grid/inset_locator_demo2.py 2009-04-21 03:12:53 UTC (rev 7056) @@ -0,0 +1,42 @@ +import matplotlib.pyplot as plt + +from mpl_toolkits.axes_grid.inset_locator import zoomed_inset_axes +from mpl_toolkits.axes_grid.inset_locator import mark_inset + +import numpy as np + +from demo_image import get_demo_image + + +fig = plt.figure(1, [5,4]) +ax = fig.add_subplot(111) + +# prepare the demo image +Z, extent = get_demo_image() +Z2 = np.zeros([150, 150], dtype="d") +ny, nx = Z.shape +Z2[30:30+ny, 30:30+nx] = Z + +# extent = [-3, 4, -4, 3] +ax.imshow(Z2, extent=extent, interpolation="nearest", + origin="lower") + +axins = zoomed_inset_axes(ax, 6, loc=1) # zoom = 6 +axins.imshow(Z2, extent=extent, interpolation="nearest", + origin="lower") + +# sub region of the original image +x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9 +axins.set_xlim(x1, x2) +axins.set_ylim(y1, y2) + +plt.xticks(visible=False) +plt.yticks(visible=False) + +# draw a bbox of the region of the inset axes in the parent axes and +# connecting lines between the bbox and the inset axes area +mark_inset(ax, axins, loc1=2, loc2=4, fc="none", ec="0.5") + +plt.draw() +plt.show() + Modified: trunk/matplotlib/examples/axes_grid/simple_axes_divider2.py =================================================================== --- trunk/matplotlib/examples/axes_grid/simple_axes_divider2.py 2009-04-19 14:29:07 UTC (rev 7055) +++ trunk/matplotlib/examples/axes_grid/simple_axes_divider2.py 2009-04-21 03:12:53 UTC (rev 7056) @@ -1,4 +1,5 @@ -from mpl_toolkits.axes_grid import Size, Divider +import mpl_toolkits.axes_grid.axes_size as Size +from mpl_toolkits.axes_grid import Divider import matplotlib.pyplot as plt fig1 = plt.figure(1, (5.5, 4.)) Modified: trunk/matplotlib/examples/axes_grid/simple_axes_divider3.py =================================================================== --- trunk/matplotlib/examples/axes_grid/simple_axes_divider3.py 2009-04-19 14:29:07 UTC (rev 7055) +++ trunk/matplotlib/examples/axes_grid/simple_axes_divider3.py 2009-04-21 03:12:53 UTC (rev 7056) @@ -1,4 +1,5 @@ -from mpl_toolkits.axes_grid import Size, Divider +import mpl_toolkits.axes_grid.axes_size as Size +from mpl_toolkits.axes_grid import Divider import matplotlib.pyplot as plt Modified: trunk/matplotlib/lib/mpl_toolkits/axes_grid/__init__.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/axes_grid/__init__.py 2009-04-19 14:29:07 UTC (rev 7055) +++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/__init__.py 2009-04-21 03:12:53 UTC (rev 7056) @@ -3,7 +3,8 @@ """ -from axes_divider import Divider, SubplotDivider, LocatableAxes, Size, \ +from axes_divider import Divider, SubplotDivider, LocatableAxes, \ make_axes_locatable from axes_grid import AxesGrid +#from axes_divider import make_axes_locatable Modified: trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_divider.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_divider.py 2009-04-19 14:29:07 UTC (rev 7055) +++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_divider.py 2009-04-21 03:12:53 UTC (rev 7056) @@ -1,189 +1,56 @@ """ -The axes_divider module provide helper classes to adjust the axes -positions of set of images in the drawing time. +The axes_divider module provide helper classes to adjust the positions of +multiple axes at the drawing time. - Size: This provides a classese of units that the size of each axes - will be determined. For example, you can specify a fixed size - - Divider: this is the class that uis used calculates the axes - position. It divides the given renctangular area into several - areas. You intialize the divider by setting the horizontal and - vertical list of sizes that the division will be based on. You + Divider: this is the class that is used calculates the axes + position. It divides the given renctangular area into several sub + rectangles. You intialize the divider by setting the horizontal + and vertical list of sizes that the division will be based on. You then use the new_locator method, whose return value is a callable object that can be used to set the axes_locator of the axes. """ -import matplotlib.axes as maxes import matplotlib.transforms as mtransforms -import matplotlib.cbook as cbook from matplotlib.axes import SubplotBase import new +import axes_size as Size -class Size(object): - """ - provides a classese of units that will be used with AxesDivider - class (or others) to determine the size of each axes. The unit - classes define __call__ that returns a tuple of two floats, - meaning relative and absolute sizes, respectively. - Note that this class is nothing more than a simple tuple of two - floats. Take a look at the Divider class to see how these two - values are used. - +class Divider(object): """ + This is the class that is used calculates the axes position. It + divides the given renctangular area into several + sub-rectangles. You intialize the divider by setting the + horizontal and vertical lists of sizes + (:mod:`mpl_toolkits.axes_grid.axes_size`) that the division will + be based on. You then use the new_locator method to create a + callable object that can be used to as the axes_locator of the + axes. + """ - class _Base(object): - "Base class" - pass - - class Fixed(_Base): - "Simple fixed size with relative part = 0" - def __init__(self, fixed_size): - self._fixed_size = fixed_size - - def get_size(self, renderer): - rel_size = 0. - abs_size = self._fixed_size - return rel_size, abs_size - - class Scaled(_Base): - "Simple scaled(?) size with absolute part = 0" - def __init__(self, scalable_size): - self._scalable_size = scalable_size - - def get_size(self, renderer): - rel_size = self._scalable_size - abs_size = 0. - return rel_size, abs_size - - Scalable=Scaled - - class AxesX(_Base): + + def __init__(self, fig, pos, horizontal, vertical, aspect=None, anchor="C"): """ - Scaled size whose relative part corresponds to the data width - of the given axes + :param fig: matplotlib figure + :param pos: position (tuple of 4 floats) of the rectangle that + will be divided. + :param horizontal: list of sizes + (:mod:`~mpl_toolkits.axes_grid.axes_size`) + for horizontal division + :param vertical: list of sizes + (:mod:`~mpl_toolkits.axes_grid.axes_size`) + for vertical division + :param aspect: if True, the overall rectalngular area is reduced + so that the relative part of the horizontal and + vertical scales have same scale. + :param anchor: Detrmine how the reduced rectangle is placed + when aspect is True, """ - def __init__(self, axes, aspect=1.): - self._axes = axes - self._aspect = aspect - - def get_size(self, renderer): - l1, l2 = self._axes.get_xlim() - rel_size = abs(l2-l1)*self._aspect - abs_size = 0. - return rel_size, abs_size - - class AxesY(_Base): - """ - Scaled size whose relative part corresponds to the data height - of the given axes - """ - def __init__(self, axes, aspect=1.): - self._axes = axes - self._aspect = aspect - - def get_size(self, renderer): - l1, l2 = self._axes.get_ylim() - rel_size = abs(l2-l1)*self._aspect - abs_size = 0. - return rel_size, abs_size - - - class MaxExtent(_Base): - """ - Size whose absolute part is the largest width (or height) of - the given list of artists. - """ - def __init__(self, artist_list, w_or_h): - self._artist_list = artist_list - - if w_or_h not in ["width", "height"]: - raise ValueError() - - self._w_or_h = w_or_h - - def add_artist(self, a): - self._artist_list.append(a) - - def get_size(self, renderer): - rel_size = 0. - w_list, h_list = [], [] - for a in self._artist_list: - bb = a.get_window_extent(renderer) - w_list.append(bb.width) - h_list.append(bb.height) - dpi = a.get_figure().get_dpi() - if self._w_or_h == "width": - abs_size = max(w_list)/dpi - elif self._w_or_h == "height": - abs_size = max(h_list)/dpi - - return rel_size, abs_size - - class Fraction(_Base): - """ - An instance whose size is a fraction of the reference size. - ex) s = Fraction(0.3, AxesX(ax)) - """ - def __init__(self, fraction, fraction_ref): - self._fraction_ref = fraction_ref - self._fraction = fraction - - def get_size(self, renderer): - if self._fraction_ref is None: - return self._fraction, 0. - else: - r, a = self._fraction_ref.get_size(renderer) - rel_size = r*self._fraction - abs_size = a*self._fraction - return rel_size, abs_size - - @classmethod - def from_any(self, size, fraction_ref=None): - """ - Creates Fixed unit when the first argument is a float, or a - Fraction unit if that is a string that ends with %. The second - argument is only meaningful when Fraction unit is created. - - >>> a = Size.from_any(1.2) # => Size.Fixed(1.2) - >>> Size.from_any("50%", a) # => Size.Fraction(0.5, a) - - """ - if cbook.is_numlike(size): - return Size.Fixed(size) - elif cbook.is_string_like(size): - if size[-1] == "%": - return Size.Fraction(float(size[:-1])/100., fraction_ref) - - raise ValueError("Unknown format") - - - - class Padded(_Base): - """ - Return a instance where the absolute part of *size* is - increase by the amount of *pad*. - """ - def __init__(self, size, pad): - self._size = size - self._pad = pad - - def get_size(self, renderer): - r, a = self._size.get_size(renderer) - rel_size = r - abs_size = a + self._pad - return rel_size, abs_size - - - - -class Divider(object): - - def __init__(self, fig, pos, horizontal, vertical, aspect=None, anchor="C"): + self._fig = fig self._pos = pos self._horizontal = horizontal @@ -224,14 +91,21 @@ def set_position(self, pos): + """ + set the position of the rectangle. + + :param pos: position (tuple of 4 floats) of the rectangle that + will be divided. + """ self._pos = pos def get_position(self): + "return the position of the rectangle." return self._pos def set_anchor(self, anchor): """ - *anchor* + :param anchor: anchor position ===== ============ value description @@ -254,43 +128,56 @@ raise ValueError('argument must be among %s' % ', '.join(mtransforms.BBox.coefs.keys())) + def get_anchor(self): + "return the anchor" + return self._anchor def set_horizontal(self, h): + """ + :param horizontal: list of sizes + (:mod:`~mpl_toolkits.axes_grid.axes_size`) + for horizontal division + """ self._horizontal = h + def get_horizontal(self): + "return horizontal sizes" return self._horizontal def set_vertical(self, v): + """ + :param horizontal: list of sizes + (:mod:`~mpl_toolkits.axes_grid.axes_size`) + for horizontal division + """ self._vertical = v def get_vertical(self): + "return vertical sizes" return self._vertical - def get_anchor(self): - return self._anchor - - def set_aspect(self, aspect=False): """ - *aspect* : True or False + :param anchor: True or False """ self._aspect = aspect def get_aspect(self): + "return aspect" return self._aspect def locate(self, nx, ny, nx1=None, ny1=None, renderer=None): """ - nx, nx1 : Integers specifying the column-position of the - cell. When nx1 is None, a single nx-th column is - specified. Otherwise location of columns spanning between nx - to nx1 (but excluding nx1-th column) is is specified. + :param nx, nx1: Integers specifying the column-position of the + cell. When nx1 is None, a single nx-th column is + specified. Otherwise location of columns spanning between nx + to nx1 (but excluding nx1-th column) is specified. - ny, ny1 : same as nx and nx1, but for row positions. + :param ny, ny1: same as nx and nx1, but for row positions. """ @@ -330,6 +217,18 @@ def new_locator(self, nx, ny, nx1=None, ny1=None): + """ + returns a new locator + (:class:`mpl_toolkits.axes_grid.axes_divider.AxesLocator`) for + specified cell. + + :param nx, nx1: Integers specifying the column-position of the + cell. When nx1 is None, a single nx-th column is + specified. Otherwise location of columns spanning between nx + to nx1 (but excluding nx1-th column) is specified. + + :param ny, ny1: same as nx and nx1, but for row positions. + """ return AxesLocator(self, nx, ny, nx1, ny1) @@ -341,14 +240,14 @@ """ def __init__(self, axes_divider, nx, ny, nx1=None, ny1=None): """ - 'axes_divider' : An instance of AxesDivider class. + :param axes_divider: An instance of AxesDivider class. - nx, nx1 : Integers specifying the column-position of the - cell. When nx1 is None, a single nx-th column is - specified. Otherwise location of columns spanning between nx - to nx1 (but excluding nx1-th column) is is specified. + :param nx, nx1: Integers specifying the column-position of the + cell. When nx1 is None, a single nx-th column is + specified. Otherwise location of columns spanning between nx + to nx1 (but excluding nx1-th column) is is specified. - ny, ny1 : same as nx and nx1, but for row positions. + :param ny, ny1: same as nx and nx1, but for row positions. """ self._axes_divider = axes_divider @@ -371,14 +270,20 @@ _xrefindex = self._axes_divider._xrefindex _yrefindex = self._axes_divider._yrefindex - return self._axes_divider.locate(self._nx + _xrefindex, self._ny + _yrefindex, - self._nx1 + _xrefindex, self._ny1 + _yrefindex, + return self._axes_divider.locate(self._nx + _xrefindex, + self._ny + _yrefindex, + self._nx1 + _xrefindex, + self._ny1 + _yrefindex, renderer) class SubplotDivider(Divider): + """ + The Divider class whose rectangle area is specified as a subplot grometry. + """ + def __init__(self, fig, *args, **kwargs): """ *fig* is a :class:`matplotlib.figure.Figure` instance. @@ -431,6 +336,7 @@ def get_position(self): + "return the bounds of the subplot box" self.update_params() return self.figbox.bounds @@ -468,9 +374,14 @@ class AxesDivider(Divider): + """ + Divider based on the pre-existing axes. + """ - def __init__(self, axes): + """ + :param axes: axes + """ self._axes = axes self._xref = Size.AxesX(axes) self._yref = Size.AxesY(axes) @@ -494,8 +405,27 @@ return ax + def new_horizontal(self, size, pad=None, pack_start=False, **kwargs): + """ + Add a new axes on the right (or left) side of the main axes. + :param size: A width of the axes. A :mod:`~mpl_toolkits.axes_grid.axes_size` + instance or if float or string is given, *from_any* + fucntion is used to create one, with *ref_size* set to AxesX instance + of the current axes. + :param pad: pad between the axes. It takes same argument as *size*. + :param pack_start: If False, the new axes is appended at the end + of the list, i.e., it became the right-most axes. If True, it is + inseted at the start of the list, and becomes the left-most axes. + + All extra keywords argument is passed to when creating a axes. + if *axes_class* is given, the new axes will be created as an + instance of the given class. Otherwise, the same class of the + main axes will be used. if Not provided + + """ + if pad: if not isinstance(pad, Size._Base): pad = Size.from_any(pad, @@ -518,18 +448,32 @@ self._horizontal.append(size) locator = self.new_locator(nx=len(self._horizontal)-1, ny=0) - #axes_class = type(self._axes) ax = self._get_new_axes(**kwargs) - #ax = axes_class(self._axes.get_figure(), - # self._axes.get_position(original=True), - # **kwargs) locator = self.new_locator(nx=len(self._horizontal)-1, ny=0) ax.set_axes_locator(locator) return ax def new_vertical(self, size, pad=None, pack_start=False, **kwargs): + """ + Add a new axes on the top (or bottom) side of the main axes. + :param size: A height of the axes. A :mod:`~mpl_toolkits.axes_grid.axes_size` + instance or if float or string is given, *from_any* + fucntion is used to create one, with *ref_size* set to AxesX instance + of the current axes. + :param pad: pad between the axes. It takes same argument as *size*. + :param pack_start: If False, the new axes is appended at the end + of the list, i.e., it became the top-most axes. If True, it is + inseted at the start of the list, and becomes the bottom-most axes. + + All extra keywords argument is passed to when creating a axes. + if *axes_class* is given, the new axes will be created as an + instance of the given class. Otherwise, the same class of the + main axes will be used. if Not provided + + """ + if pad: if not isinstance(pad, Size._Base): pad = Size.from_any(pad, @@ -553,10 +497,6 @@ locator = self.new_locator(nx=0, ny=len(self._vertical)-1) ax = self._get_new_axes(**kwargs) - #axes_class = type(self._axes) - #ax = axes_class(self._axes.get_figure(), - # self._axes.get_position(original=True), - # **kwargs) ax.set_axes_locator(locator) return ax @@ -650,3 +590,138 @@ return divider +def get_demo_image(): + # prepare image + delta = 0.5 + + extent = (-3,4,-4,3) + import numpy as np + x = np.arange(-3.0, 4.001, delta) + y = np.arange(-4.0, 3.001, delta) + X, Y = np.meshgrid(x, y) + import matplotlib.mlab as mlab + Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) + Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) + Z = (Z1 - Z2) * 10 + + return Z, extent + +def demo_locatable_axes(): + import matplotlib.pyplot as plt + + fig1 = plt.figure(1, (6, 6)) + fig1.clf() + + ## PLOT 1 + # simple image & colorbar + ax = fig1.add_subplot(2, 2, 1) + + Z, extent = get_demo_image() + + im = ax.imshow(Z, extent=extent, interpolation="nearest") + cb = plt.colorbar(im) + plt.setp(cb.ax.get_yticklabels(), visible=False) + + + ## PLOT 2 + # image and colorbar whose location is adjusted in the drawing time. + # a hard way + + divider = SubplotDivider(fig1, 2, 2, 2, aspect=True) + + # axes for image + ax = LocatableAxes(fig1, divider.get_position()) + + # axes for coloarbar + ax_cb = LocatableAxes(fig1, divider.get_position()) + + h = [Size.AxesX(ax), # main axes + Size.Fixed(0.05), # padding, 0.1 inch + Size.Fixed(0.2), # colorbar, 0.3 inch + ] + + v = [Size.AxesY(ax)] + + divider.set_horizontal(h) + divider.set_vertical(v) + + ax.set_axes_locator(divider.new_locator(nx=0, ny=0)) + ax_cb.set_axes_locator(divider.new_locator(nx=2, ny=0)) + + fig1.add_axes(ax) + fig1.add_axes(ax_cb) + + ax_cb.yaxis.set_ticks_position("right") + + Z, extent = get_demo_image() + + im = ax.imshow(Z, extent=extent, interpolation="nearest") + plt.colorbar(im, cax=ax_cb) + plt.setp(ax_cb.get_yticklabels(), visible=False) + + plt.draw() + #plt.colorbar(im, cax=ax_cb) + + + ## PLOT 3 + # image and colorbar whose location is adjusted in the drawing time. + # a easy way + + ax = fig1.add_subplot(2, 2, 3) + divider = make_axes_locatable(ax) + + ax_cb = divider.new_horizontal(size="5%", pad=0.05) + fig1.add_axes(ax_cb) + + im = ax.imshow(Z, extent=extent, interpolation="nearest") + plt.colorbar(im, cax=ax_cb) + plt.setp(ax_cb.get_yticklabels(), visible=False) + + + ## PLOT 4 + # two images side by sied with fixed padding. + + ax = fig1.add_subplot(2, 2, 4) + divider = make_axes_locatable(ax) + + ax2 = divider.new_horizontal(size="100%", pad=0.05) + fig1.add_axes(ax2) + + ax.imshow(Z, extent=extent, interpolation="nearest") + ax2.imshow(Z, extent=extent, interpolation="nearest") + plt.setp(ax2.get_yticklabels(), visible=False) + plt.draw() + plt.show() + + +def demo_fixed_size_axes(): + import matplotlib.pyplot as plt + + fig2 = plt.figure(2, (6, 6)) + + # The first items are for padding and the second items are for the axes. + # sizes are in inch. + h = [Size.Fixed(1.0), Size.Fixed(4.5)] + v = [Size.Fixed(0.7), Size.Fixed(5.)] + + divider = Divider(fig2, (0.0, 0.0, 1., 1.), h, v, aspect=False) + # the width and height of the rectangle is ignored. + + ax = LocatableAxes(fig2, divider.get_position()) + ax.set_axes_locator(divider.new_locator(nx=1, ny=1)) + + fig2.add_axes(ax) + + ax.plot([1,2,3]) + + plt.draw() + plt.show() + #plt.colorbar(im, cax=ax_cb) + + + + + +if __name__ == "__main__": + demo_locatable_axes() + demo_fixed_size_axes() Modified: trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_grid.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_grid.py 2009-04-19 14:29:07 UTC (rev 7055) +++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_grid.py 2009-04-21 03:12:53 UTC (rev 7056) @@ -53,16 +53,11 @@ ticks, ticklabels, offset_string = self._ticker() if self.orientation == 'vertical': - #ax.set_xticks([]) - #ax.yaxis.set_label_position('right') - #ax.yaxis.set_ticks_position('right') ax.set_yticks(ticks) ax.set_yticklabels(ticklabels) ax.yaxis.get_major_formatter().set_offset_string(offset_string) else: - #ax.set_yticks([]) - #ax.xaxis.set_label_position('bottom') ax.set_xticks(ticks) ax.set_xticklabels(ticklabels) ax.xaxis.get_major_formatter().set_offset_string(offset_string) @@ -150,17 +145,12 @@ class AxesGrid(object): """ - The :class:`Axes` contains most of the figure elements: - :class:`~matplotlib.axis.Axis`, :class:`~matplotlib.axis.Tick`, - :class:`~matplotlib.lines.Line2D`, :class:`~matplotlib.text.Text`, - :class:`~matplotlib.patches.Polygon`, etc., and sets the - coordinate system. - - The :class:`Axes` instance supports callbacks through a callbacks - attribute which is a :class:`~matplotlib.cbook.CallbackRegistry` - instance. The events you can connect to are 'xlim_changed' and - 'ylim_changed' and the callback will be called with func(*ax*) - where *ax* is the :class:`Axes` instance. + A class that creates a grid of Axes. In matplotlib, the axes + location (and size) is specified in the normalized figure + coordinates. This may not be ideal for images that needs to be + displayed with a given aspect ratio. For example, displaying + images of a same size with some fixed padding between them cannot + be easily done in matplotlib. AxesGrid is used in such case. """ def __init__(self, fig, @@ -275,7 +265,7 @@ for i in range(self.ngrids): - col, row = self.get_col_row(i) + col, row = self._get_col_row(i) if share_all: sharex = self._refax @@ -359,7 +349,7 @@ for i in range(self.ngrids): - col, row = self.get_col_row(i) + col, row = self._get_col_row(i) #locator = self._divider.new_locator(nx=4*col, ny=2*(self._nrows - row - 1)) locator = self._divider.new_locator(nx=h_ax_pos[col], ny=v_ax_pos[self._nrows -1 - row]) @@ -406,7 +396,7 @@ - def get_col_row(self, n): + def _get_col_row(self, n): if self._direction == "column": col, row = divmod(n, self._nrows) else: @@ -420,80 +410,57 @@ def get_geometry(self): + """ + get geometry of the grid. Returns a tuple of two integer, + representing number of rows and number of columns. + """ return self._nrows, self._ncols def set_axes_pad(self, axes_pad): + "set axes_pad" self._axes_pad = axes_pad def get_axes_pad(self): + "get axes_pad" return self._axes_pad def set_aspect(self, aspect): + "set aspect" self._divider.set_aspect(aspect) def get_aspect(self): + "get aspect" return self._divider.get_aspect() def set_label_mode(self, mode): + "set label_mode" if mode == "all": for ax in self.axes_all: _tick_only(ax, False, False) - #[l.set_visible(True) for l in ax.get_xticklabels()] - #[l.set_visible(True) for l in ax.get_yticklabels()] elif mode == "L": # left-most axes for ax in self.axes_column[0][:-1]: _tick_only(ax, bottom_on=True, left_on=False) - #[l.set_visible(False) for l in ax.get_xticklabels()] - #[l.set_visible(True) for l in ax.get_yticklabels()] - #if hasattr(ax, "_axislines"): - # ax._axislines["left"].major_ticklabels.set_visible(True) - # ax._axislines["bottom"].major_ticklabels.set_visible(False) # lower-left axes ax = self.axes_column[0][-1] _tick_only(ax, bottom_on=False, left_on=False) - #[l.set_visible(True) for l in ax.get_xticklabels()] - #[l.set_visible(True) for l in ax.get_yticklabels()] - #if hasattr(ax, "_axislines"): - # ax._axislines["left"].major_ticklabels.set_visible(True) - # ax._axislines["bottom"].major_ticklabels.set_visible(True) for col in self.axes_column[1:]: # axes with no labels for ax in col[:-1]: _tick_only(ax, bottom_on=True, left_on=True) - #[l.set_visible(False) for l in ax.get_xticklabels()] - #[l.set_visible(False) for l in ax.get_yticklabels()] - #if hasattr(ax, "_axislines"): - # ax._axislines["left"].major_ticklabels.set_visible(False) - # ax._axislines["bottom"].major_ticklabels.set_visible(False) # bottom ax = col[-1] _tick_only(ax, bottom_on=False, left_on=True) - #[l.set_visible(True) for l in ax.get_xticklabels()] - #[l.set_visible(False) for l in ax.get_yticklabels()] - #if hasattr(ax, "_axislines"): - # ax._axislines["left"].major_ticklabels.set_visible(False) - # ax._axislines["bottom"].major_ticklabels.set_visible(True) elif mode == "1": for ax in self.axes_all: _tick_only(ax, bottom_on=True, left_on=True) - #[l.set_visible(False) for l in ax.get_xticklabels()] - #[l.set_visible(False) for l in ax.get_yticklabels()] - #if hasattr(ax, "_axislines"): - # for axisline in ax._axislines.values(): - # axisline.major_ticklabels.set_visible(False) ax = self.axes_llc _tick_only(ax, bottom_on=False, left_on=False) - #[l.set_visible(True) for l in ax.get_xticklabels()] - #[l.set_visible(True) for l in ax.get_yticklabels()] - #if hasattr(ax, "_axislines"): - # ax._axislines["left"].major_ticklabels.set_visible(True) - # ax._axislines["bottom"].major_ticklabels.set_visible(True) Added: trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_size.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_size.py (rev 0) +++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_size.py 2009-04-21 03:12:53 UTC (rev 7056) @@ -0,0 +1,207 @@ + +""" +provides a classese of simlpe units that will be used with AxesDivider +class (or others) to determine the size of each axes. The unit +classes define `get_size` method that returns a tuple of two floats, +meaning relative and absolute sizes, respectively. + +Note that this class is nothing more than a simple tuple of two +floats. Take a look at the Divider class to see how these two +values are used. + +""" + +import matplotlib.cbook as cbook + + +class _Base(object): + "Base class" + pass + +class Fixed(_Base): + "Simple fixed size with absolute part = *fixed_size* and relative part = 0" + def __init__(self, fixed_size): + self._fixed_size = fixed_size + + def get_size(self, renderer): + rel_size = 0. + abs_size = self._fixed_size + return rel_size, abs_size + +class Scaled(_Base): + "Simple scaled(?) size with absolute part = 0 and relative part = *scalable_size*" + def __init__(self, scalable_size): + self._scalable_size = scalable_size + + def get_size(self, renderer): + rel_size = self._scalable_size + abs_size = 0. + return rel_size, abs_size + +Scalable=Scaled + + +class AxesX(_Base): + """ + Scaled size whose relative part corresponds to the data width + of the *axes* multiplied by the *aspect*. + """ + def __init__(self, axes, aspect=1.): + self._axes = axes + self._aspect = aspect + + def get_size(self, renderer): + l1, l2 = self._axes.get_xlim() + rel_size = abs(l2-l1)*self._aspect + abs_size = 0. + return rel_size, abs_size + +class AxesY(_Base): + """ + Scaled size whose relative part corresponds to the data height + of the *axes* multiplied by the *aspect*. + """ + def __init__(self, axes, aspect=1.): + self._axes = axes + self._aspect = aspect + + def get_size(self, renderer): + l1, l2 = self._axes.get_ylim() + rel_size = abs(l2-l1)*self._aspect + abs_size = 0. + return rel_size, abs_size + + +class MaxExtent(_Base): + """ + Size whose absolute part is the largest width (or height) of + the given *artist_list*. + """ + def __init__(self, artist_list, w_or_h): + self._artist_list = artist_list + + if w_or_h not in ["width", "height"]: + raise ValueError() + + self._w_or_h = w_or_h + + def add_artist(self, a): + self._artist_list.append(a) + + def get_size(self, renderer): + rel_size = 0. + w_list, h_list = [], [] + for a in self._artist_list: + bb = a.get_window_extent(renderer) + w_list.append(bb.width) + h_list.append(bb.height) + dpi = a.get_figure().get_dpi() + if self._w_or_h == "width": + abs_size = max(w_list)/dpi + elif self._w_or_h == "height": + abs_size = max(h_list)/dpi + + return rel_size, abs_size + + +class MaxWidth(_Base): + """ + Size whose absolute part is the largest width of + the given *artist_list*. + """ + def __init__(self, artist_list): + self._artist_list = artist_list + + def add_artist(self, a): + self._artist_list.append(a) + + def get_size(self, renderer): + rel_size = 0. + w_list = [] + for a in self._artist_list: + bb = a.get_window_extent(renderer) + w_list.append(bb.width) + dpi = a.get_figure().get_dpi() + abs_size = max(w_list)/dpi + + return rel_size, abs_size + + + +class MaxHeight(_Base): + """ + Size whose absolute part is the largest height of + the given *artist_list*. + """ + def __init__(self, artist_list): + self._artist_list = artist_list + + def add_artist(self, a): + self._artist_list.append(a) + + def get_size(self, renderer): + rel_size = 0. + h_list = [] + for a in self._artist_list: + bb = a.get_window_extent(renderer) + h_list.append(bb.height) + dpi = a.get_figure().get_dpi() + abs_size = max(h_list)/dpi + + return rel_size, abs_size + + +class Fraction(_Base): + """ + An instance whose size is a *fraction* of the *ref_size*. + + >>> s = Fraction(0.3, AxesX(ax)) + + """ + def __init__(self, fraction, ref_size): + self._fraction_ref = ref_size + self._fraction = fraction + + def get_size(self, renderer): + if self._fraction_ref is None: + return self._fraction, 0. + else: + r, a = self._fraction_ref.get_size(renderer) + rel_size = r*self._fraction + abs_size = a*self._fraction + return rel_size, abs_size + +class Padded(_Base): + """ + Return a instance where the absolute part of *size* is + increase by the amount of *pad*. + """ + def __init__(self, size, pad): + self._size = size + self._pad = pad + + def get_size(self, renderer): + r, a = self._size.get_size(renderer) + rel_size = r + abs_size = a + self._pad + return rel_size, abs_size + +def from_any(size, fraction_ref=None): + """ + Creates Fixed unit when the first argument is a float, or a + Fraction unit if that is a string that ends with %. The second + argument is only meaningful when Fraction unit is created. + + >>> a = Size.from_any(1.2) # => Size.Fixed(1.2) + >>> Size.from_any("50%", a) # => Size.Fraction(0.5, a) + + """ + if cbook.is_numlike(size): + return Fixed(size) + elif cbook.is_string_like(size): + if size[-1] == "%": + return Fraction(float(size[:-1])/100., fraction_ref) + + raise ValueError("Unknown format") + + Added: trunk/matplotlib/lib/mpl_toolkits/axes_grid/inset_locator.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/axes_grid/inset_locator.py (rev 0) +++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/inset_locator.py 2009-04-21 03:12:53 UTC (rev 7056) @@ -0,0 +1,308 @@ +from matplotlib.offsetbox import AnchoredOffsetbox +#from matplotlib.transforms import IdentityTransform + +import matplotlib.transforms as mtrans +from matplotlib.axes import Axes + +from matplotlib.transforms import Bbox, TransformedBbox, IdentityTransform + +from matplotlib.patches import Patch +from matplotlib.path import Path + +from matplotlib.patches import Rectangle + + +class InsetPosition(object): + def __init__(self, parent, lbwh): + self.parent = parent + self.lbwh = lbwh # position of the inset axes in the normalized coordinate of the parent axes + + def __call__(self, ax, renderer): + bbox_parent = self.parent.get_position(original=False) + trans = mtrans.BboxTransformTo(bbox_parent) + bbox_inset = mtrans.Bbox.from_bounds(*self.lbwh) + bb = mtrans.TransformedBbox(bbox_inset, trans) + return bb + + +class AnchoredLocatorBase(AnchoredOffsetbox): + def __init__(self, bbox_to_anchor, offsetbox, loc, + borderpad=0.5, bbox_transform=None): + + super(AnchoredLocatorBase, self).__init__(loc, + pad=0., child=None, + borderpad=borderpad, + bbox_to_anchor=bbox_to_anchor, + bbox_transform=bbox_transform) + + + def draw(self, renderer): + raise RuntimeError("No draw method should be called") + + + def __call__(self, ax, renderer): + + fontsize = renderer.points_to_pixels(self.prop.get_size_in_points()) + self._update_offset_func(renderer, fontsize) + + width, height, xdescent, ydescent = self.get_extent(renderer) + + px, py = self.get_offset(width, height, 0, 0) + bbox_canvas = mtrans.Bbox.from_bounds(px, py, width, height) + tr = ax.figure.transFigure.inverted() + bb = mtrans.TransformedBbox(bbox_canvas, tr) + + return bb + + + + +from mpl_toolkits.axes_grid.axes_divider import Size + +class AnchoredSizeLocator(AnchoredLocatorBase): + def __init__(self, bbox_to_anchor, x_size, y_size, loc, + borderpad=0.5, bbox_transform=None): + + self.axes = None + self.x_size = Size.from_any(x_size) + self.y_size = Size.from_any(y_size) + + super(AnchoredSizeLocator, self).__init__(bbox_to_anchor, None, loc, + borderpad=borderpad, + bbox_transform=bbox_transform) + + def get_extent(self, renderer): + + x, y, w, h = self.get_bbox_to_anchor().bounds + + dpi = renderer.points_to_pixels(72.) + + r, a = self.x_size.get_size(renderer) + width = w*r + a*dpi + + r, a = self.y_size.get_size(renderer) + height = h*r + a*dpi + xd, yd = 0, 0 + + fontsize = renderer.points_to_pixels(self.prop.get_size_in_points()) + pad = self.pad * fontsize + + return width+2*pad, height+2*pad, xd+pad, yd+pad + + + def __call__(self, ax, renderer): + + self.axes = ax + return super(AnchoredSizeLocator, self).__call__(ax, renderer) + + +class AnchoredZoomLocator(AnchoredLocatorBase): + def __init__(self, parent_axes, zoom, loc, + borderpad=0.5, + bbox_to_anchor=None, + bbox_transform=None): + + self.parent_axes = parent_axes + self.zoom = zoom + + if bbox_to_anchor is None: + bbox_to_anchor = parent_axes.bbox + + super(AnchoredZoomLocator, self).__init__(bbox_to_anchor, None, loc, + borderpad=borderpad, + bbox_transform=bbox_transform) + + self.axes = None + + + def get_extent(self, renderer): + + bb = mtrans.TransformedBbox(self.axes.viewLim, self.parent_axes.transData) + + x, y, w, h = bb.bounds + + xd, yd = 0, 0 + + fontsize = renderer.points_to_pixels(self.prop.get_size_in_points()) + pad = self.pad * fontsize + + return w*self.zoom+2*pad, h*self.zoom+2*pad, xd+pad, yd+pad + + + def __call__(self, ax, renderer): + + self.axes = ax + return super(AnchoredZoomLocator, self).__call__(ax, renderer) + + + + + + +class BboxPatch(Patch): + def __init__(self, bbox, **kwargs): + if "transform" in kwargs: + raise ValueError("trnasform should nt be set") + + kwargs["transform"] = IdentityTransform() + Patch.__init__(self, **kwargs) + self.bbox = bbox + + def get_path(self): + x0, y0, x1, y1 = self.bbox.extents + + verts = [(x0, y0), + (x1, y0), + (x1, y1), + (x0, y1), + (x0, y0), + (0,0)] + + codes = [Path.MOVETO, + Path.LINETO, + Path.LINETO, + Path.LINETO, + Path.LINETO, + Path.CLOSEPOLY] + + return Path(verts, codes) + + + + +class BboxConnector(Patch): + + @staticmethod + def get_bbox_edge_pos(bbox, loc): + x0, y0, x1, y1 = bbox.extents + if loc==1: + return x1, y1 + elif loc==2: + return x0, y1 + elif loc==3: + return x0, y0 + elif loc==4: + return x1, y0 + + @staticmethod + def connect_bbox(bbox1, bbox2, loc1, loc2=None): + if isinstance(bbox1, Rectangle): + transform = bbox1.get_transfrom() + bbox1 = Bbox.from_bounds(0, 0, 1, 1) + bbox1 = TransformedBbox(bbox1, transform) + + if isinstance(bbox2, Rectangle): + transform = bbox2.get_transform() + bbox2 = Bbox.from_bounds(0, 0, 1, 1) + bbox2 = TransformedBbox(bbox2, transform) + + if loc2 is None: + loc2 = loc1 + + x1, y1 = BboxConnector.get_bbox_edge_pos(bbox1, loc1) + x2, y2 = BboxConnector.get_bbox_edge_pos(bbox2, loc2) + + verts = [[x1, y1], [x2,y2]] + #Path() + + codes = [Path.MOVETO, Path.LINETO] + + return Path(verts, codes) + + + def __init__(self, bbox1, bbox2, loc1, loc2=None, **kwargs): + """ + *path* is a :class:`matplotlib.path.Path` object. + + Valid kwargs are: + %(Patch)s + + .. seealso:: + + :class:`Patch` + For additional kwargs + + """ + if "transform" in kwargs: + raise ValueError("trnasform should nt be set") + + kwargs["transform"] = IdentityTransform() + Patch.__init__(self, **kwargs) + self.bbox1 = bbox1 + self.bbox2 = bbox2 + self.loc1 = loc1 + self.loc2 = loc2 + + + def get_path(self): + return self.connect_bbox(self.bbox1, self.bbox2, + self.loc1, self.loc2) + + +def _add_inset_axes(parent_axes, inset_axes): + parent_axes.figure.add_axes(inset_axes) + inset_axes.set_navigate(False) + + +def inset_axes(parent_axes, width, height, loc=1, + bbox_to_anchor=None, bbox_transform=None, + axes_kwargs=None, + **kwargs): + + if axes_kwargs is None: + inset_axes = Axes(parent_axes.figure, parent_axes.get_position()) + else: + inset_axes = Axes(parent_axes.figure, parent_axes.get_position(), + **axes_kwargs) + + axes_locator = AnchoredSizeLocator(parent_axes.bbox, + width, height, + loc=loc) + + inset_axes.set_axes_locator(axes_locator) + + _add_inset_axes(parent_axes, inset_axes) + + return inset_axes + + +def zoomed_inset_axes(parent_axes, zoom, loc=1, + bbox_to_anchor=None, bbox_transform=None, + axes_kwargs=None, + connects=None, + **kwargs): + + if axes_kwargs is None: + inset_axes = Axes(parent_axes.figure, parent_axes.get_position()) + else: + inset_axes = Axes(parent_axes.figure, parent_axes.get_position(), + **axes_kwargs) + + axes_locator = AnchoredZoomLocator(parent_axes, zoom=zoom, loc=loc) + inset_axes.set_axes_locator(axes_locator) + + _add_inset_axes(parent_axes, inset_axes) + + if connects is not None: + pass + + return inset_axes + + +def mark_inset(parent_axes, inset_axes, loc1, loc2, **kwargs): + rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData) + + pp = BboxPatch(rect, **kwargs) + parent_axes.add_patch(pp) + + p1 = BboxConnector(inset_axes.bbox, rect, loc1=loc1, **kwargs) + inset_axes.add_patch(p1) + p1.set_clip_on(False) + p2 = BboxConnector(inset_axes.bbox, rect, loc1=loc2, **kwargs) + inset_axes.add_patch(p2) + p2.set_clip_on(False) + + return pp, p1, p2 + + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ry...@us...> - 2009-04-24 17:09:02
|
Revision: 7064 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7064&view=rev Author: ryanmay Date: 2009-04-24 17:08:50 +0000 (Fri, 24 Apr 2009) Log Message: ----------- Use subprocess.Popen instead of os.popen to retrieve memory usage. os.popen* are deprecated in Python 2.6. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/cbook.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-04-24 16:53:44 UTC (rev 7063) +++ trunk/matplotlib/CHANGELOG 2009-04-24 17:08:50 UTC (rev 7064) @@ -1,6 +1,9 @@ ====================================================================== -2009-04-20 Worked on axes_grid documentation. Added +2009-04-24 Changed use of os.open* to instead use subprocess.Popen. + os.popen* are deprecated in 2.6 and are removed in 3.0. - RMM + +2009-04-20 Worked on axes_grid documentation. Added axes_grid.inset_locator. - JJL 2009-04-17 Initial check-in of the axes_grid toolkit. - JJL @@ -16,12 +19,11 @@ an rasterizing backend are placed with incorrect size. - JJL -2008-04-14 Added Jonathan Taylor's Reinier Heeres' port of John +2009-04-14 Added Jonathan Taylor's Reinier Heeres' port of John Porters' mplot3d to svn trunk. Package in mpl_toolkits.mplot3d and demo is examples/mplot3d/demo.py. Thanks Reiner - 2009-04-06 The pdf backend now escapes newlines and linefeeds in strings. Fixes sf bug #2708559; thanks to Tiago Pereira for the report. Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2009-04-24 16:53:44 UTC (rev 7063) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2009-04-24 17:08:50 UTC (rev 7064) @@ -903,15 +903,19 @@ def report_memory(i=0): # argument may go away 'return the memory consumed by process' + from subprocess import Popen, PIPE pid = os.getpid() if sys.platform=='sunos5': - a2 = os.popen('ps -p %d -o osz' % pid).readlines() + a2 = Popen('ps -p %d -o osz' % pid, shell=True, + stdout=PIPE).stdout.readlines() mem = int(a2[-1].strip()) elif sys.platform.startswith('linux'): - a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines() + a2 = Popen('ps -p %d -o rss,sz' % pid, shell=True, + stdout=PIPE).stdout.readlines() mem = int(a2[1].split()[1]) elif sys.platform.startswith('darwin'): - a2 = os.popen('ps -p %d -o rss,vsz' % pid).readlines() + a2 = Popen('ps -p %d -o rss,vsz' % pid, shell=True, + stdout=PIPE).stdout.readlines() mem = int(a2[1].split()[0]) return mem This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-04-28 19:48:22
|
Revision: 7068 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7068&view=rev Author: leejjoon Date: 2009-04-28 19:48:18 +0000 (Tue, 28 Apr 2009) Log Message: ----------- Fixed incorrect bbox of eps output when usetex=True Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/backends/backend_ps.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-04-27 23:30:20 UTC (rev 7067) +++ trunk/matplotlib/CHANGELOG 2009-04-28 19:48:18 UTC (rev 7068) @@ -1,5 +1,7 @@ ====================================================================== +2009-04-28 Fixed incorrect bbox of eps output when usetex=True. - JJL + 2009-04-24 Changed use of os.open* to instead use subprocess.Popen. os.popen* are deprecated in 2.6 and are removed in 3.0. - RMM Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-04-27 23:30:20 UTC (rev 7067) +++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-04-28 19:48:18 UTC (rev 7068) @@ -1096,17 +1096,25 @@ isLandscape = True width, height = height, width bbox = (lly, llx, ury, urx) - temp_papertype = _get_papertype(width, height) - if papertype=='auto': - papertype = temp_papertype - paperWidth, paperHeight = papersize[temp_papertype] + + # set the paper size to the figure size if isEPSF. The + # resulting ps file has the given size with correct bounding + # box so that there is no need to call 'pstoeps' + if isEPSF: + paperWidth, paperHeight = self.figure.get_size_inches() else: - paperWidth, paperHeight = papersize[papertype] - if (width>paperWidth or height>paperHeight) and isEPSF: + temp_papertype = _get_papertype(width, height) + if papertype=='auto': + papertype = temp_papertype paperWidth, paperHeight = papersize[temp_papertype] - verbose.report('Your figure is too big to fit on %s paper. %s \ -paper will be used to prevent clipping.'%(papertype, temp_papertype), 'helpful') + else: + paperWidth, paperHeight = papersize[papertype] + if (width>paperWidth or height>paperHeight) and isEPSF: + paperWidth, paperHeight = papersize[temp_papertype] + verbose.report('Your figure is too big to fit on %s paper. %s \ + paper will be used to prevent clipping.'%(papertype, temp_papertype), 'helpful') + texmanager = renderer.get_texmanager() font_preamble = texmanager.get_font_preamble() custom_preamble = texmanager.get_custom_preamble() @@ -1247,10 +1255,16 @@ os.remove(outfile) os.remove(tmpfile) shutil.move(psfile, tmpfile) - if eps: - pstoeps(tmpfile, bbox) + + # Since the the paper size is set to the figure size for eps + # output (in '_print_figure_tex'), pstoeps call is not required. + + #if eps: + # pstoeps(tmpfile, bbox) + + def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None): """ Use ghostscript's ps2pdf and xpdf's/poppler's pdftops to distill a file. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2009-04-29 16:07:31
|
Revision: 7070 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7070&view=rev Author: jdh2358 Date: 2009-04-29 16:07:27 +0000 (Wed, 29 Apr 2009) Log Message: ----------- add masked array support to fill_between Modified Paths: -------------- trunk/matplotlib/examples/user_interfaces/embedding_in_gtk.py trunk/matplotlib/examples/user_interfaces/embedding_in_gtk2.py trunk/matplotlib/lib/matplotlib/axes.py Modified: trunk/matplotlib/examples/user_interfaces/embedding_in_gtk.py =================================================================== --- trunk/matplotlib/examples/user_interfaces/embedding_in_gtk.py 2009-04-29 15:28:33 UTC (rev 7069) +++ trunk/matplotlib/examples/user_interfaces/embedding_in_gtk.py 2009-04-29 16:07:27 UTC (rev 7070) @@ -10,8 +10,8 @@ from numpy import arange, sin, pi # uncomment to select /GTK/GTKAgg/GTKCairo -from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas -#from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas +#from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas +from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas #from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas Modified: trunk/matplotlib/examples/user_interfaces/embedding_in_gtk2.py =================================================================== --- trunk/matplotlib/examples/user_interfaces/embedding_in_gtk2.py 2009-04-29 15:28:33 UTC (rev 7069) +++ trunk/matplotlib/examples/user_interfaces/embedding_in_gtk2.py 2009-04-29 16:07:27 UTC (rev 7070) @@ -9,8 +9,8 @@ from numpy import arange, sin, pi # uncomment to select /GTK/GTKAgg/GTKCairo -from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas -#from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas +#from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas +from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas #from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas # or NavigationToolbar for classic Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-04-29 15:28:33 UTC (rev 7069) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-04-29 16:07:27 UTC (rev 7070) @@ -5832,6 +5832,26 @@ self._process_unit_info(xdata=x, ydata=y1, kwargs=kwargs) self._process_unit_info(ydata=y2) + if where is None: + where = np.ones(len(x), np.bool) + else: + where = np.asarray(where) + + maskedx = isinstance(x, np.ma.MaskedArray) + maskedy1 = isinstance(y1, np.ma.MaskedArray) + maskedy2 = isinstance(y2, np.ma.MaskedArray) + + if (maskedx or maskedy1 or maskedy2): + if maskedx: + where = where & (~x.mask) + + if maskedy1: + where = where & (~y1.mask) + + if maskedy2: + where = where & (~y2.mask) + + # Convert the arrays so we can work with them x = np.asarray(self.convert_xunits(x)) y1 = np.asarray(self.convert_yunits(y1)) @@ -5843,10 +5863,7 @@ if not cbook.iterable(y2): y2 = np.ones_like(x)*y2 - if where is None: - where = np.ones(len(x), np.bool) - where = np.asarray(where) assert( (len(x)==len(y1)) and (len(x)==len(y2)) and len(x)==len(where)) polys = [] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2009-04-29 19:38:47
|
Revision: 7071 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7071&view=rev Author: efiring Date: 2009-04-29 19:38:35 +0000 (Wed, 29 Apr 2009) Log Message: ----------- Condense argument handling in fill_between, and add masked example Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/fill_between.py trunk/matplotlib/lib/matplotlib/axes.py Modified: trunk/matplotlib/examples/pylab_examples/fill_between.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/fill_between.py 2009-04-29 16:07:27 UTC (rev 7070) +++ trunk/matplotlib/examples/pylab_examples/fill_between.py 2009-04-29 19:38:35 UTC (rev 7071) @@ -1,6 +1,6 @@ #!/usr/bin/env python import matplotlib.mlab as mlab -from pylab import figure, show +from matplotlib.pyplot import figure, show import numpy as np x = np.arange(0.0, 2, 0.01) @@ -27,11 +27,24 @@ # fill_between(x[where], y1[where],y2[where] # because of edge effects over multiple contiguous regions. fig = figure() -ax = fig.add_subplot(111) +ax = fig.add_subplot(211) ax.plot(x, y1, x, y2, color='black') -ax.fill_between(x, y1, y2, where=y2>y1, facecolor='green') +ax.fill_between(x, y1, y2, where=y2>=y1, facecolor='green') ax.fill_between(x, y1, y2, where=y2<=y1, facecolor='red') ax.set_title('fill between where') +# Test support for masked arrays. +y2 = np.ma.masked_greater(y2, 1.0) +ax1 = fig.add_subplot(212, sharex=ax) +ax1.plot(x, y1, x, y2, color='black') +ax1.fill_between(x, y1, y2, where=y2>=y1, facecolor='green') +ax1.fill_between(x, y1, y2, where=y2<=y1, facecolor='red') +ax1.set_title('Now regions with y2>1 are masked') + +# This example illustrates a problem; because of the data +# gridding, there are undesired unfilled triangles at the crossover +# points. A brute-force solution would be to interpolate all +# arrays to a very fine grid before plotting. + show() Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-04-29 16:07:27 UTC (rev 7070) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-04-29 19:38:35 UTC (rev 7071) @@ -5832,40 +5832,29 @@ self._process_unit_info(xdata=x, ydata=y1, kwargs=kwargs) self._process_unit_info(ydata=y2) - if where is None: - where = np.ones(len(x), np.bool) - else: - where = np.asarray(where) - - maskedx = isinstance(x, np.ma.MaskedArray) - maskedy1 = isinstance(y1, np.ma.MaskedArray) - maskedy2 = isinstance(y2, np.ma.MaskedArray) - - if (maskedx or maskedy1 or maskedy2): - if maskedx: - where = where & (~x.mask) - - if maskedy1: - where = where & (~y1.mask) - - if maskedy2: - where = where & (~y2.mask) - - # Convert the arrays so we can work with them - x = np.asarray(self.convert_xunits(x)) - y1 = np.asarray(self.convert_yunits(y1)) - y2 = np.asarray(self.convert_yunits(y2)) + x = np.asanyarray(self.convert_xunits(x)) + y1 = np.asanyarray(self.convert_yunits(y1)) + y2 = np.asanyarray(self.convert_yunits(y2)) - if not cbook.iterable(y1): + if y1.ndim == 0: y1 = np.ones_like(x)*y1 - - if not cbook.iterable(y2): + if y2.ndim == 0: y2 = np.ones_like(x)*y2 + if where is None: + where = np.ones(len(x), np.bool) + else: + where = np.asarray(where, np.bool) - assert( (len(x)==len(y1)) and (len(x)==len(y2)) and len(x)==len(where)) + if not (x.shape == y1.shape == y2.shape == where.shape): + raise ValueError("Argument dimensions are incompatible") + mask = reduce(ma.mask_or, + [ma.getmask(x), ma.getmask(y1), ma.getmask(y2)]) + if mask is not ma.nomask: + where &= ~mask + polys = [] for ind0, ind1 in mlab.contiguous_regions(where): theseverts = [] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2009-04-30 13:29:03
|
Revision: 7073 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7073&view=rev Author: mdboom Date: 2009-04-30 13:28:54 +0000 (Thu, 30 Apr 2009) Log Message: ----------- Merged revisions 7072 via svnmerge from https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v0_98_5_maint ........ r7072 | mdboom | 2009-04-30 09:27:04 -0400 (Thu, 30 Apr 2009) | 2 lines Fix solaris builds where "putchar" is a macro. ........ Modified Paths: -------------- trunk/matplotlib/ttconv/pprdrv.h trunk/matplotlib/ttconv/pprdrv_tt.cpp trunk/matplotlib/ttconv/pprdrv_tt2.cpp trunk/matplotlib/ttconv/ttutil.cpp Property Changed: ---------------- trunk/matplotlib/ trunk/matplotlib/doc/pyplots/README trunk/matplotlib/doc/sphinxext/gen_gallery.py trunk/matplotlib/doc/sphinxext/gen_rst.py trunk/matplotlib/lib/matplotlib/sphinxext/mathmpl.py trunk/matplotlib/lib/matplotlib/sphinxext/only_directives.py trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py Property changes on: trunk/matplotlib ___________________________________________________________________ Modified: svnmerge-integrated - /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-7054 + /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-7072 Modified: svn:mergeinfo - /branches/v0_91_maint:5753-5771 /branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042 + /branches/v0_91_maint:5753-5771 /branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 Property changes on: trunk/matplotlib/doc/pyplots/README ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_98_5_maint/doc/pyplots/README:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042 + /branches/v0_98_5_maint/doc/pyplots/README:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 Property changes on: trunk/matplotlib/doc/sphinxext/gen_gallery.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/_templates/gen_gallery.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_gallery.py:6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042 + /branches/v0_91_maint/doc/_templates/gen_gallery.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_gallery.py:6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 Property changes on: trunk/matplotlib/doc/sphinxext/gen_rst.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/examples/gen_rst.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_rst.py:6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042 + /branches/v0_91_maint/doc/examples/gen_rst.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_rst.py:6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 Property changes on: trunk/matplotlib/lib/matplotlib/sphinxext/mathmpl.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/sphinxext/mathmpl.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/mathmpl.py:6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042 + /branches/v0_91_maint/doc/sphinxext/mathmpl.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/mathmpl.py:6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 Property changes on: trunk/matplotlib/lib/matplotlib/sphinxext/only_directives.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/sphinxext/only_directives.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/only_directives.py:6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042 + /branches/v0_91_maint/doc/sphinxext/only_directives.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/only_directives.py:6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 Property changes on: trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/sphinxext/plot_directive.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/plot_directive.py:6920-6925,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042 + /branches/v0_91_maint/doc/sphinxext/plot_directive.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/plot_directive.py:6920-6925,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 Modified: trunk/matplotlib/ttconv/pprdrv.h =================================================================== --- trunk/matplotlib/ttconv/pprdrv.h 2009-04-30 13:27:04 UTC (rev 7072) +++ trunk/matplotlib/ttconv/pprdrv.h 2009-04-30 13:28:54 UTC (rev 7073) @@ -40,7 +40,7 @@ virtual void write(const char*) = 0; virtual void printf(const char* format, ...); - virtual void putchar(int val); + virtual void put_char(int val); virtual void puts(const char* a); virtual void putline(const char* a); }; Modified: trunk/matplotlib/ttconv/pprdrv_tt.cpp =================================================================== --- trunk/matplotlib/ttconv/pprdrv_tt.cpp 2009-04-30 13:27:04 UTC (rev 7072) +++ trunk/matplotlib/ttconv/pprdrv_tt.cpp 2009-04-30 13:28:54 UTC (rev 7073) @@ -495,20 +495,20 @@ if(!in_string) { - stream.putchar('<'); + stream.put_char('<'); string_len=0; line_len++; in_string=TRUE; } - stream.putchar( hexdigits[ n / 16 ] ); - stream.putchar( hexdigits[ n % 16 ] ); + stream.put_char( hexdigits[ n / 16 ] ); + stream.put_char( hexdigits[ n % 16 ] ); string_len++; line_len+=2; if(line_len > 70) { - stream.putchar('\n'); + stream.put_char('\n'); line_len=0; } @@ -561,7 +561,7 @@ #endif sfnts_pputBYTE(stream, 0); /* extra byte for pre-2013 compatibility */ - stream.putchar('>'); + stream.put_char('>'); line_len++; } in_string=FALSE; @@ -968,7 +968,7 @@ /* a BuildGlyph and BuildChar proceedures. */ if( font->target_type == PS_TYPE_3 ) { - stream.putchar('\n'); + stream.put_char('\n'); stream.putline("/BuildGlyph"); stream.putline(" {exch begin"); /* start font dictionary */ @@ -977,7 +977,7 @@ stream.putline(" true 3 1 roll get exec"); stream.putline(" end}_d"); - stream.putchar('\n'); + stream.put_char('\n'); /* This proceedure is for compatiblity with */ /* level 1 interpreters. */ @@ -986,7 +986,7 @@ stream.putline(" 1 index /BuildGlyph get exec"); stream.putline("}_d"); - stream.putchar('\n'); + stream.put_char('\n'); } /* If we are generating a type 42 font, we need to check to see */ @@ -998,7 +998,7 @@ /* setup instructions and part of BuildGlyph came from. */ else if( font->target_type == PS_TYPE_42 ) { - stream.putchar('\n'); + stream.put_char('\n'); /* If we have no "resourcestatus" command, or FontType 42 */ /* is unknown, leave "true" on the stack. */ @@ -1079,7 +1079,7 @@ /* if the printer has no built-in TrueType */ /* rasterizer. */ stream.putline("}if"); - stream.putchar('\n'); + stream.put_char('\n'); } /* end of if Type 42 not understood. */ stream.putline("FontName currentdict end definefont pop"); Modified: trunk/matplotlib/ttconv/pprdrv_tt2.cpp =================================================================== --- trunk/matplotlib/ttconv/pprdrv_tt2.cpp 2009-04-30 13:27:04 UTC (rev 7072) +++ trunk/matplotlib/ttconv/pprdrv_tt2.cpp 2009-04-30 13:28:54 UTC (rev 7073) @@ -104,7 +104,7 @@ { /* have a log of points. */ if(stack_depth == 0) { - stream.putchar('{'); + stream.put_char('{'); stack_depth=1; } Modified: trunk/matplotlib/ttconv/ttutil.cpp =================================================================== --- trunk/matplotlib/ttconv/ttutil.cpp 2009-04-30 13:27:04 UTC (rev 7072) +++ trunk/matplotlib/ttconv/ttutil.cpp 2009-04-30 13:28:54 UTC (rev 7073) @@ -52,7 +52,7 @@ va_end(arg_list); } -void TTStreamWriter::putchar(int val) +void TTStreamWriter::put_char(int val) { char c[2]; c[0] = (char)val; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-04-30 17:05:28
|
Revision: 7074 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7074&view=rev Author: leejjoon Date: 2009-04-30 17:05:27 +0000 (Thu, 30 Apr 2009) Log Message: ----------- Incorrect eps bbox for landscape mode fixed Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/backends/backend_ps.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-04-30 13:28:54 UTC (rev 7073) +++ trunk/matplotlib/CHANGELOG 2009-04-30 17:05:27 UTC (rev 7074) @@ -1,5 +1,7 @@ ====================================================================== +2009-04-30 Incorrect eps bbox for landscape mode fixed - JJL + 2009-04-28 Fixed incorrect bbox of eps output when usetex=True. - JJL 2009-04-24 Changed use of os.open* to instead use subprocess.Popen. Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-04-30 13:28:54 UTC (rev 7073) +++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-04-30 17:05:27 UTC (rev 7074) @@ -1100,8 +1100,10 @@ # set the paper size to the figure size if isEPSF. The # resulting ps file has the given size with correct bounding # box so that there is no need to call 'pstoeps' - if isEPSF: + if isEPSF: paperWidth, paperHeight = self.figure.get_size_inches() + if isLandscape: + paperWidth, paperHeight = paperHeight, paperWidth else: temp_papertype = _get_papertype(width, height) if papertype=='auto': This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2009-05-01 19:04:09
|
Revision: 7077 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7077&view=rev Author: efiring Date: 2009-05-01 19:04:06 +0000 (Fri, 01 May 2009) Log Message: ----------- Make Axes.add_artist etc. return their argument. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-01 18:05:12 UTC (rev 7076) +++ trunk/matplotlib/CHANGELOG 2009-05-01 19:04:06 UTC (rev 7077) @@ -1,4 +1,6 @@ ====================================================================== +2009-05-01 Changed add_artist and similar Axes methods to + return their argument. - EF 2009-04-30 Incorrect eps bbox for landscape mode fixed - JJL Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-05-01 18:05:12 UTC (rev 7076) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-05-01 19:04:06 UTC (rev 7077) @@ -1323,17 +1323,24 @@ len(self.patches))>0 def add_artist(self, a): - 'Add any :class:`~matplotlib.artist.Artist` to the axes' + ''' + Add any :class:`~matplotlib.artist.Artist` to the axes + + Returns the artist. + ''' a.set_axes(self) self.artists.append(a) self._set_artist_props(a) a.set_clip_path(self.patch) a._remove_method = lambda h: self.artists.remove(h) + return a def add_collection(self, collection, autolim=True): ''' add a :class:`~matplotlib.collections.Collection` instance to the axes + + Returns the collection. ''' label = collection.get_label() if not label: @@ -1348,11 +1355,14 @@ self.update_datalim(collection.get_datalim(self.transData)) collection._remove_method = lambda h: self.collections.remove(h) + return collection def add_line(self, line): ''' Add a :class:`~matplotlib.lines.Line2D` to the list of plot lines + + Returns the line. ''' self._set_artist_props(line) if line.get_clip_path() is None: @@ -1363,6 +1373,7 @@ line.set_label('_line%d'%len(self.lines)) self.lines.append(line) line._remove_method = lambda h: self.lines.remove(h) + return line def _update_line_limits(self, line): p = line.get_path() @@ -1378,6 +1389,8 @@ axes patches; the clipbox will be set to the Axes clipping box. If the transform is not set, it will be set to :attr:`transData`. + + Returns the patch. """ self._set_artist_props(p) @@ -1386,6 +1399,7 @@ self._update_patch_limits(p) self.patches.append(p) p._remove_method = lambda h: self.patches.remove(h) + return p def _update_patch_limits(self, patch): 'update the data limits for patch *p*' @@ -1412,11 +1426,14 @@ ''' Add a :class:`~matplotlib.tables.Table` instance to the list of axes tables + + Returns the table. ''' self._set_artist_props(tab) self.tables.append(tab) tab.set_clip_path(self.patch) tab._remove_method = lambda h: self.tables.remove(h) + return tab def relim(self): 'recompute the data limits based on current artists' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2009-05-03 00:09:14
|
Revision: 7078 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7078&view=rev Author: efiring Date: 2009-05-03 00:09:06 +0000 (Sun, 03 May 2009) Log Message: ----------- Added options to plotfile Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/examples/pylab_examples/plotfile_demo.py trunk/matplotlib/lib/matplotlib/pyplot.py Added Paths: ----------- trunk/matplotlib/examples/data/data_x_x2_x3.csv Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-01 19:04:06 UTC (rev 7077) +++ trunk/matplotlib/CHANGELOG 2009-05-03 00:09:06 UTC (rev 7078) @@ -1,4 +1,7 @@ ====================================================================== +2009-05-02 Added options to plotfile based on question from + Joseph Smidt and patch by Matthias Michler. - EF + 2009-05-01 Changed add_artist and similar Axes methods to return their argument. - EF Added: trunk/matplotlib/examples/data/data_x_x2_x3.csv =================================================================== --- trunk/matplotlib/examples/data/data_x_x2_x3.csv (rev 0) +++ trunk/matplotlib/examples/data/data_x_x2_x3.csv 2009-05-03 00:09:06 UTC (rev 7078) @@ -0,0 +1,11 @@ + 0 0 0 + 1 1 1 + 2 4 8 + 3 9 27 + 4 16 64 + 5 25 125 + 6 36 216 + 7 49 343 + 8 64 512 + 9 81 729 +10 100 1000 Modified: trunk/matplotlib/examples/pylab_examples/plotfile_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/plotfile_demo.py 2009-05-01 19:04:06 UTC (rev 7077) +++ trunk/matplotlib/examples/pylab_examples/plotfile_demo.py 2009-05-03 00:09:06 UTC (rev 7078) @@ -1,6 +1,7 @@ -from pylab import plotfile, show +from pylab import plotfile, show, gca fname = '../data/msft.csv' +fname2 = '../data/data_x_x2_x3.csv' # test 1; use ints plotfile(fname, (0,5,6)) @@ -14,7 +15,20 @@ # test 4; use semilogy for volume plotfile(fname, (0,5,6), plotfuncs={5:'semilogy'}) -# test 5; use bar for volume +#test 5; single subplot +plotfile(fname, ('date', 'open', 'high', 'low', 'close'), subplots=False) + +# test 6; labeling, if no names in csv-file +plotfile(fname2, cols=(0,1,2), delimiter=' ', + names=['$x$', '$f(x)=x^2$', '$f(x)=x^3$']) + +# test 7; more than one file per figure--illustrated here with a single file +plotfile(fname2, cols=(0, 1), delimiter=' ') +plotfile(fname2, cols=(0, 2), newfig=False, delimiter=' ') # use current figure +gca().set_xlabel(r'$x$') +gca().set_ylabel(r'$f(x) = x^2, x^3$') + +# test 8; use bar for volume plotfile(fname, (0,5,6), plotfuncs={5:'bar'}) show() Modified: trunk/matplotlib/lib/matplotlib/pyplot.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pyplot.py 2009-05-01 19:04:06 UTC (rev 7077) +++ trunk/matplotlib/lib/matplotlib/pyplot.py 2009-05-03 00:09:06 UTC (rev 7078) @@ -1448,7 +1448,8 @@ return ret def plotfile(fname, cols=(0,), plotfuncs=None, - comments='#', skiprows=0, checkrows=5, delimiter=',', + comments='#', skiprows=0, checkrows=5, delimiter=',', names=None, + subplots=True, newfig=True, **kwargs): """ Plot the data in *fname* @@ -1464,18 +1465,28 @@ - If len(*cols*) > 1, the first element will be an identifier for data for the *x* axis and the remaining elements will be the - column indexes for multiple subplots + column indexes for multiple subplots if *subplots* is *True* + (the default), or for lines in a single subplot if *subplots* + is *False*. *plotfuncs*, if not *None*, is a dictionary mapping identifier to an :class:`~matplotlib.axes.Axes` plotting function as a string. Default is 'plot', other choices are 'semilogy', 'fill', 'bar', etc. You must use the same type of identifier in the *cols* vector as you use in the *plotfuncs* dictionary, eg., integer - column numbers in both or column names in both. + column numbers in both or column names in both. If *subplots* + is *False*, then including any function such as 'semilogy' + that changes the axis scaling will set the scaling for all + columns. - *comments*, *skiprows*, *checkrows*, and *delimiter* are all passed on to - :func:`matplotlib.pylab.csv2rec` to load the data into a record array. + *comments*, *skiprows*, *checkrows*, *delimiter*, and *names* + are all passed on to :func:`matplotlib.pylab.csv2rec` to + load the data into a record array. + If *newfig* is *True*, the plot always will be made in a new figure; + if *False*, it will be made in the current figure if one exists, + else in a new figure. + kwargs are passed on to plotting functions. Example usage:: @@ -1484,17 +1495,26 @@ plotfile(fname, (0,1,3)) # plot using column names; specify an alternate plot type for volume - plotfile(fname, ('date', 'volume', 'adj_close'), plotfuncs={'volume': 'semilogy'}) + plotfile(fname, ('date', 'volume', 'adj_close'), + plotfuncs={'volume': 'semilogy'}) + + Note: plotfile is intended as a convenience for quickly plotting + data from flat files; it is not intended as an alternative + interface to general plotting with pyplot or matplotlib. """ - fig = figure() + if newfig: + fig = figure() + else: + fig = gcf() + if len(cols)<1: raise ValueError('must have at least one column of data') if plotfuncs is None: plotfuncs = dict() - r = mlab.csv2rec(fname, comments=comments, - skiprows=skiprows, checkrows=checkrows, delimiter=delimiter) + r = mlab.csv2rec(fname, comments=comments, skiprows=skiprows, + checkrows=checkrows, delimiter=delimiter, names=names) def getname_val(identifier): 'return the name and column data for identifier' @@ -1507,36 +1527,44 @@ raise TypeError('identifier must be a string or integer') xname, x = getname_val(cols[0]) + ynamelist = [] if len(cols)==1: ax1 = fig.add_subplot(1,1,1) funcname = plotfuncs.get(cols[0], 'plot') func = getattr(ax1, funcname) func(x, **kwargs) - ax1.set_xlabel(xname) + ax1.set_ylabel(xname) else: N = len(cols) for i in range(1,N): - if i==1: - ax = ax1 = fig.add_subplot(N-1,1,i) - ax.grid(True) - else: - ax = fig.add_subplot(N-1,1,i, sharex=ax1) - ax.grid(True) + if subplots: + if i==1: + ax = ax1 = fig.add_subplot(N-1,1,i) + else: + ax = fig.add_subplot(N-1,1,i, sharex=ax1) + elif i==1: + ax = fig.add_subplot(1,1,1) + ax.grid(True) + yname, y = getname_val(cols[i]) + ynamelist.append(yname) funcname = plotfuncs.get(cols[i], 'plot') func = getattr(ax, funcname) func(x, y, **kwargs) - ax.set_ylabel(yname) + if subplots: + ax.set_ylabel(yname) if ax.is_last_row(): ax.set_xlabel(xname) else: ax.set_xlabel('') + if not subplots: + ax.legend(ynamelist, loc='best') if xname=='date': fig.autofmt_xdate() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2009-05-04 18:19:24
|
Revision: 7079 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7079&view=rev Author: jdh2358 Date: 2009-05-04 18:19:18 +0000 (Mon, 04 May 2009) Log Message: ----------- added sf patch 2786759 for fill_betweenx Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/boilerplate.py trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/pyplot.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-03 00:09:06 UTC (rev 7078) +++ trunk/matplotlib/CHANGELOG 2009-05-04 18:19:18 UTC (rev 7079) @@ -1,7 +1,10 @@ ====================================================================== +2009-05-04 Added TJ's fill_betweenx patch - JDH + 2009-05-02 Added options to plotfile based on question from Joseph Smidt and patch by Matthias Michler. - EF + 2009-05-01 Changed add_artist and similar Axes methods to return their argument. - EF Modified: trunk/matplotlib/boilerplate.py =================================================================== --- trunk/matplotlib/boilerplate.py 2009-05-03 00:09:06 UTC (rev 7078) +++ trunk/matplotlib/boilerplate.py 2009-05-04 18:19:18 UTC (rev 7079) @@ -65,6 +65,7 @@ 'errorbar', 'fill', 'fill_between', + 'fill_betweenx', 'hexbin', 'hist', 'hlines', Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-05-03 00:09:06 UTC (rev 7078) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-05-04 18:19:18 UTC (rev 7079) @@ -5826,10 +5826,10 @@ an N length np array of the x data *y1* - an N length scalar or np array of the x data + an N length scalar or np array of the y data *y2* - an N length scalar or np array of the x data + an N length scalar or np array of the y data *where* if None, default to fill between everywhere. If not None, @@ -5844,6 +5844,12 @@ %(PolyCollection)s .. plot:: mpl_examples/pylab_examples/fill_between.py + + .. seealso:: + + :meth:`fill_betweenx` + for filling between two sets of x-values + """ # Handle united data, such as dates self._process_unit_info(xdata=x, ydata=y1, kwargs=kwargs) @@ -5913,6 +5919,113 @@ return collection fill_between.__doc__ = cbook.dedent(fill_between.__doc__) % martist.kwdocd + def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs): + """ + call signature:: + + fill_between(y, x1, x2=0, where=None, **kwargs) + + Create a :class:`~matplotlib.collections.PolyCollection` + filling the regions between *x1* and *x2* where + ``where==True`` + + *y* + an N length np array of the y data + + *x1* + an N length scalar or np array of the x data + + *x2* + an N length scalar or np array of the x data + + *where* + if None, default to fill between everywhere. If not None, + it is a a N length numpy boolean array and the fill will + only happen over the regions where ``where==True`` + + *kwargs* + keyword args passed on to the :class:`PolyCollection` + + kwargs control the Polygon properties: + + %(PolyCollection)s + + .. plot:: mpl_examples/pylab_examples/fill_betweenx.py + + .. seealso:: + + :meth:`fill_between` + for filling between two sets of y-values + + """ + # Handle united data, such as dates + self._process_unit_info(ydata=y, xdata=x1, kwargs=kwargs) + self._process_unit_info(xdata=x2) + + # Convert the arrays so we can work with them + y = np.asanyarray(self.convert_yunits(y)) + x1 = np.asanyarray(self.convert_xunits(x1)) + x2 = np.asanyarray(self.convert_xunits(x2)) + + if x1.ndim == 0: + x1 = np.ones_like(y)*x1 + if x2.ndim == 0: + x2 = np.ones_like(y)*x2 + + if where is None: + where = np.ones(len(y), np.bool) + else: + where = np.asarray(where, np.bool) + + if not (y.shape == x1.shape == x2.shape == where.shape): + raise ValueError("Argument dimensions are incompatible") + + mask = reduce(ma.mask_or, + [ma.getmask(y), ma.getmask(x1), ma.getmask(x2)]) + if mask is not ma.nomask: + where &= ~mask + + polys = [] + for ind0, ind1 in mlab.contiguous_regions(where): + theseverts = [] + yslice = y[ind0:ind1] + x1slice = x1[ind0:ind1] + x2slice = x2[ind0:ind1] + + if not len(yslice): + continue + + N = len(yslice) + Y = np.zeros((2*N+2, 2), np.float) + + # the purpose of the next two lines is for when x2 is a + # scalar like 0 and we want the fill to go all the way + # down to 0 even if none of the x1 sample points do + Y[0] = x2slice[0], yslice[0] + Y[N+1] = x2slice[-1], yslice[-1] + + Y[1:N+1,0] = x1slice + Y[1:N+1,1] = yslice + Y[N+2:,0] = x2slice[::-1] + Y[N+2:,1] = yslice[::-1] + + polys.append(Y) + + collection = mcoll.PolyCollection(polys, **kwargs) + + # now update the datalim and autoscale + X1Y = np.array([x1[where], y[where]]).T + X2Y = np.array([x2[where], y[where]]).T + self.dataLim.update_from_data_xy(X1Y, self.ignore_existing_data_limits, + updatex=True, updatey=True) + + self.dataLim.update_from_data_xy(X2Y, self.ignore_existing_data_limits, + updatex=False, updatey=True) + self.add_collection(collection) + self.autoscale_view() + return collection + fill_between.__doc__ = cbook.dedent(fill_between.__doc__) % martist.kwdocd + #### plotting z(x,y): imshow, pcolor and relatives, contour def imshow(self, X, cmap=None, norm=None, aspect=None, Modified: trunk/matplotlib/lib/matplotlib/pyplot.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pyplot.py 2009-05-03 00:09:06 UTC (rev 7078) +++ trunk/matplotlib/lib/matplotlib/pyplot.py 2009-05-04 18:19:18 UTC (rev 7079) @@ -1185,7 +1185,8 @@ figtext add text in figure coords figure create or change active figure fill make filled polygons - fill_between make filled polygons + fill_between make filled polygons between two sets of y-values + fill_betweenx make filled polygons between two sets of x-values gca return the current axes gcf return the current figure gci get the current image, or None @@ -1973,6 +1974,28 @@ # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost +def fill_betweenx(*args, **kwargs): + # allow callers to override the hold state by passing hold=True|False + b = ishold() + h = kwargs.pop('hold', None) + if h is not None: + hold(h) + try: + ret = gca().fill_betweenx(*args, **kwargs) + draw_if_interactive() + except: + hold(b) + raise + + hold(b) + return ret +if Axes.fill_betweenx.__doc__ is not None: + fill_betweenx.__doc__ = dedent(Axes.fill_betweenx.__doc__) + """ + +Additional kwargs: hold = [True|False] overrides default hold state""" + +# This function was autogenerated by boilerplate.py. Do not edit as +# changes will be lost def hexbin(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2009-05-04 19:07:48
|
Revision: 7081 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7081&view=rev Author: mdboom Date: 2009-05-04 19:07:43 +0000 (Mon, 04 May 2009) Log Message: ----------- Merged revisions 7080 via svnmerge from https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v0_98_5_maint ........ r7080 | mdboom | 2009-05-04 15:05:38 -0400 (Mon, 04 May 2009) | 2 lines [2723470] UnboundLocalError in ticker.py ........ Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/ticker.py Property Changed: ---------------- trunk/matplotlib/ trunk/matplotlib/doc/pyplots/README trunk/matplotlib/doc/sphinxext/gen_gallery.py trunk/matplotlib/doc/sphinxext/gen_rst.py trunk/matplotlib/lib/matplotlib/sphinxext/mathmpl.py trunk/matplotlib/lib/matplotlib/sphinxext/only_directives.py trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py Property changes on: trunk/matplotlib ___________________________________________________________________ Modified: svnmerge-integrated - /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-7072 + /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-7080 Modified: svn:mergeinfo - /branches/v0_91_maint:5753-5771 /branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 + /branches/v0_91_maint:5753-5771 /branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 Property changes on: trunk/matplotlib/doc/pyplots/README ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_98_5_maint/doc/pyplots/README:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 + /branches/v0_98_5_maint/doc/pyplots/README:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 Property changes on: trunk/matplotlib/doc/sphinxext/gen_gallery.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/_templates/gen_gallery.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_gallery.py:6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 + /branches/v0_91_maint/doc/_templates/gen_gallery.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_gallery.py:6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 Property changes on: trunk/matplotlib/doc/sphinxext/gen_rst.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/examples/gen_rst.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_rst.py:6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 + /branches/v0_91_maint/doc/examples/gen_rst.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_rst.py:6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 Property changes on: trunk/matplotlib/lib/matplotlib/sphinxext/mathmpl.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/sphinxext/mathmpl.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/mathmpl.py:6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 + /branches/v0_91_maint/doc/sphinxext/mathmpl.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/mathmpl.py:6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 Property changes on: trunk/matplotlib/lib/matplotlib/sphinxext/only_directives.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/sphinxext/only_directives.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/only_directives.py:6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 + /branches/v0_91_maint/doc/sphinxext/only_directives.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/only_directives.py:6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 Property changes on: trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/sphinxext/plot_directive.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/plot_directive.py:6920-6925,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072 + /branches/v0_91_maint/doc/sphinxext/plot_directive.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/plot_directive.py:6920-6925,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 Modified: trunk/matplotlib/lib/matplotlib/ticker.py =================================================================== --- trunk/matplotlib/lib/matplotlib/ticker.py 2009-05-04 19:05:38 UTC (rev 7080) +++ trunk/matplotlib/lib/matplotlib/ticker.py 2009-05-04 19:07:43 UTC (rev 7081) @@ -953,6 +953,8 @@ vmax -= offset raw_step = (vmax-vmin)/nbins scaled_raw_step = raw_step/scale + best_vmax = vmax + best_vmin = vmin for step in self._steps: if step < scaled_raw_step: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-05-04 20:14:41
|
Revision: 7083 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7083&view=rev Author: leejjoon Date: 2009-05-04 20:14:40 +0000 (Mon, 04 May 2009) Log Message: ----------- Merged revisions 7082 via svnmerge from https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v0_98_5_maint ........ r7082 | leejjoon | 2009-05-04 16:05:57 -0400 (Mon, 04 May 2009) | 2 lines Fix bug that Text.Annotation is still drawn while set to not visible ........ Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/text.py Property Changed: ---------------- trunk/matplotlib/ Property changes on: trunk/matplotlib ___________________________________________________________________ Modified: svnmerge-integrated - /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-7080 + /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-7082 Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-04 20:05:57 UTC (rev 7082) +++ trunk/matplotlib/CHANGELOG 2009-05-04 20:14:40 UTC (rev 7083) @@ -1,4 +1,7 @@ ====================================================================== +2009-05-04 Fix bug that Text.Annotation is still drawn while set to + not visible.-JJL + 2009-05-04 Added TJ's fill_betweenx patch - JDH 2009-05-02 Added options to plotfile based on question from Modified: trunk/matplotlib/lib/matplotlib/text.py =================================================================== --- trunk/matplotlib/lib/matplotlib/text.py 2009-05-04 20:05:57 UTC (rev 7082) +++ trunk/matplotlib/lib/matplotlib/text.py 2009-05-04 20:14:40 UTC (rev 7083) @@ -1612,6 +1612,11 @@ """ Draw the :class:`Annotation` object to the given *renderer*. """ + + if renderer is not None: + self._renderer = renderer + if not self.get_visible(): return + self.update_positions(renderer) self.update_bbox_position_size(renderer) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-05-05 17:27:28
|
Revision: 7085 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7085&view=rev Author: leejjoon Date: 2009-05-05 17:27:23 +0000 (Tue, 05 May 2009) Log Message: ----------- Add Axes.get_legend_handles_labels method Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-05 03:27:48 UTC (rev 7084) +++ trunk/matplotlib/CHANGELOG 2009-05-05 17:27:23 UTC (rev 7085) @@ -1,4 +1,6 @@ ====================================================================== +2009-05-05 Add Axes.get_legend_handles_labels method -JJL + 2009-05-04 Fix bug that Text.Annotation is still drawn while set to not visible.-JJL Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-05-05 03:27:48 UTC (rev 7084) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-05-05 17:27:23 UTC (rev 7085) @@ -3761,6 +3761,41 @@ return lags, c, a, b xcorr.__doc__ = cbook.dedent(xcorr.__doc__) % martist.kwdocd + + def _get_legend_handles(self): + "return artists that will be used as handles for legend" + handles = self.lines[:] + handles.extend(self.patches) + handles.extend([c for c in self.collections + if isinstance(c, mcoll.LineCollection)]) + handles.extend([c for c in self.collections + if isinstance(c, mcoll.RegularPolyCollection)]) + return handles + + + def get_legend_handles_labels(self): + """ + return handles and labels for legend + + ax.legend() is equibalent to :: + + h, l = ax.get_legend_handles_labels() + ax.legend(h, l) + + """ + + handles = [] + labels = [] + for handle in self._get_legend_handles(): + label = handle.get_label() + if (label is not None and + label != '' and not label.startswith('_')): + handles.append(handle) + labels.append(label) + + return handles, labels + + def legend(self, *args, **kwargs): """ call signature:: @@ -3867,24 +3902,8 @@ .. plot:: mpl_examples/api/legend_demo.py """ - def get_handles(): - handles = self.lines[:] - handles.extend(self.patches) - handles.extend([c for c in self.collections - if isinstance(c, mcoll.LineCollection)]) - handles.extend([c for c in self.collections - if isinstance(c, mcoll.RegularPolyCollection)]) - return handles - if len(args)==0: - handles = [] - labels = [] - for handle in get_handles(): - label = handle.get_label() - if (label is not None and - label != '' and not label.startswith('_')): - handles.append(handle) - labels.append(label) + handles, labels = self.get_legend_handles_labels() if len(handles) == 0: warnings.warn("No labeled objects found. " "Use label='...' kwarg on individual plots.") @@ -3893,13 +3912,15 @@ elif len(args)==1: # LABELS labels = args[0] - handles = [h for h, label in zip(get_handles(), labels)] + handles = [h for h, label in zip(self._get_legend_handles(), + labels)] elif len(args)==2: if is_string_like(args[1]) or isinstance(args[1], int): # LABELS, LOC labels, loc = args - handles = [h for h, label in zip(get_handles(), labels)] + handles = [h for h, label in zip(self._get_legend_handles(), + labels)] kwargs['loc'] = loc else: # LINES, LABELS This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ry...@us...> - 2009-05-06 18:13:50
|
Revision: 7086 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7086&view=rev Author: ryanmay Date: 2009-05-06 18:13:41 +0000 (Wed, 06 May 2009) Log Message: ----------- Add an example of an updating plot using (multi)processing. Credit goes to Robert Cimrman. Modified Paths: -------------- trunk/matplotlib/CHANGELOG Added Paths: ----------- trunk/matplotlib/examples/misc/log.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-05 17:27:23 UTC (rev 7085) +++ trunk/matplotlib/CHANGELOG 2009-05-06 18:13:41 UTC (rev 7086) @@ -1,9 +1,13 @@ ====================================================================== -2009-05-05 Add Axes.get_legend_handles_labels method -JJL +2009-05-05 Add an example that shows how to make a plot that updates + using data from another process. Thanks to Robert + Cimrman - RMM -2009-05-04 Fix bug that Text.Annotation is still drawn while set to - not visible.-JJL +2009-05-05 Add Axes.get_legend_handles_labels method. - JJL +2009-05-04 Fix bug that Text.Annotation is still drawn while set to + not visible. - JJL + 2009-05-04 Added TJ's fill_betweenx patch - JDH 2009-05-02 Added options to plotfile based on question from Added: trunk/matplotlib/examples/misc/log.py =================================================================== --- trunk/matplotlib/examples/misc/log.py (rev 0) +++ trunk/matplotlib/examples/misc/log.py 2009-05-06 18:13:41 UTC (rev 7086) @@ -0,0 +1,87 @@ +#Demo of using multiprocessing for generating data in one process and plotting +#in another. +#Written by Robert Cimrman +#Requires >= Python 2.6 for the multiprocessing module or having the +#standalone processing module installed +import time +try: + from multiprocessing import Process, Pipe +except ImportError: + from processing import Process, Pipe +from Queue import Empty +import numpy as np +import pylab +import gobject + +class ProcessPlotter(object): + + def __init__(self): + self.x = [] + self.y = [] + + def terminate(self): + pylab.close('all') + + def poll_draw(self): + + def call_back(): + while 1: + if not self.pipe.poll(): + break + + command = self.pipe.recv() + + if command is None: + self.terminate() + return False + + else: + self.x.append(command[0]) + self.y.append(command[1]) + self.ax.plot(self.x, self.y, 'ro') + + self.fig.canvas.draw() + return True + + return call_back + + def __call__(self, pipe): + print 'starting plotter...' + + self.pipe = pipe + self.fig = pylab.figure() + + self.ax = self.fig.add_subplot(111) + self.gid = gobject.timeout_add(1000, self.poll_draw()) + + print '...done' + pylab.show() + + +class NBPlot(object): + def __init__(self): + self.plot_pipe, plotter_pipe = Pipe() + self.plotter = ProcessPlotter() + self.plot_process = Process(target = self.plotter, + args = (plotter_pipe,)) + self.plot_process.daemon = True + self.plot_process.start() + + def plot(self, finished=False): + send = self.plot_pipe.send + if finished: + send(None) + else: + data = np.random.random(2) + send(data) + +def main(): + pl = NBPlot() + for ii in xrange(10): + pl.plot() + time.sleep(0.5) + raw_input('press Enter...') + pl.plot(finished=True) + +if __name__ == '__main__': + main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-05-07 03:40:46
|
Revision: 7089 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7089&view=rev Author: leejjoon Date: 2009-05-07 03:40:40 +0000 (Thu, 07 May 2009) Log Message: ----------- per-artist rasterization Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/artist.py trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/axis.py trunk/matplotlib/lib/matplotlib/collections.py trunk/matplotlib/lib/matplotlib/figure.py trunk/matplotlib/lib/matplotlib/image.py trunk/matplotlib/lib/matplotlib/legend.py trunk/matplotlib/lib/matplotlib/lines.py trunk/matplotlib/lib/matplotlib/patches.py trunk/matplotlib/lib/matplotlib/quiver.py trunk/matplotlib/lib/matplotlib/table.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-06 23:02:57 UTC (rev 7088) +++ trunk/matplotlib/CHANGELOG 2009-05-07 03:40:40 UTC (rev 7089) @@ -1,4 +1,6 @@ ====================================================================== +2009-05-06 Per-artist Rasterization, originally by Eric Bruning. -JJ + 2009-05-05 Add an example that shows how to make a plot that updates using data from another process. Thanks to Robert Cimrman - RMM Modified: trunk/matplotlib/lib/matplotlib/artist.py =================================================================== --- trunk/matplotlib/lib/matplotlib/artist.py 2009-05-06 23:02:57 UTC (rev 7088) +++ trunk/matplotlib/lib/matplotlib/artist.py 2009-05-07 03:40:40 UTC (rev 7089) @@ -22,6 +22,38 @@ # http://groups.google.com/groups?hl=en&lr=&threadm=mailman.5090.1098044946.5135.python-list%40python.org&rnum=1&prev=/groups%3Fq%3D__doc__%2Bauthor%253Ajdhunter%2540ace.bsd.uchicago.edu%26hl%3Den%26btnG%3DGoogle%2BSearch + + +def allow_rasterization(draw): + """ + Decorator for Artist.draw method. Provides routines + that run before and after the draw call. The before and after functions + are useful for changing artist-dependant renderer attributes or making + other setup function calls, such as starting and flushing a mixed-mode + renderer. + """ + def before(artist, renderer): + if artist.get_rasterized(): + renderer.start_rasterizing() + + def after(artist, renderer): + if artist.get_rasterized(): + renderer.stop_rasterizing() + + # the axes class has a second argument inframe for its draw method. + def draw_wrapper(artist, renderer, *kl): + before(artist, renderer) + draw(artist, renderer, *kl) + after(artist, renderer) + + # "safe wrapping" to exactly replicate anything we haven't overridden above + draw_wrapper.__name__ = draw.__name__ + draw_wrapper.__dict__ = draw.__dict__ + draw_wrapper.__doc__ = draw.__doc__ + draw_wrapper._supports_rasterization = True + return draw_wrapper + + class Artist(object): """ Abstract base class for someone who renders into a @@ -45,6 +77,7 @@ self._label = '' self._picker = None self._contains = None + self._rasterized = None self.eventson = False # fire events only if eventson self._oid = 0 # an observer id @@ -510,7 +543,23 @@ else: gc.set_clip_rectangle(None) gc.set_clip_path(None) + + def get_rasterized(self): + return self._rasterized + + def set_rasterized(self, rasterized): + """ + Force rasterized (bitmap) drawing in vector backend output. + + Defaults to None, which implies the backend's default behavior + + ACCEPTS: [True | False | None] + """ + if rasterized and not hasattr(self.draw, "_supports_rasterization"): + warnings.warn("Rasterization of '%s' will be ignored" % self) + self._rasterized = rasterized + def draw(self, renderer, *args, **kwargs): 'Derived classes drawing method' if not self.get_visible(): return Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-05-06 23:02:57 UTC (rev 7088) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-05-07 03:40:40 UTC (rev 7089) @@ -1602,6 +1602,7 @@ #### Drawing + @allow_rasterization def draw(self, renderer=None, inframe=False): "Draw everything (plot lines, axes, labels)" if renderer is None: Modified: trunk/matplotlib/lib/matplotlib/axis.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axis.py 2009-05-06 23:02:57 UTC (rev 7088) +++ trunk/matplotlib/lib/matplotlib/axis.py 2009-05-07 03:40:40 UTC (rev 7089) @@ -5,6 +5,7 @@ from matplotlib import rcParams import matplotlib.artist as artist +from matplotlib.artist import allow_rasterization import matplotlib.cbook as cbook import matplotlib.font_manager as font_manager import matplotlib.lines as mlines @@ -176,6 +177,7 @@ 'Return the tick location (data coords) as a scalar' return self._loc + @allow_rasterization def draw(self, renderer): if not self.get_visible(): return renderer.open_group(self.__name__) @@ -719,6 +721,7 @@ bbox2 = mtransforms.Bbox.from_extents(0, 0, 0, 0) return bbox, bbox2 + @allow_rasterization def draw(self, renderer, *args, **kwargs): 'Draw the axis lines, grid lines, tick lines and labels' ticklabelBoxes = [] Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2009-05-06 23:02:57 UTC (rev 7088) +++ trunk/matplotlib/lib/matplotlib/collections.py 2009-05-07 03:40:40 UTC (rev 7089) @@ -17,6 +17,7 @@ import matplotlib.cm as cm import matplotlib.transforms as transforms import matplotlib.artist as artist +from matplotlib.artist import allow_rasterization import matplotlib.backend_bases as backend_bases import matplotlib.path as mpath import matplotlib.mlab as mlab @@ -190,6 +191,7 @@ return transform, transOffset, offsets, paths + @allow_rasterization def draw(self, renderer): if not self.get_visible(): return renderer.open_group(self.__class__.__name__) @@ -594,6 +596,7 @@ def get_datalim(self, transData): return self._bbox + @allow_rasterization def draw(self, renderer): if not self.get_visible(): return renderer.open_group(self.__class__.__name__) @@ -781,6 +784,7 @@ __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd + @allow_rasterization def draw(self, renderer): self._transforms = [ transforms.Affine2D().rotate(-self._rotation).scale( Modified: trunk/matplotlib/lib/matplotlib/figure.py =================================================================== --- trunk/matplotlib/lib/matplotlib/figure.py 2009-05-06 23:02:57 UTC (rev 7088) +++ trunk/matplotlib/lib/matplotlib/figure.py 2009-05-07 03:40:40 UTC (rev 7089) @@ -15,7 +15,7 @@ import time import artist -from artist import Artist +from artist import Artist, allow_rasterization from axes import Axes, SubplotBase, subplot_class_factory from cbook import flatten, allequal, Stack, iterable, dedent import _image @@ -727,6 +727,7 @@ """ self.clf() + @allow_rasterization def draw(self, renderer): """ Render the figure using :class:`matplotlib.backend_bases.RendererBase` instance renderer Modified: trunk/matplotlib/lib/matplotlib/image.py =================================================================== --- trunk/matplotlib/lib/matplotlib/image.py 2009-05-06 23:02:57 UTC (rev 7088) +++ trunk/matplotlib/lib/matplotlib/image.py 2009-05-07 03:40:40 UTC (rev 7089) @@ -11,6 +11,7 @@ from matplotlib import rcParams import matplotlib.artist as martist +from matplotlib.artist import allow_rasterization import matplotlib.colors as mcolors import matplotlib.cm as cm import matplotlib.cbook as cbook @@ -225,7 +226,7 @@ norm=self._filternorm, radius=self._filterrad) return im - + @allow_rasterization def draw(self, renderer, *args, **kwargs): if not self.get_visible(): return if (self.axes.get_xscale() != 'linear' or @@ -571,6 +572,7 @@ im.is_grayscale = self.is_grayscale return im + @allow_rasterization def draw(self, renderer, *args, **kwargs): if not self.get_visible(): return im = self.make_image(renderer.get_image_magnification()) @@ -723,6 +725,7 @@ return im + @allow_rasterization def draw(self, renderer, *args, **kwargs): if not self.get_visible(): return # todo: we should be able to do some cacheing here Modified: trunk/matplotlib/lib/matplotlib/legend.py =================================================================== --- trunk/matplotlib/lib/matplotlib/legend.py 2009-05-06 23:02:57 UTC (rev 7088) +++ trunk/matplotlib/lib/matplotlib/legend.py 2009-05-07 03:40:40 UTC (rev 7089) @@ -26,7 +26,7 @@ import numpy as np from matplotlib import rcParams -from matplotlib.artist import Artist +from matplotlib.artist import Artist, allow_rasterization from matplotlib.cbook import is_string_like, iterable, silent_list, safezip from matplotlib.font_manager import FontProperties from matplotlib.lines import Line2D @@ -323,6 +323,7 @@ return x+xdescent, y+ydescent + @allow_rasterization def draw(self, renderer): "Draw everything that belongs to the legend" if not self.get_visible(): return Modified: trunk/matplotlib/lib/matplotlib/lines.py =================================================================== --- trunk/matplotlib/lib/matplotlib/lines.py 2009-05-06 23:02:57 UTC (rev 7088) +++ trunk/matplotlib/lib/matplotlib/lines.py 2009-05-07 03:40:40 UTC (rev 7089) @@ -18,6 +18,8 @@ from transforms import Affine2D, Bbox, TransformedPath, IdentityTransform from matplotlib import rcParams +from artist import allow_rasterization + # special-purpose marker identifiers: (TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN, CARETLEFT, CARETRIGHT, CARETUP, CARETDOWN) = range(8) @@ -459,6 +461,7 @@ if len(x)<2: return 1 return np.alltrue(x[1:]-x[0:-1]>=0) + @allow_rasterization def draw(self, renderer): if self._invalid: self.recache() Modified: trunk/matplotlib/lib/matplotlib/patches.py =================================================================== --- trunk/matplotlib/lib/matplotlib/patches.py 2009-05-06 23:02:57 UTC (rev 7088) +++ trunk/matplotlib/lib/matplotlib/patches.py 2009-05-07 03:40:40 UTC (rev 7089) @@ -7,6 +7,7 @@ import numpy as np import matplotlib.cbook as cbook import matplotlib.artist as artist +from matplotlib.artist import allow_rasterization import matplotlib.colors as colors import matplotlib.transforms as transforms from matplotlib.path import Path @@ -260,7 +261,7 @@ 'Return the current hatching pattern' return self._hatch - + @allow_rasterization def draw(self, renderer): 'Draw the :class:`Patch` to the given *renderer*.' if not self.get_visible(): return @@ -1176,6 +1177,7 @@ self.theta2 = theta2 __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd + @allow_rasterization def draw(self, renderer): """ Ellipses are normally drawn using an approximation that uses Modified: trunk/matplotlib/lib/matplotlib/quiver.py =================================================================== --- trunk/matplotlib/lib/matplotlib/quiver.py 2009-05-06 23:02:57 UTC (rev 7088) +++ trunk/matplotlib/lib/matplotlib/quiver.py 2009-05-07 03:40:40 UTC (rev 7089) @@ -21,6 +21,7 @@ import matplotlib.transforms as transforms import matplotlib.text as mtext import matplotlib.artist as martist +from matplotlib.artist import allow_rasterization import matplotlib.font_manager as font_manager from matplotlib.cbook import delete_masked_points from matplotlib.patches import CirclePolygon @@ -282,6 +283,7 @@ else: return y + @allow_rasterization def draw(self, renderer): self._init() self.vector.draw(renderer) @@ -418,6 +420,7 @@ if self.width is None: self.width = 0.06 * self.span / sn + @allow_rasterization def draw(self, renderer): self._init() if self._new_UV or self.angles == 'xy': Modified: trunk/matplotlib/lib/matplotlib/table.py =================================================================== --- trunk/matplotlib/lib/matplotlib/table.py 2009-05-06 23:02:57 UTC (rev 7088) +++ trunk/matplotlib/lib/matplotlib/table.py 2009-05-07 03:40:40 UTC (rev 7089) @@ -23,7 +23,7 @@ import warnings import artist -from artist import Artist +from artist import Artist, allow_rasterization from patches import Rectangle from cbook import is_string_like from text import Text @@ -90,6 +90,7 @@ return fontsize + @allow_rasterization def draw(self, renderer): if not self.get_visible(): return # draw the rectangle @@ -215,6 +216,7 @@ def _approx_text_height(self): return self.FONTSIZE/72.0*self.figure.dpi/self._axes.bbox.height * 1.2 + @allow_rasterization def draw(self, renderer): # Need a renderer to do hit tests on mouseevent; assume the last one will do if renderer is None: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-05-07 03:51:04
|
Revision: 7090 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7090&view=rev Author: leejjoon Date: 2009-05-07 03:50:55 +0000 (Thu, 07 May 2009) Log Message: ----------- print_ps with mixed-renderer Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/backend_bases.py trunk/matplotlib/lib/matplotlib/backends/backend_ps.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-07 03:40:40 UTC (rev 7089) +++ trunk/matplotlib/CHANGELOG 2009-05-07 03:50:55 UTC (rev 7090) @@ -1,4 +1,8 @@ ====================================================================== +2009-05-06 print_ps now uses mixed-mode renderer. Axes.draw rasterize + artists whose zorder smaller than rasterization_zorder. + -JJL + 2009-05-06 Per-artist Rasterization, originally by Eric Bruning. -JJ 2009-05-05 Add an example that shows how to make a plot that updates Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-05-07 03:40:40 UTC (rev 7089) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-05-07 03:50:55 UTC (rev 7090) @@ -8,6 +8,7 @@ rcParams = matplotlib.rcParams import matplotlib.artist as martist +from matplotlib.artist import allow_rasterization import matplotlib.axis as maxis import matplotlib.cbook as cbook import matplotlib.collections as mcoll @@ -531,6 +532,8 @@ self._frameon = frameon self._axisbelow = rcParams['axes.axisbelow'] + self._rasterization_zorder = -30000 + self._hold = rcParams['axes.hold'] self._connected = {} # a dict from events to (id, func) self.cla() @@ -1566,6 +1569,19 @@ """ self._autoscaleYon = b + def set_rasterization_zorder(self, z): + """ + Set zorder value below which artists will be rasterized + """ + self._rasterization_zorder = z + + def get_rasterization_zorder(self): + """ + Get zorder value below which artists will be rasterized + """ + return self._rasterization_zorder + + def autoscale_view(self, tight=False, scalex=True, scaley=True): """ autoscale the view limits using the data limits. You can @@ -1620,15 +1636,55 @@ else: self.apply_aspect() + + artists = [] + + artists.extend(self.collections) + artists.extend(self.patches) + artists.extend(self.lines) + artists.extend(self.texts) + artists.extend(self.artists) + if self.axison and not inframe: + if self._axisbelow: + self.xaxis.set_zorder(0.5) + self.yaxis.set_zorder(0.5) + else: + self.xaxis.set_zorder(2.5) + self.yaxis.set_zorder(2.5) + artists.extend([self.xaxis, self.yaxis]) + if not inframe: artists.append(self.title) + artists.extend(self.tables) + if self.legend_ is not None: + artists.append(self.legend_) + + # the frame draws the edges around the axes patch -- we + # decouple these so the patch can be in the background and the + # frame in the foreground. + if self.axison and self._frameon: + artists.append(self.frame) + + + dsu = [ (a.zorder, i, a) for i, a in enumerate(artists) + if not a.get_animated() ] + dsu.sort() + + + # rasterze artists with negative zorder + # if the minimum zorder is negative, start rasterization + rasterization_zorder = self._rasterization_zorder + if len(dsu) > 0 and dsu[0][0] < rasterization_zorder: + renderer.start_rasterizing() + dsu_rasterized = [l for l in dsu if l[0] < rasterization_zorder] + dsu = [l for l in dsu if l[0] >= rasterization_zorder] + else: + dsu_rasterized = [] + + # the patch draws the background rectangle -- the frame below # will draw the edges if self.axison and self._frameon: self.patch.draw(renderer) - artists = [] - - - if len(self.images)<=1 or renderer.option_image_nocomposite(): for im in self.images: im.draw(renderer) @@ -1657,35 +1713,13 @@ self.patch.get_path(), self.patch.get_transform()) - artists.extend(self.collections) - artists.extend(self.patches) - artists.extend(self.lines) - artists.extend(self.texts) - artists.extend(self.artists) - if self.axison and not inframe: - if self._axisbelow: - self.xaxis.set_zorder(0.5) - self.yaxis.set_zorder(0.5) - else: - self.xaxis.set_zorder(2.5) - self.yaxis.set_zorder(2.5) - artists.extend([self.xaxis, self.yaxis]) - if not inframe: artists.append(self.title) - artists.extend(self.tables) - if self.legend_ is not None: - artists.append(self.legend_) - # the frame draws the edges around the axes patch -- we - # decouple these so the patch can be in the background and the - # frame in the foreground. - if self.axison and self._frameon: - artists.append(self.frame) + if dsu_rasterized: + for zorder, i, a in dsu_rasterized: + a.draw(renderer) + renderer.stop_rasterizing() - dsu = [ (a.zorder, i, a) for i, a in enumerate(artists) - if not a.get_animated() ] - dsu.sort() - for zorder, i, a in dsu: a.draw(renderer) Modified: trunk/matplotlib/lib/matplotlib/backend_bases.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backend_bases.py 2009-05-07 03:40:40 UTC (rev 7089) +++ trunk/matplotlib/lib/matplotlib/backend_bases.py 2009-05-07 03:50:55 UTC (rev 7090) @@ -1443,6 +1443,7 @@ facecolor=facecolor, edgecolor=edgecolor, orientation=orientation, + dryrun=True, **kwargs) renderer = self.figure._cachedRenderer bbox_inches = self.figure.get_tightbbox(renderer) Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-05-07 03:40:40 UTC (rev 7089) +++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-05-07 03:50:55 UTC (rev 7090) @@ -33,6 +33,9 @@ from matplotlib.path import Path from matplotlib.transforms import Affine2D +from matplotlib.backends.backend_mixed import MixedModeRenderer + + import numpy as npy import binascii import re @@ -843,8 +846,13 @@ def print_eps(self, outfile, *args, **kwargs): return self._print_ps(outfile, 'eps', *args, **kwargs) + + + + + def _print_ps(self, outfile, format, *args, **kwargs): - papertype = kwargs.get("papertype", rcParams['ps.papersize']) + papertype = kwargs.pop("papertype", rcParams['ps.papersize']) papertype = papertype.lower() if papertype == 'auto': pass @@ -852,25 +860,28 @@ raise RuntimeError( '%s is not a valid papertype. Use one \ of %s'% (papertype, ', '.join( papersize.keys() )) ) - orientation = kwargs.get("orientation", "portrait").lower() + orientation = kwargs.pop("orientation", "portrait").lower() if orientation == 'landscape': isLandscape = True elif orientation == 'portrait': isLandscape = False else: raise RuntimeError('Orientation must be "portrait" or "landscape"') self.figure.set_dpi(72) # Override the dpi kwarg - imagedpi = kwargs.get("dpi", 72) - facecolor = kwargs.get("facecolor", "w") - edgecolor = kwargs.get("edgecolor", "w") + imagedpi = kwargs.pop("dpi", 72) + facecolor = kwargs.pop("facecolor", "w") + edgecolor = kwargs.pop("edgecolor", "w") if rcParams['text.usetex']: self._print_figure_tex(outfile, format, imagedpi, facecolor, edgecolor, - orientation, isLandscape, papertype) + orientation, isLandscape, papertype, + **kwargs) else: self._print_figure(outfile, format, imagedpi, facecolor, edgecolor, - orientation, isLandscape, papertype) + orientation, isLandscape, papertype, + **kwargs) def _print_figure(self, outfile, format, dpi=72, facecolor='w', edgecolor='w', - orientation='portrait', isLandscape=False, papertype=None): + orientation='portrait', isLandscape=False, papertype=None, + **kwargs): """ Render the figure to hardcopy. Set the figure patch face and edge colors. This is useful because some of the GUIs have a @@ -939,10 +950,30 @@ self.figure.set_facecolor(facecolor) self.figure.set_edgecolor(edgecolor) - self._pswriter = StringIO() - renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi) + + dryrun = kwargs.get("dryrun", False) + if dryrun: + class NullWriter(object): + def write(self, *kl, **kwargs): + pass + + self._pswriter = NullWriter() + else: + self._pswriter = StringIO() + + + # mixed mode rendering + _bbox_inches_restore = kwargs.pop("bbox_inches_restore", None) + ps_renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi) + renderer = MixedModeRenderer(self.figure, + width, height, dpi, ps_renderer, + bbox_inches_restore=_bbox_inches_restore) + self.figure.draw(renderer) + if dryrun: # return immediately if dryrun (tightbbox=True) + return + self.figure.set_facecolor(origfacecolor) self.figure.set_edgecolor(origedgecolor) @@ -962,7 +993,7 @@ Ndict = len(psDefs) print >>fh, "%%BeginProlog" if not rcParams['ps.useafm']: - Ndict += len(renderer.used_characters) + Ndict += len(ps_renderer.used_characters) print >>fh, "/mpldict %d dict def"%Ndict print >>fh, "mpldict begin" for d in psDefs: @@ -970,7 +1001,7 @@ for l in d.split('\n'): print >>fh, l.strip() if not rcParams['ps.useafm']: - for font_filename, chars in renderer.used_characters.values(): + for font_filename, chars in ps_renderer.used_characters.values(): if len(chars): font = FT2Font(font_filename) cmap = font.get_charmap() @@ -1019,7 +1050,8 @@ shutil.move(tmpfile, outfile) def _print_figure_tex(self, outfile, format, dpi, facecolor, edgecolor, - orientation, isLandscape, papertype): + orientation, isLandscape, papertype, + **kwargs): """ If text.usetex is True in rc, a temporary pair of tex/eps files are created to allow tex to manage the text layout via the PSFrags @@ -1051,10 +1083,29 @@ self.figure.set_facecolor(facecolor) self.figure.set_edgecolor(edgecolor) - self._pswriter = StringIO() - renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi) + dryrun = kwargs.get("dryrun", False) + if dryrun: + class NullWriter(object): + def write(self, *kl, **kwargs): + pass + + self._pswriter = NullWriter() + else: + self._pswriter = StringIO() + + + # mixed mode rendering + _bbox_inches_restore = kwargs.pop("bbox_inches_restore", None) + ps_renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi) + renderer = MixedModeRenderer(self.figure, + width, height, dpi, ps_renderer, + bbox_inches_restore=_bbox_inches_restore) + self.figure.draw(renderer) + if dryrun: # return immediately if dryrun (tightbbox=True) + return + self.figure.set_facecolor(origfacecolor) self.figure.set_edgecolor(origedgecolor) @@ -1117,11 +1168,11 @@ paper will be used to prevent clipping.'%(papertype, temp_papertype), 'helpful') - texmanager = renderer.get_texmanager() + texmanager = ps_renderer.get_texmanager() font_preamble = texmanager.get_font_preamble() custom_preamble = texmanager.get_custom_preamble() - convert_psfrags(tmpfile, renderer.psfrag, font_preamble, + convert_psfrags(tmpfile, ps_renderer.psfrag, font_preamble, custom_preamble, paperWidth, paperHeight, orientation) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ry...@us...> - 2009-05-07 19:33:43
|
Revision: 7096 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7096&view=rev Author: ryanmay Date: 2009-05-07 19:33:33 +0000 (Thu, 07 May 2009) Log Message: ----------- Move from LABELPAD class attribute on an Axis to a labelpad instance attribute. Add a label argument to Axes.set_[xy]label to control the spacing between a label and its axis. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/axis.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-07 18:14:01 UTC (rev 7095) +++ trunk/matplotlib/CHANGELOG 2009-05-07 19:33:33 UTC (rev 7096) @@ -1,4 +1,8 @@ ====================================================================== +2009-05-07 'labelpad' can now be passed when setting x/y labels. This + allows controlling the spacing between the label and its + axis. - RMM + 2009-05-06 print_ps now uses mixed-mode renderer. Axes.draw rasterize artists whose zorder smaller than rasterization_zorder. -JJL Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-05-07 18:14:01 UTC (rev 7095) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-05-07 19:33:33 UTC (rev 7096) @@ -1579,7 +1579,7 @@ """ Get zorder value below which artists will be rasterized """ - return self._rasterization_zorder + return self._rasterization_zorder def autoscale_view(self, tight=False, scalex=True, scaley=True): @@ -1678,8 +1678,8 @@ dsu = [l for l in dsu if l[0] >= rasterization_zorder] else: dsu_rasterized = [] - - + + # the patch draws the background rectangle -- the frame below # will draw the edges if self.axison and self._frameon: @@ -2721,14 +2721,16 @@ label = self.xaxis.get_label() return label.get_text() - def set_xlabel(self, xlabel, fontdict=None, **kwargs): + def set_xlabel(self, xlabel, fontdict=None, labelpad=None, **kwargs): """ call signature:: - set_xlabel(xlabel, fontdict=None, **kwargs) + set_xlabel(xlabel, fontdict=None, labelpad=None, **kwargs) Set the label for the xaxis. + *labelpad* is the spacing in points between the label and the x-axis + Valid kwargs are Text properties: %(Text)s ACCEPTS: str @@ -2738,6 +2740,7 @@ :meth:`text` for information on how override and the optional args work """ + if labelpad is not None: self.xaxis.labelpad = labelpad return self.xaxis.set_label_text(xlabel, fontdict, **kwargs) set_xlabel.__doc__ = cbook.dedent(set_xlabel.__doc__) % martist.kwdocd @@ -2748,14 +2751,16 @@ label = self.yaxis.get_label() return label.get_text() - def set_ylabel(self, ylabel, fontdict=None, **kwargs): + def set_ylabel(self, ylabel, fontdict=None, labelpad=None, **kwargs): """ call signature:: - set_ylabel(ylabel, fontdict=None, **kwargs) + set_ylabel(ylabel, fontdict=None, labelpad=None, **kwargs) Set the label for the yaxis + *labelpad* is the spacing in points between the label and the y-axis + Valid kwargs are Text properties: %(Text)s ACCEPTS: str @@ -2765,6 +2770,7 @@ :meth:`text` for information on how override and the optional args work """ + if labelpad is not None: self.yaxis.labelpad = labelpad return self.yaxis.set_label_text(ylabel, fontdict, **kwargs) set_ylabel.__doc__ = cbook.dedent(set_ylabel.__doc__) % martist.kwdocd @@ -3816,7 +3822,7 @@ h, l = ax.get_legend_handles_labels() ax.legend(h, l) - + """ handles = [] Modified: trunk/matplotlib/lib/matplotlib/axis.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axis.py 2009-05-07 18:14:01 UTC (rev 7095) +++ trunk/matplotlib/lib/matplotlib/axis.py 2009-05-07 19:33:33 UTC (rev 7096) @@ -500,9 +500,8 @@ * :attr:`transData` - transform data coords to display coords * :attr:`transAxis` - transform axis coords to display coords - + * :attr:`labelpad` - number of points between the axis and its label """ - LABELPAD = 5 OFFSETTEXTPAD = 3 def __str__(self): @@ -538,6 +537,7 @@ self._autolabelpos = True self.label = self._get_label() + self.labelpad = 5 self.offsetText = self._get_offset_text() self.majorTicks = [] self.minorTicks = [] @@ -1267,7 +1267,7 @@ else: bbox = mtransforms.Bbox.union(bboxes) bottom = bbox.y0 - self.label.set_position( (x, bottom - self.LABELPAD*self.figure.dpi / 72.0)) + self.label.set_position( (x, bottom - self.labelpad*self.figure.dpi / 72.0)) else: if not len(bboxes2): @@ -1275,7 +1275,7 @@ else: bbox = mtransforms.Bbox.union(bboxes2) top = bbox.y1 - self.label.set_position( (x, top+self.LABELPAD*self.figure.dpi / 72.0)) + self.label.set_position( (x, top+self.labelpad*self.figure.dpi / 72.0)) def _update_offset_text_position(self, bboxes, bboxes2): """ @@ -1506,7 +1506,7 @@ bbox = mtransforms.Bbox.union(bboxes) left = bbox.x0 - self.label.set_position( (left-self.LABELPAD*self.figure.dpi/72.0, y)) + self.label.set_position( (left-self.labelpad*self.figure.dpi/72.0, y)) else: if not len(bboxes2): @@ -1515,7 +1515,7 @@ bbox = mtransforms.Bbox.union(bboxes2) right = bbox.x1 - self.label.set_position( (right+self.LABELPAD*self.figure.dpi/72.0, y)) + self.label.set_position( (right+self.labelpad*self.figure.dpi/72.0, y)) def _update_offset_text_position(self, bboxes, bboxes2): """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2009-05-08 19:04:42
|
Revision: 7097 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7097&view=rev Author: efiring Date: 2009-05-08 19:04:34 +0000 (Fri, 08 May 2009) Log Message: ----------- clabel takes new kwarg, rightside_up (defaults to True) Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/contour.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-07 19:33:33 UTC (rev 7096) +++ trunk/matplotlib/CHANGELOG 2009-05-08 19:04:34 UTC (rev 7097) @@ -1,4 +1,9 @@ ====================================================================== +2009-05-08 clabel takes new kwarg, rightside_up; if False, labels + will not be flipped to keep them rightside-up. This + allows the use of clabel to make streamfunction arrows, + as requested by Evan Mason. - EF + 2009-05-07 'labelpad' can now be passed when setting x/y labels. This allows controlling the spacing between the label and its axis. - RMM Modified: trunk/matplotlib/lib/matplotlib/contour.py =================================================================== --- trunk/matplotlib/lib/matplotlib/contour.py 2009-05-07 19:33:33 UTC (rev 7096) +++ trunk/matplotlib/lib/matplotlib/contour.py 2009-05-08 19:04:34 UTC (rev 7097) @@ -91,6 +91,10 @@ placement, delete or backspace act like the third mouse button, and any other key will select a label location). + *rightside_up*: + if *True* (default), label rotations will always be plus + or minus 90 degrees from level. + .. plot:: mpl_examples/pylab_examples/contour_demo.py """ @@ -116,6 +120,8 @@ # Detect if manual selection is desired and remove from argument list self.labelManual=kwargs.get('manual',False) + self.rightside_up = kwargs.get('rightside_up', True) + if len(args) == 0: levels = self.levels indices = range(len(self.levels)) @@ -381,11 +387,12 @@ else: rotation = np.arctan2(dd[1], dd[0]) * 180.0 / np.pi - # Fix angle so text is never upside-down - if rotation > 90: - rotation = rotation - 180.0 - if rotation < -90: - rotation = 180.0 + rotation + if self.rightside_up: + # Fix angle so text is never upside-down + if rotation > 90: + rotation = rotation - 180.0 + if rotation < -90: + rotation = 180.0 + rotation # Break contour if desired nlc = [] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-05-12 04:12:11
|
Revision: 7098 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7098&view=rev Author: leejjoon Date: 2009-05-12 04:12:07 +0000 (Tue, 12 May 2009) Log Message: ----------- aspect for log-log plot Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py Added Paths: ----------- trunk/matplotlib/examples/pylab_examples/aspect_loglog.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-08 19:04:34 UTC (rev 7097) +++ trunk/matplotlib/CHANGELOG 2009-05-12 04:12:07 UTC (rev 7098) @@ -1,4 +1,6 @@ ====================================================================== +2009-05-11 aspect=1 in log-log plot gives square decades. + 2009-05-08 clabel takes new kwarg, rightside_up; if False, labels will not be flipped to keep them rightside-up. This allows the use of clabel to make streamfunction arrows, Added: trunk/matplotlib/examples/pylab_examples/aspect_loglog.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/aspect_loglog.py (rev 0) +++ trunk/matplotlib/examples/pylab_examples/aspect_loglog.py 2009-05-12 04:12:07 UTC (rev 7098) @@ -0,0 +1,22 @@ +import matplotlib.pyplot as plt + +ax1 = plt.subplot(121) +ax1.set_xscale("log") +ax1.set_yscale("log") +ax1.set_xlim(1e1, 1e3) +ax1.set_ylim(1e2, 1e3) +ax1.set_aspect(1) +ax1.set_title("adjustable = box") + +ax2 = plt.subplot(122) +ax2.set_xscale("log") +ax2.set_yscale("log") +ax2.set_adjustable("datalim") +ax2.plot([1,3, 10], [1, 9, 100], "o-") +ax2.set_xlim(1e-1, 1e2) +ax2.set_ylim(1e-1, 1e3) +ax2.set_aspect(1) +ax2.set_title("adjustable = datalim") + +plt.draw() +plt.show() Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-05-08 19:04:34 UTC (rev 7097) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-05-12 04:12:07 UTC (rev 7098) @@ -1085,7 +1085,7 @@ raise ValueError('argument must be among %s' % ', '.join(mtransforms.BBox.coefs.keys())) - def get_data_ratio(self): + def get_data_ratio(self, mode="linear"): """ Returns the aspect ratio of the raw data. @@ -1093,11 +1093,18 @@ types. """ xmin,xmax = self.get_xbound() - xsize = max(math.fabs(xmax-xmin), 1e-30) ymin,ymax = self.get_ybound() - ysize = max(math.fabs(ymax-ymin), 1e-30) + + if mode == "log": + xsize = max(math.fabs(math.log10(xmax)-math.log10(xmin)), 1e-30) + ysize = max(math.fabs(math.log10(ymax)-math.log10(ymin)), 1e-30) + else: + xsize = max(math.fabs(xmax-xmin), 1e-30) + ysize = max(math.fabs(ymax-ymin), 1e-30) + return ysize/xsize + def apply_aspect(self, position=None): ''' Use :meth:`_aspect` and :meth:`_adjustable` to modify the @@ -1106,7 +1113,20 @@ if position is None: position = self.get_position(original=True) + aspect = self.get_aspect() + + xscale, yscale = self.get_xscale(), self.get_yscale() + if xscale == "linear" and yscale == "linear": + aspect_scale_mode = "linear" + elif xscale == "log" and yscale == "log": + aspect_scale_mode = "log" + else: + warnings.warn( + 'aspect is not supported for Axes with xscale=%s, yscale=%s' \ + % (xscale, yscale)) + aspect = "auto" + if aspect == 'auto': self.set_position( position , which='active') return @@ -1127,7 +1147,7 @@ figW,figH = self.get_figure().get_size_inches() fig_aspect = figH/figW if self._adjustable == 'box': - box_aspect = A * self.get_data_ratio() + box_aspect = A * self.get_data_ratio(mode=aspect_scale_mode) pb = position.frozen() pb1 = pb.shrunk_to_aspect(box_aspect, pb, fig_aspect) self.set_position(pb1.anchored(self.get_anchor(), pb), 'active') @@ -1137,11 +1157,18 @@ # by prior use of 'box' self.set_position(position, which='active') + xmin,xmax = self.get_xbound() + ymin,ymax = self.get_ybound() + + if aspect_scale_mode == "log": + xmin, xmax = math.log10(xmin), math.log10(xmax) + ymin, ymax = math.log10(ymin), math.log10(ymax) + xsize = max(math.fabs(xmax-xmin), 1e-30) - ymin,ymax = self.get_ybound() ysize = max(math.fabs(ymax-ymin), 1e-30) + l,b,w,h = position.bounds box_aspect = fig_aspect * (h/w) data_ratio = box_aspect / A @@ -1152,9 +1179,18 @@ if abs(y_expander) < 0.005: #print 'good enough already' return - dL = self.dataLim - xr = 1.05 * dL.width - yr = 1.05 * dL.height + + if aspect_scale_mode == "log": + dL = self.dataLim + dL_width = math.log10(dL.x1) - math.log10(dL.x0) + dL_height = math.log10(dL.y1) - math.log10(dL.y0) + xr = 1.05 * dL_width + yr = 1.05 * dL_height + else: + dL = self.dataLim + xr = 1.05 * dL.width + yr = 1.05 * dL.height + xmarg = xsize - xr ymarg = ysize - yr Ysize = data_ratio * xsize @@ -1189,14 +1225,20 @@ yc = 0.5*(ymin+ymax) y0 = yc - Ysize/2.0 y1 = yc + Ysize/2.0 - self.set_ybound((y0, y1)) + if aspect_scale_mode == "log": + self.set_ybound((10.**y0, 10.**y1)) + else: + self.set_ybound((y0, y1)) #print 'New y0, y1:', y0, y1 #print 'New ysize, ysize/xsize', y1-y0, (y1-y0)/xsize else: xc = 0.5*(xmin+xmax) x0 = xc - Xsize/2.0 x1 = xc + Xsize/2.0 - self.set_xbound((x0, x1)) + if aspect_scale_mode == "log": + self.set_xbound((10.**x0, 10.**x1)) + else: + self.set_xbound((x0, x1)) #print 'New x0, x1:', x0, x1 #print 'New xsize, ysize/xsize', x1-x0, ysize/(x1-x0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2009-05-13 19:59:28
|
Revision: 7100 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7100&view=rev Author: efiring Date: 2009-05-13 19:59:16 +0000 (Wed, 13 May 2009) Log Message: ----------- Experimental clipping of Line _transformed_path to speed zoom and pan. This can be modified to work with x monotonically decreasing, but for a first try it works only with x monotonically increasing. The intention is to greatly speed up zooming and panning into a small segment of a very long time series (e.g., 10^6 points) without incurring any significant speed penalty in other situations. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/lines.py trunk/matplotlib/lib/matplotlib/path.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-12 19:35:25 UTC (rev 7099) +++ trunk/matplotlib/CHANGELOG 2009-05-13 19:59:16 UTC (rev 7100) @@ -1,4 +1,11 @@ ====================================================================== +2009-05-13 When the x-coordinate of a line is monotonically + increasing, it is now automatically clipped at + the stage of generating the transformed path in + the draw method; this greatly speeds up zooming and + panning when one is looking at a short segment of + a long time series, for example. - EF + 2009-05-11 aspect=1 in log-log plot gives square decades. 2009-05-08 clabel takes new kwarg, rightside_up; if False, labels Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-05-12 19:35:25 UTC (rev 7099) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-05-13 19:59:16 UTC (rev 7100) @@ -765,7 +765,10 @@ self.xaxis.get_transform(), self.yaxis.get_transform())) if hasattr(self, "lines"): for line in self.lines: - line._transformed_path.invalidate() + try: + line._transformed_path.invalidate() + except AttributeError: + pass def get_position(self, original=False): 'Return the a copy of the axes rectangle as a Bbox' Modified: trunk/matplotlib/lib/matplotlib/lines.py =================================================================== --- trunk/matplotlib/lib/matplotlib/lines.py 2009-05-12 19:35:25 UTC (rev 7099) +++ trunk/matplotlib/lib/matplotlib/lines.py 2009-05-13 19:59:16 UTC (rev 7100) @@ -440,12 +440,22 @@ self._x = self._xy[:, 0] # just a view self._y = self._xy[:, 1] # just a view - # Masked arrays are now handled by the Path class itself + self._subslice = False + if len(x) > 100 and self._is_sorted(x): + self._subslice = True self._path = Path(self._xy) - self._transformed_path = TransformedPath(self._path, self.get_transform()) - + self._transformed_path = None self._invalid = False + def _transform_path(self, subslice=None): + # Masked arrays are now handled by the Path class itself + if subslice is not None: + _path = Path(self._xy[subslice,:]) + else: + _path = self._path + self._transformed_path = TransformedPath(_path, self.get_transform()) + + def set_transform(self, t): """ set the Transformation instance used by this artist @@ -454,7 +464,6 @@ """ Artist.set_transform(self, t) self._invalid = True - # self._transformed_path = TransformedPath(self._path, self.get_transform()) def _is_sorted(self, x): "return true if x is sorted" @@ -465,7 +474,15 @@ def draw(self, renderer): if self._invalid: self.recache() - + if self._subslice: + # Need to handle monotonically decreasing case also... + x0, x1 = self.axes.get_xbound() + i0, = self._x.searchsorted([x0], 'left') + i1, = self._x.searchsorted([x1], 'right') + subslice = slice(max(i0-1, 0), i1+1) + self._transform_path(subslice) + if self._transformed_path is None: + self._transform_path() renderer.open_group('line2d', self.get_gid()) if not self._visible: return Modified: trunk/matplotlib/lib/matplotlib/path.py =================================================================== --- trunk/matplotlib/lib/matplotlib/path.py 2009-05-12 19:35:25 UTC (rev 7099) +++ trunk/matplotlib/lib/matplotlib/path.py 2009-05-13 19:59:16 UTC (rev 7100) @@ -118,7 +118,10 @@ (len(vertices) >= 128 and (codes is None or np.all(codes <= Path.LINETO)))) self.simplify_threshold = rcParams['path.simplify_threshold'] - self.has_nonfinite = not np.isfinite(vertices).all() + # The following operation takes most of the time in this + # initialization, and it does not appear to be used anywhere; + # if it is occasionally needed, it could be made a property. + #self.has_nonfinite = not np.isfinite(vertices).all() self.codes = codes self.vertices = vertices This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-05-14 04:00:41
|
Revision: 7101 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7101&view=rev Author: leejjoon Date: 2009-05-14 04:00:38 +0000 (Thu, 14 May 2009) Log Message: ----------- psfrag in backend_ps now uses baseline-alignment when preview.sty is used Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/backends/backend_ps.py trunk/matplotlib/lib/matplotlib/offsetbox.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-13 19:59:16 UTC (rev 7100) +++ trunk/matplotlib/CHANGELOG 2009-05-14 04:00:38 UTC (rev 7101) @@ -1,4 +1,9 @@ ====================================================================== +2009-05-13 psfrag in backend_ps now uses baseline-alignment + when preview.sty is used ((default is + bottom-alignment). Also, a small api imporvement + in OffsetBox-JJL + 2009-05-13 When the x-coordinate of a line is monotonically increasing, it is now automatically clipped at the stage of generating the transformed path in @@ -6,7 +11,7 @@ panning when one is looking at a short segment of a long time series, for example. - EF -2009-05-11 aspect=1 in log-log plot gives square decades. +2009-05-11 aspect=1 in log-log plot gives square decades. -JJL 2009-05-08 clabel takes new kwarg, rightside_up; if False, labels will not be flipped to keep them rightside-up. This Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-05-13 19:59:16 UTC (rev 7100) +++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-05-14 04:00:38 UTC (rev 7101) @@ -537,8 +537,6 @@ """ w, h, bl = self.get_text_width_height_descent(s, prop, ismath) fontsize = prop.get_size_in_points() - corr = 0#w/2*(fontsize-10)/10 - pos = _nums_to_str(x-corr, y) thetext = 'psmarker%d' % self.textcnt color = '%1.3f,%1.3f,%1.3f'% gc.get_rgb()[:3] fontcmd = {'sans-serif' : r'{\sffamily %s}', @@ -546,7 +544,17 @@ rcParams['font.family'], r'{\rmfamily %s}') s = fontcmd % s tex = r'\color[rgb]{%s} %s' % (color, s) - self.psfrag.append(r'\psfrag{%s}[bl][bl][1][%f]{\fontsize{%f}{%f}%s}'%(thetext, angle, fontsize, fontsize*1.25, tex)) + + corr = 0#w/2*(fontsize-10)/10 + if rcParams['text.latex.preview']: + # use baseline alignment! + pos = _nums_to_str(x-corr, y+bl) + self.psfrag.append(r'\psfrag{%s}[Bl][Bl][1][%f]{\fontsize{%f}{%f}%s}'%(thetext, angle, fontsize, fontsize*1.25, tex)) + else: + # stick to the bottom alignment, but this may give incorrect baseline some times. + pos = _nums_to_str(x-corr, y) + self.psfrag.append(r'\psfrag{%s}[bl][bl][1][%f]{\fontsize{%f}{%f}%s}'%(thetext, angle, fontsize, fontsize*1.25, tex)) + ps = """\ gsave %(pos)s moveto Modified: trunk/matplotlib/lib/matplotlib/offsetbox.py =================================================================== --- trunk/matplotlib/lib/matplotlib/offsetbox.py 2009-05-13 19:59:16 UTC (rev 7100) +++ trunk/matplotlib/lib/matplotlib/offsetbox.py 2009-05-14 04:00:38 UTC (rev 7101) @@ -782,11 +782,14 @@ explicitly specify the bbox_to_anchor. """ + zorder = 5 # zorder of the legend + def __init__(self, loc, pad=0.4, borderpad=0.5, child=None, prop=None, frameon=True, bbox_to_anchor=None, - bbox_transform=None): + bbox_transform=None, + **kwargs): """ loc is a string or an integer specifying the legend location. The valid location codes are:: @@ -819,7 +822,7 @@ """ - super(AnchoredOffsetbox, self).__init__() + super(AnchoredOffsetbox, self).__init__(**kwargs) self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform) self.set_child(child) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2009-05-14 06:28:11
|
Revision: 7102 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7102&view=rev Author: leejjoon Date: 2009-05-14 06:27:58 +0000 (Thu, 14 May 2009) Log Message: ----------- An optional offset and bbox support in restore_bbox Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/backends/backend_agg.py trunk/matplotlib/src/_backend_agg.cpp trunk/matplotlib/src/_backend_agg.h Added Paths: ----------- trunk/matplotlib/examples/animation/animation_blit_gtk2.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-05-14 04:00:38 UTC (rev 7101) +++ trunk/matplotlib/CHANGELOG 2009-05-14 06:27:58 UTC (rev 7102) @@ -1,4 +1,7 @@ ====================================================================== +2009-05-13 An optional offset and bbox support in restore_bbox. + Add animation_blit_gtk2.py. -JJL + 2009-05-13 psfrag in backend_ps now uses baseline-alignment when preview.sty is used ((default is bottom-alignment). Also, a small api imporvement Added: trunk/matplotlib/examples/animation/animation_blit_gtk2.py =================================================================== --- trunk/matplotlib/examples/animation/animation_blit_gtk2.py (rev 0) +++ trunk/matplotlib/examples/animation/animation_blit_gtk2.py 2009-05-14 06:27:58 UTC (rev 7102) @@ -0,0 +1,167 @@ +#!/usr/bin/env python + +""" +This example utlizes restore_region with optional bbox and xy +arguments. The plot is continuously shifted to the left. Instead of +drawing everything again, the plot is saved (copy_from_bbox) and +restored with offset by the amount of the shift. And only newly +exposed area is drawn. This technique may reduce drawing time for some cases. +""" + +import time + +import gtk, gobject + +import matplotlib +matplotlib.use('GTKAgg') + +import numpy as np +import matplotlib.pyplot as plt + +class UpdateLine(object): + def get_bg_bbox(self): + + return self.ax.bbox.padded(-3) + + def __init__(self, canvas, ax): + self.cnt = 0 + self.canvas = canvas + self.ax = ax + + self.prev_time = time.time() + self.start_time = self.prev_time + self.prev_pixel_offset = 0. + + + self.x0 = 0 + self.phases = np.random.random_sample((20,)) * np.pi * 2 + self.line, = ax.plot([], [], "-", animated=True, lw=2) + + self.point, = ax.plot([], [], "ro", animated=True, lw=2) + + self.ax.set_ylim(-1.1, 1.1) + + self.background1 = None + + cmap = plt.cm.jet + from itertools import cycle + self.color_cycle = cycle(cmap(np.arange(cmap.N))) + + + def save_bg(self): + self.background1 = self.canvas.copy_from_bbox(self.ax.get_figure().bbox) + + self.background2 = self.canvas.copy_from_bbox(self.get_bg_bbox()) + + + def get_dx_data(self, dx_pixel): + tp = self.ax.transData.inverted().transform_point + x0, y0 = tp((0, 0)) + x1, y1 = tp((dx_pixel, 0)) + return (x1-x0) + + + def restore_background_shifted(self, dx_pixel): + """ + restore bacground shifted by dx in data coordinate. This only + works if the data coordinate system is linear. + """ + + # restore the clean slate background + self.canvas.restore_region(self.background1) + + # restore subregion (x1+dx, y1, x2, y2) of the second bg + # in a offset position (x1-dx, y1) + x1, y1, x2, y2 = self.background2.get_extents() + self.canvas.restore_region(self.background2, + bbox=(x1+dx_pixel, y1, x2, y2), + xy=(x1-dx_pixel, y1)) + + return dx_pixel + + def on_draw(self, *args): + self.save_bg() + return False + + def update_line(self, *args): + + if self.background1 is None: + return True + + cur_time = time.time() + pixel_offset = int((cur_time - self.start_time)*100.) + dx_pixel = pixel_offset - self.prev_pixel_offset + self.prev_pixel_offset = pixel_offset + dx_data = self.get_dx_data(dx_pixel) #cur_time - self.prev_time) + + x0 = self.x0 + self.x0 += dx_data + self.prev_time = cur_time + + self.ax.set_xlim(self.x0-2, self.x0+0.1) + + + # restore background which will plot lines from previous plots + self.restore_background_shifted(dx_pixel) #x0, self.x0) + # This restores lines between [x0-2, x0] + + + + self.line.set_color(self.color_cycle.next()) + + # now plot line segment within [x0, x0+dx_data], + # Note that we're only plotting a line between [x0, x0+dx_data]. + xx = np.array([x0, self.x0]) + self.line.set_xdata(xx) + + # the for loop below could be improved by using collection. + [(self.line.set_ydata(np.sin(xx+p)), + self.ax.draw_artist(self.line)) \ + for p in self.phases] + + self.background2 = canvas.copy_from_bbox(self.get_bg_bbox()) + + self.point.set_xdata([self.x0]) + + [(self.point.set_ydata(np.sin([self.x0+p])), + self.ax.draw_artist(self.point)) \ + for p in self.phases] + + + self.ax.draw_artist(self.ax.xaxis) + self.ax.draw_artist(self.ax.yaxis) + + self.canvas.blit(self.ax.get_figure().bbox) + + + dt = (time.time()-tstart) + if dt>15: + # print the timing info and quit + print 'FPS:' , self.cnt/dt + gtk.main_quit() + raise SystemExit + + self.cnt += 1 + return True + + +plt.rcParams["text.usetex"] = False +fig = plt.figure() + +ax = fig.add_subplot(111) +ax.xaxis.set_animated(True) +ax.yaxis.set_animated(True) +canvas = fig.canvas + +fig.subplots_adjust(left=0.2, bottom=0.2) +canvas.draw() + +# for profiling +tstart = time.time() + +ul = UpdateLine(canvas, ax) +gobject.idle_add(ul.update_line) + +canvas.mpl_connect('draw_event', ul.on_draw) + +plt.show() Modified: trunk/matplotlib/lib/matplotlib/backends/backend_agg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2009-05-14 04:00:38 UTC (rev 7101) +++ trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2009-05-14 06:27:58 UTC (rev 7102) @@ -33,7 +33,7 @@ from matplotlib.ft2font import FT2Font, LOAD_FORCE_AUTOHINT from matplotlib.mathtext import MathTextParser from matplotlib.path import Path -from matplotlib.transforms import Bbox +from matplotlib.transforms import Bbox, BboxBase from _backend_agg import RendererAgg as _RendererAgg from matplotlib import _png @@ -65,7 +65,6 @@ self.draw_quad_mesh = self._renderer.draw_quad_mesh self.draw_image = self._renderer.draw_image self.copy_from_bbox = self._renderer.copy_from_bbox - self.restore_region = self._renderer.restore_region self.tostring_rgba_minimized = self._renderer.tostring_rgba_minimized self.mathtext_parser = MathTextParser('Agg') @@ -239,7 +238,39 @@ # with the Agg backend return True + def restore_region(self, region, bbox=None, xy=None): + """ + restore the saved region. if bbox (instance of BboxBase, or + its extents) is given, only the region specified by the bbox + will be restored. *xy* (a tuple of two floasts) optionally + specify the new position (of the LLC of the originally region, + not the LLC of the bbox) that the region will be restored. + >>> region = renderer.copy_from_bbox() + >>> x1, y1, x2, y2 = region.get_extents() + >>> renderer.restore_region(region, bbox=(x1+dx, y1, x2, y2), + xy=(x1-dx, y1)) + + """ + if bbox is not None or xy is not None: + if bbox is None: + x1, y1, x2, y2 = region.get_extents() + elif isinstance(bbox, BboxBase): + x1, y1, x2, y2 = bbox.extents + else: + x1, y1, x2, y2 = bbox + + if xy is None: + ox, oy = x1, y1 + else: + ox, oy = xy + + self._renderer.restore_region2(region, x1, y1, x2, y2, ox, oy) + + else: + self._renderer.restore_region(region) + + def new_figure_manager(num, *args, **kwargs): """ Create a new figure manager instance @@ -269,9 +300,9 @@ renderer = self.get_renderer() return renderer.copy_from_bbox(bbox) - def restore_region(self, region): + def restore_region(self, region, bbox=None, xy=None): renderer = self.get_renderer() - return renderer.restore_region(region) + return renderer.restore_region(region, bbox, xy) def draw(self): """ @@ -334,3 +365,4 @@ renderer.width, renderer.height, filename_or_obj, self.figure.dpi) renderer.dpi = original_dpi + Modified: trunk/matplotlib/src/_backend_agg.cpp =================================================================== --- trunk/matplotlib/src/_backend_agg.cpp 2009-05-14 04:00:38 UTC (rev 7101) +++ trunk/matplotlib/src/_backend_agg.cpp 2009-05-14 06:27:58 UTC (rev 7102) @@ -104,6 +104,18 @@ return Py::Object(); } +Py::Object BufferRegion::get_extents(const Py::Tuple &args) { + args.verify_length(0); + + Py::Tuple extents(4); + extents[0] = Py::Int(rect.x1); + extents[1] = Py::Int(rect.y1); + extents[2] = Py::Int(rect.x2); + extents[3] = Py::Int(rect.y2); + + return extents; +} + Py::Object BufferRegion::to_string_argb(const Py::Tuple &args) { // owned=true to prevent memory leak Py_ssize_t length; @@ -426,6 +438,49 @@ return Py::Object(); } +// Restore the part of the saved region with offsets +Py::Object +RendererAgg::restore_region2(const Py::Tuple& args) { + //copy BufferRegion to buffer + args.verify_length(7); + + + + int x(0),y(0), xx1(0),yy1(0), xx2(0), yy2(0); + try { + xx1 = Py::Int( args[1] ); + yy1 = Py::Int( args[2] ); + xx2 = Py::Int( args[3] ); + yy2 = Py::Int( args[4] ); + x = Py::Int( args[5] ); + y = Py::Int( args[6] ); + } + catch (Py::TypeError) { + throw Py::TypeError("Invalid input arguments to draw_text_image"); + } + + + BufferRegion* region = static_cast<BufferRegion*>(args[0].ptr()); + + if (region->data==NULL) + throw Py::ValueError("Cannot restore_region from NULL data"); + + agg::rect_i rect(xx1-region->rect.x1, (yy1-region->rect.y1), + xx2-region->rect.x1, (yy2-region->rect.y1)); + + + agg::rendering_buffer rbuf; + rbuf.attach(region->data, + region->width, + region->height, + region->stride); + + rendererBase.copy_from(rbuf, &rect, x, y); + + return Py::Object(); +} + + bool RendererAgg::render_clippath(const Py::Object& clippath, const agg::trans_affine& clippath_trans) { typedef agg::conv_transform<PathIterator> transformed_path_t; typedef agg::conv_curve<transformed_path_t> curve_t; @@ -1717,6 +1772,9 @@ add_varargs_method("set_y", &BufferRegion::set_y, "set_y(y)"); + add_varargs_method("get_extents", &BufferRegion::get_extents, + "get_extents()"); + add_varargs_method("to_string", &BufferRegion::to_string, "to_string()"); add_varargs_method("to_string_argb", &BufferRegion::to_string_argb, @@ -1759,6 +1817,8 @@ "copy_from_bbox(bbox)"); add_varargs_method("restore_region", &RendererAgg::restore_region, "restore_region(region)"); + add_varargs_method("restore_region2", &RendererAgg::restore_region2, + "restore_region(region, x1, y1, x2, y2, x3, y3)"); } extern "C" Modified: trunk/matplotlib/src/_backend_agg.h =================================================================== --- trunk/matplotlib/src/_backend_agg.h 2009-05-14 04:00:38 UTC (rev 7101) +++ trunk/matplotlib/src/_backend_agg.h 2009-05-14 06:27:58 UTC (rev 7102) @@ -87,6 +87,8 @@ Py::Object set_x(const Py::Tuple &args); Py::Object set_y(const Py::Tuple &args); + Py::Object get_extents(const Py::Tuple &args); + Py::Object to_string(const Py::Tuple &args); Py::Object to_string_argb(const Py::Tuple &args); static void init_type(void); @@ -174,6 +176,7 @@ Py::Object copy_from_bbox(const Py::Tuple & args); Py::Object restore_region(const Py::Tuple & args); + Py::Object restore_region2(const Py::Tuple & args); virtual ~RendererAgg(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |