From: <jd...@us...> - 2007-12-13 16:20:02
|
Revision: 4720 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4720&view=rev Author: jdh2358 Date: 2007-12-13 08:06:59 -0800 (Thu, 13 Dec 2007) Log Message: ----------- moved optional rec2* packages out of mlab and into toolkits Modified Paths: -------------- trunk/matplotlib/API_CHANGES trunk/matplotlib/CODING_GUIDE trunk/matplotlib/examples/figimage_demo.py trunk/matplotlib/lib/matplotlib/image.py trunk/matplotlib/lib/matplotlib/mlab.py trunk/matplotlib/src/_backend_agg.cpp trunk/matplotlib/src/_image.cpp Modified: trunk/matplotlib/API_CHANGES =================================================================== --- trunk/matplotlib/API_CHANGES 2007-12-13 16:04:14 UTC (rev 4719) +++ trunk/matplotlib/API_CHANGES 2007-12-13 16:06:59 UTC (rev 4720) @@ -1,3 +1,8 @@ + Moved rec2gtk to matplotlib.toolkits.gtktools + + Moved rec2excel to matplotlib.toolkits.exceltools + + Removed, dead/experimental ExampleInfo, Namespace and Importer code from matplotlib/__init__.py 0.91.1 Released Modified: trunk/matplotlib/CODING_GUIDE =================================================================== --- trunk/matplotlib/CODING_GUIDE 2007-12-13 16:04:14 UTC (rev 4719) +++ trunk/matplotlib/CODING_GUIDE 2007-12-13 16:06:59 UTC (rev 4720) @@ -113,6 +113,16 @@ .emacs will cause emacs to strip trailing white space on save for python, C and C++ + +When importing modules from the matplotlib namespace + + import matplotlib.cbook as cbook # DO + from matplotlib import cbook #DONT + +because the latter is ambiguous whether cbook is a module or a +function to the new developer. The former makes it explcit that you +are importing a module or package. + ; and similarly for c++-mode-hook and c-mode-hook (add-hook 'python-mode-hook (lambda () Modified: trunk/matplotlib/examples/figimage_demo.py =================================================================== --- trunk/matplotlib/examples/figimage_demo.py 2007-12-13 16:04:14 UTC (rev 4719) +++ trunk/matplotlib/examples/figimage_demo.py 2007-12-13 16:06:59 UTC (rev 4720) @@ -13,7 +13,7 @@ im1 = figimage(Z, xo=50, yo=0) im2 = figimage(Z, xo=100, yo=100, alpha=.8) #gray() # overrides current and sets default -#savefig('figimage_demo') +savefig('figimage_demo') show() Modified: trunk/matplotlib/lib/matplotlib/image.py =================================================================== --- trunk/matplotlib/lib/matplotlib/image.py 2007-12-13 16:04:14 UTC (rev 4719) +++ trunk/matplotlib/lib/matplotlib/image.py 2007-12-13 16:06:59 UTC (rev 4720) @@ -23,6 +23,7 @@ from matplotlib._image import * class AxesImage(martist.Artist, cm.ScalarMappable): + zorder = 1 def __init__(self, ax, cmap = None, @@ -517,18 +518,21 @@ self.update_dict['array'] = True class FigureImage(martist.Artist, cm.ScalarMappable): + zorder = 1 def __init__(self, fig, cmap = None, norm = None, offsetx = 0, offsety = 0, origin=None, + **kwargs ): """ cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 + kwargs are an optional list of Artist keyword args """ martist.Artist.__init__(self) cm.ScalarMappable.__init__(self, norm, cmap) @@ -537,6 +541,7 @@ self.figure = fig self.ox = offsetx self.oy = offsety + self.update(kwargs) def contains(self, mouseevent): """Test whether the mouse event occured within the image. Modified: trunk/matplotlib/lib/matplotlib/mlab.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mlab.py 2007-12-13 16:04:14 UTC (rev 4719) +++ trunk/matplotlib/lib/matplotlib/mlab.py 2007-12-13 16:06:59 UTC (rev 4720) @@ -48,13 +48,13 @@ * rec2csv : store record array in CSV file * rec2excel : store record array in excel worksheet - required pyExcelerator - * rec2gtk : put record array in GTK treeview - requires gtk + * csv2rec : import record array from CSV file with type inspection * rec_append_field : add a field/array to record array * rec_drop_fields : drop fields from record array * rec_join : join two record arrays on sequence of fields -For the rec viewer clases (rec2csv, rec2excel and rec2gtk), there are +For the rec viewer clases (rec2csv, rec2excel), there are a bunch of Format objects you can pass into the functions that will do things like color negative values red, set percent formatting and scaling, etc. @@ -1978,7 +1978,7 @@ join record arrays r1 and r2 on key; key is a tuple of field names. if r1 and r2 have equal values on all the keys in the key tuple, then their fields will be merged into a new record array - containing the union of the fields of r1 and r2 + containing the intersection of the fields of r1 and r2 """ for name in key: @@ -2343,373 +2343,5 @@ writer.writerow([func(val) for func, val in zip(funcs, row)]) fh.close() -# if pyExcelerator is installed, provide an excel view -try: - import pyExcelerator as excel -except ImportError: - pass -else: - def xlformat_factory(format): - """ - copy the format, perform any overrides, and attach an xlstyle instance - copied format is returned - """ - format = copy.deepcopy(format) - - - xlstyle = excel.XFStyle() - if isinstance(format, FormatFloat): - zeros = ''.join(['0']*format.precision) - xlstyle.num_format_str = '#,##0.%s;[RED]-#,##0.%s'%(zeros, zeros) - elif isinstance(format, FormatInt): - xlstyle.num_format_str = '#,##;[RED]-#,##' - elif isinstance(format, FormatPercent): - zeros = ''.join(['0']*format.precision) - xlstyle.num_format_str = '0.%s%%;[RED]-0.%s%%'%(zeros, zeros) - format.scale = 1. - else: - xlstyle = None - - format.xlstyle = xlstyle - - return format - - def rec2excel(r, ws, formatd=None, rownum=0, colnum=0): - """ - save record array r to excel pyExcelerator worksheet ws - starting at rownum. if ws is string like, assume it is a - filename and save to it - - start writing at rownum, colnum - - formatd is a dictionary mapping dtype name -> FormatXL instances - - The next rownum after writing is returned - """ - - autosave = False - if cbook.is_string_like(ws): - filename = ws - wb = excel.Workbook() - ws = wb.add_sheet('worksheet') - autosave = True - - - if formatd is None: - formatd = dict() - - formats = [] - font = excel.Font() - font.bold = True - - stylehdr = excel.XFStyle() - stylehdr.font = font - - for i, name in enumerate(r.dtype.names): - dt = r.dtype[name] - format = formatd.get(name) - if format is None: - format = defaultformatd.get(dt.type, FormatObj()) - - format = xlformat_factory(format) - ws.write(rownum, colnum+i, name, stylehdr) - formats.append(format) - - rownum+=1 - - - ind = npy.arange(len(r.dtype.names)) - for row in r: - for i in ind: - val = row[i] - format = formats[i] - val = format.toval(val) - if format.xlstyle is None: - ws.write(rownum, colnum+i, val) - else: - if safe_isnan(val): - ws.write(rownum, colnum+i, 'NaN') - else: - ws.write(rownum, colnum+i, val, format.xlstyle) - rownum += 1 - - if autosave: - wb.save(filename) - return rownum - - - - -# if gtk is installed, provide a gtk view -try: - import gtk, gobject -except ImportError: - pass -except RuntimeError: - pass -else: - - - def gtkformat_factory(format, colnum): - """ - copy the format, perform any overrides, and attach an gtk style attrs - - - xalign = 0. - cell = None - - """ - - format = copy.copy(format) - format.xalign = 0. - format.cell = None - - def negative_red_cell(column, cell, model, thisiter): - val = model.get_value(thisiter, colnum) - try: val = float(val) - except: cell.set_property('foreground', 'black') - else: - if val<0: - cell.set_property('foreground', 'red') - else: - cell.set_property('foreground', 'black') - - - if isinstance(format, FormatFloat) or isinstance(format, FormatInt): - format.cell = negative_red_cell - format.xalign = 1. - elif isinstance(format, FormatDate): - format.xalign = 1. - return format - - - - class SortedStringsScrolledWindow(gtk.ScrolledWindow): - """ - A simple treeview/liststore assuming all columns are strings. - Supports ascending/descending sort by clicking on column header - """ - - def __init__(self, colheaders, formatterd=None): - """ - xalignd if not None, is a dict mapping col header to xalignent (default 1) - - formatterd if not None, is a dict mapping col header to a ColumnFormatter - """ - - - gtk.ScrolledWindow.__init__(self) - self.colheaders = colheaders - self.seq = None # not initialized with accts - self.set_shadow_type(gtk.SHADOW_ETCHED_IN) - self.set_policy(gtk.POLICY_AUTOMATIC, - gtk.POLICY_AUTOMATIC) - - types = [gobject.TYPE_STRING] * len(colheaders) - model = self.model = gtk.ListStore(*types) - - - treeview = gtk.TreeView(self.model) - treeview.show() - treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE) - treeview.set_rules_hint(True) - - - class Clicked: - def __init__(self, parent, i): - self.parent = parent - self.i = i - self.num = 0 - - def __call__(self, column): - ind = [] - dsu = [] - for rownum, thisiter in enumerate(self.parent.iters): - val = model.get_value(thisiter, self.i) - try: val = float(val.strip().rstrip('%')) - except ValueError: pass - if npy.isnan(val): val = npy.inf # force nan to sort uniquely - dsu.append((val, rownum)) - dsu.sort() - if not self.num%2: dsu.reverse() - - vals, otherind = zip(*dsu) - ind.extend(otherind) - - self.parent.model.reorder(ind) - newiters = [] - for i in ind: - newiters.append(self.parent.iters[i]) - self.parent.iters = newiters[:] - for i, thisiter in enumerate(self.parent.iters): - key = tuple([self.parent.model.get_value(thisiter, j) for j in range(len(colheaders))]) - self.parent.rownumd[i] = key - - self.num+=1 - - - if formatterd is None: - formatterd = dict() - - formatterd = formatterd.copy() - - for i, header in enumerate(colheaders): - renderer = gtk.CellRendererText() - if header not in formatterd: - formatterd[header] = ColumnFormatter() - formatter = formatterd[header] - - column = gtk.TreeViewColumn(header, renderer, text=i) - renderer.set_property('xalign', formatter.xalign) - column.connect('clicked', Clicked(self, i)) - column.set_property('clickable', True) - - if formatter.cell is not None: - column.set_cell_data_func(renderer, formatter.cell) - - treeview.append_column(column) - - - - self.formatterd = formatterd - self.lastcol = column - self.add(treeview) - self.treeview = treeview - self.clear() - - def clear(self): - self.iterd = dict() - self.iters = [] # an ordered list of iters - self.rownumd = dict() # a map from rownum -> symbol - self.model.clear() - self.datad = dict() - - - def flat(self, row): - seq = [] - for i,val in enumerate(row): - formatter = self.formatterd.get(self.colheaders[i]) - seq.extend([i,formatter.tostr(val)]) - return seq - - def __delete_selected(self, *unused): # untested - - - keyd = dict([(thisiter, key) for key, thisiter in self.iterd.values()]) - for row in self.get_selected(): - key = tuple(row) - thisiter = self.iterd[key] - self.model.remove(thisiter) - del self.datad[key] - del self.iterd[key] - self.iters.remove(thisiter) - - for i, thisiter in enumerate(self.iters): - self.rownumd[i] = keyd[thisiter] - - - - def delete_row(self, row): - key = tuple(row) - thisiter = self.iterd[key] - self.model.remove(thisiter) - - - del self.datad[key] - del self.iterd[key] - self.rownumd[len(self.iters)] = key - self.iters.remove(thisiter) - - for rownum, thiskey in self.rownumd.items(): - if thiskey==key: del self.rownumd[rownum] - - def add_row(self, row): - thisiter = self.model.append() - self.model.set(thisiter, *self.flat(row)) - key = tuple(row) - self.datad[key] = row - self.iterd[key] = thisiter - self.rownumd[len(self.iters)] = key - self.iters.append(thisiter) - - def update_row(self, rownum, newrow): - key = self.rownumd[rownum] - thisiter = self.iterd[key] - newkey = tuple(newrow) - - self.rownumd[rownum] = newkey - del self.datad[key] - del self.iterd[key] - self.datad[newkey] = newrow - self.iterd[newkey] = thisiter - - - self.model.set(thisiter, *self.flat(newrow)) - - def get_row(self, rownum): - key = self.rownumd[rownum] - return self.datad[key] - - def get_selected(self): - selected = [] - def foreach(model, path, iter, selected): - selected.append(model.get_value(iter, 0)) - - self.treeview.get_selection().selected_foreach(foreach, selected) - return selected - - - - def rec2gtk(r, formatd=None, rownum=0, autowin=True): - """ - save record array r to excel pyExcelerator worksheet ws - starting at rownum. if ws is string like, assume it is a - filename and save to it - - formatd is a dictionary mapping dtype name -> FormatXL instances - - This function creates a SortedStringsScrolledWindow (derived - from gtk.ScrolledWindow) and returns it. if autowin is True, - a gtk.Window is created, attached to the - SortedStringsScrolledWindow instance, shown and returned. If - autowin=False, the caller is responsible for adding the - SortedStringsScrolledWindow instance to a gtk widget and - showing it. - """ - - - - if formatd is None: - formatd = dict() - - formats = [] - for i, name in enumerate(r.dtype.names): - dt = r.dtype[name] - format = formatd.get(name) - if format is None: - format = defaultformatd.get(dt.type, FormatObj()) - #print 'gtk fmt factory', i, name, format, type(format) - format = gtkformat_factory(format, i) - formatd[name] = format - - - colheaders = r.dtype.names - scroll = SortedStringsScrolledWindow(colheaders, formatd) - - ind = npy.arange(len(r.dtype.names)) - for row in r: - scroll.add_row(row) - - - if autowin: - win = gtk.Window() - win.set_default_size(800,600) - win.add(scroll) - win.show_all() - scroll.win = win - - return scroll - - Modified: trunk/matplotlib/src/_backend_agg.cpp =================================================================== --- trunk/matplotlib/src/_backend_agg.cpp 2007-12-13 16:04:14 UTC (rev 4719) +++ trunk/matplotlib/src/_backend_agg.cpp 2007-12-13 16:06:59 UTC (rev 4720) @@ -251,7 +251,7 @@ alphaMaskRenderingBuffer = new agg::rendering_buffer; alphaMaskRenderingBuffer->attach(alphaBuffer, width, height, stride); alphaMask = new alpha_mask_type(*alphaMaskRenderingBuffer); - //jdh + pixfmtAlphaMask = new agg::pixfmt_gray8(*alphaMaskRenderingBuffer); rendererBaseAlphaMask = new renderer_base_alpha_mask_type(*pixfmtAlphaMask); rendererAlphaMask = new renderer_alpha_mask_type(*rendererBaseAlphaMask); @@ -441,7 +441,6 @@ GCAgg gc = GCAgg(args[0], dpi); facepair_t face = _get_rgba_face(args[1], gc.alpha); - double l = Py::Float( args[2] ); double b = Py::Float( args[3] ); double w = Py::Float( args[4] ); @@ -2022,7 +2021,6 @@ delete [] fillCache; delete [] strokeCache; - //jdh _VERBOSE("RendererAgg::_draw_markers_cache done"); return Py::Object(); @@ -2200,6 +2198,7 @@ agg::span_allocator<agg::gray8> gray_span_allocator; image_span_gen_type image_span_generator(gray_span_allocator, srcbuf, 0, interpolator, filter); + span_gen_type output_span_generator(&image_span_generator, gc.color); renderer_type ri(*rendererBase, output_span_generator); //agg::rasterizer_scanline_aa<> rasterizer; Modified: trunk/matplotlib/src/_image.cpp =================================================================== --- trunk/matplotlib/src/_image.cpp 2007-12-13 16:04:14 UTC (rev 4719) +++ trunk/matplotlib/src/_image.cpp 2007-12-13 16:06:59 UTC (rev 4720) @@ -297,7 +297,7 @@ Py::Object Image::get_matrix(const Py::Tuple& args) { - _VERBOSE("Image::get_size"); + _VERBOSE("Image::get_matrix"); args.verify_length(0); @@ -565,7 +565,7 @@ Py::Object Image::get_size_out(const Py::Tuple& args) { - _VERBOSE("Image::get_size"); + _VERBOSE("Image::get_size_out"); args.verify_length(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |