From: <jd...@us...> - 2008-07-25 23:45:03
|
Revision: 5879 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5879&view=rev Author: jdh2358 Date: 2008-07-25 23:45:01 +0000 (Fri, 25 Jul 2008) Log Message: ----------- fix for ps renderer dpi/imagedpi confusion Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/image_demo.py trunk/matplotlib/lib/matplotlib/backends/backend_ps.py trunk/matplotlib/lib/matplotlib/collections.py trunk/matplotlib/lib/matplotlib/text.py Modified: trunk/matplotlib/examples/pylab_examples/image_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/image_demo.py 2008-07-25 23:22:26 UTC (rev 5878) +++ trunk/matplotlib/examples/pylab_examples/image_demo.py 2008-07-25 23:45:01 UTC (rev 5879) @@ -14,5 +14,6 @@ im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray, origin='lower', extent=[-3,3,-3,3]) +plt.savefig('test.ps', dpi=300) plt.show() Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2008-07-25 23:22:26 UTC (rev 5878) +++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2008-07-25 23:45:01 UTC (rev 5879) @@ -126,7 +126,12 @@ fontd = maxdict(50) afmfontd = maxdict(50) - def __init__(self, width, height, pswriter, dpi=72): + def __init__(self, width, height, pswriter, imagedpi=72): + """ + Although postscript itself is dpi independent, we need to + imform the image code about a requested dpi to generate high + res images and them scale them before embeddin them + """ RendererBase.__init__(self) self.width = width self.height = height @@ -134,7 +139,7 @@ if rcParams['text.usetex']: self.textcnt = 0 self.psfrag = [] - self.dpi = dpi + self.imagedpi = imagedpi # current renderer state (None=uninitialised) self.color = None @@ -145,7 +150,7 @@ self.fontname = None self.fontsize = None self.hatch = None - self.image_magnification = dpi/72.0 + self.image_magnification = imagedpi/72.0 self._clip_paths = {} self._path_collection_id = 0 @@ -857,15 +862,15 @@ else: raise RuntimeError('Orientation must be "portrait" or "landscape"') self.figure.set_dpi(72) # Override the dpi kwarg - dpi = kwargs.get("dpi", 72) + imagedpi = kwargs.get("dpi", 72) facecolor = kwargs.get("facecolor", "w") edgecolor = kwargs.get("edgecolor", "w") if rcParams['text.usetex']: - self._print_figure_tex(outfile, format, dpi, facecolor, edgecolor, + self._print_figure_tex(outfile, format, imagedpi, facecolor, edgecolor, orientation, isLandscape, papertype) else: - self._print_figure(outfile, format, dpi, facecolor, edgecolor, + self._print_figure(outfile, format, imagedpi, facecolor, edgecolor, orientation, isLandscape, papertype) def _print_figure(self, outfile, format, dpi=72, facecolor='w', edgecolor='w', @@ -939,7 +944,7 @@ self.figure.set_edgecolor(edgecolor) self._pswriter = StringIO() - renderer = RendererPS(width, height, self._pswriter, dpi=dpi) + renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi) self.figure.draw(renderer) self.figure.set_facecolor(origfacecolor) @@ -1050,7 +1055,7 @@ self.figure.set_edgecolor(edgecolor) self._pswriter = StringIO() - renderer = RendererPS(width, height, self._pswriter, dpi=dpi) + renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi) self.figure.draw(renderer) self.figure.set_facecolor(origfacecolor) Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2008-07-25 23:22:26 UTC (rev 5878) +++ trunk/matplotlib/lib/matplotlib/collections.py 2008-07-25 23:45:01 UTC (rev 5879) @@ -222,7 +222,7 @@ """ Set the offsets for the collection. *offsets* can be a scalar or a sequence. - + ACCEPTS: float or sequence of floats """ offsets = np.asarray(offsets, np.float_) @@ -603,7 +603,7 @@ if self._sizes is not None: self._transforms = [ transforms.Affine2D().scale( - (np.sqrt(x) * renderer.dpi / 72.0)) + (np.sqrt(x) * self.figure.dpi / 72.0)) for x in self._sizes] return Collection.draw(self, renderer) @@ -680,7 +680,7 @@ # in points^2 self._transforms = [ transforms.Affine2D().rotate(-self._rotation).scale( - (np.sqrt(x) * renderer.dpi / 72.0) / np.sqrt(np.pi)) + (np.sqrt(x) * self.figure.dpi / 72.0) / np.sqrt(np.pi)) for x in self._sizes] return Collection.draw(self, renderer) @@ -877,7 +877,7 @@ # in points^2 self._transforms = [ transforms.Affine2D().scale( - (np.sqrt(x) * renderer.dpi / 72.0) / np.sqrt(np.pi)) + (np.sqrt(x) * self.figure.dpi / 72.0) / np.sqrt(np.pi)) for x in self._sizes] return Collection.draw(self, renderer) Modified: trunk/matplotlib/lib/matplotlib/text.py =================================================================== --- trunk/matplotlib/lib/matplotlib/text.py 2008-07-25 23:22:26 UTC (rev 5878) +++ trunk/matplotlib/lib/matplotlib/text.py 2008-07-25 23:45:01 UTC (rev 5879) @@ -400,7 +400,7 @@ return (x, y, self._text, self._color, self._verticalalignment, self._horizontalalignment, hash(self._fontproperties), self._rotation, - self._renderer.dpi, id(self._renderer) + self.figure.dpi, id(self._renderer) ) def get_text(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2008-07-26 00:29:27
|
Revision: 5883 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5883&view=rev Author: jdh2358 Date: 2008-07-26 00:29:25 +0000 (Sat, 26 Jul 2008) Log Message: ----------- removed debug savefig from image demo Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/image_demo.py trunk/matplotlib/lib/matplotlib/image.py Modified: trunk/matplotlib/examples/pylab_examples/image_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/image_demo.py 2008-07-26 00:01:18 UTC (rev 5882) +++ trunk/matplotlib/examples/pylab_examples/image_demo.py 2008-07-26 00:29:25 UTC (rev 5883) @@ -14,6 +14,5 @@ im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray, origin='lower', extent=[-3,3,-3,3]) -plt.savefig('test.ps', dpi=300) plt.show() Modified: trunk/matplotlib/lib/matplotlib/image.py =================================================================== --- trunk/matplotlib/lib/matplotlib/image.py 2008-07-26 00:01:18 UTC (rev 5882) +++ trunk/matplotlib/lib/matplotlib/image.py 2008-07-26 00:29:25 UTC (rev 5883) @@ -638,7 +638,7 @@ def make_image(self, magnification=1.0): # had to introduce argument magnification to satisfy the unit test # figimage_demo.py. I have no idea, how magnification should be used - # within the function. It should be !=1.0 only for non-default DPI + # within the function. It should be !=1.0 only for non-default DPI< # settings in the PS backend, as introduced by patch #1562394 # Probably Nicholas Young should look over this code and see, how # magnification should be handled correctly. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2008-07-26 23:11:56
|
Revision: 5894 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5894&view=rev Author: jdh2358 Date: 2008-07-26 23:11:54 +0000 (Sat, 26 Jul 2008) Log Message: ----------- fixed a couple of examples Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/barcode_demo.py trunk/matplotlib/examples/tests/backend_driver.py trunk/matplotlib/lib/matplotlib/backends/backend_wxagg.py Modified: trunk/matplotlib/examples/pylab_examples/barcode_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/barcode_demo.py 2008-07-26 22:23:06 UTC (rev 5893) +++ trunk/matplotlib/examples/pylab_examples/barcode_demo.py 2008-07-26 23:11:54 UTC (rev 5894) @@ -15,6 +15,7 @@ ax = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops) ax.imshow(x, **barprops) +x = x.copy() # a horizontal barcode x.shape = 1, len(x) ax = fig.add_axes([0.3, 0.1, 0.6, 0.1], **axprops) Modified: trunk/matplotlib/examples/tests/backend_driver.py =================================================================== --- trunk/matplotlib/examples/tests/backend_driver.py 2008-07-26 22:23:06 UTC (rev 5893) +++ trunk/matplotlib/examples/tests/backend_driver.py 2008-07-26 23:11:54 UTC (rev 5894) @@ -34,6 +34,7 @@ 'bar_stacked.py', 'barchart_demo.py', 'barb_demo.py', + 'barcode_demo.py ', 'boxplot_demo.py', 'broken_barh.py', 'barh_demo.py', Modified: trunk/matplotlib/lib/matplotlib/backends/backend_wxagg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_wxagg.py 2008-07-26 22:23:06 UTC (rev 5893) +++ trunk/matplotlib/lib/matplotlib/backends/backend_wxagg.py 2008-07-26 23:11:54 UTC (rev 5894) @@ -41,7 +41,7 @@ toolbar = None return toolbar -class FigureCanvasWxAgg(FigureCanvasWx, FigureCanvasAgg): +class FigureCanvasWxAgg(FigureCanvasAgg, FigureCanvasWx): """ The FigureCanvas contains the figure and does event handling. @@ -95,11 +95,11 @@ self.gui_repaint() filetypes = FigureCanvasAgg.filetypes - + def print_figure(self, filename, *args, **kwargs): FigureCanvasAgg.print_figure(self, filename, *args, **kwargs) self.draw() - + class NavigationToolbar2WxAgg(NavigationToolbar2Wx): def get_canvas(self, frame, fig): return FigureCanvasWxAgg(frame, -1, fig) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <as...@us...> - 2008-07-27 00:07:35
|
Revision: 5896 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5896&view=rev Author: astraw Date: 2008-07-27 00:07:33 +0000 (Sun, 27 Jul 2008) Log Message: ----------- Added optional C and reduce_C_function arguments to axes.hexbin(). Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py Added Paths: ----------- trunk/matplotlib/examples/pylab_examples/hexbin_demo2.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-07-26 23:26:02 UTC (rev 5895) +++ trunk/matplotlib/CHANGELOG 2008-07-27 00:07:33 UTC (rev 5896) @@ -1,3 +1,8 @@ +2008-07-26 Added optional C and reduce_C_function arguments to + axes.hexbin(). This allows hexbin to accumulate the values + of C based on the x,y coordinates and display in hexagonal + bins. - ADS + 2008-07-24 Deprecated (raise NotImplementedError) all the mlab2 functions from matplotlib.mlab out of concern that some of them were not clean room implementations. JDH Added: trunk/matplotlib/examples/pylab_examples/hexbin_demo2.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/hexbin_demo2.py (rev 0) +++ trunk/matplotlib/examples/pylab_examples/hexbin_demo2.py 2008-07-27 00:07:33 UTC (rev 5896) @@ -0,0 +1,54 @@ +""" +hexbin is an axes method or pyplot function that is essentially a +pcolor of a 2-D histogram with hexagonal cells. +""" + +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.mlab as mlab + +delta = 0.025 +x = y = np.arange(-3.0, 3.0, delta) +X, Y = np.meshgrid(x, y) +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 = Z2-Z1 # difference of Gaussians + +x = X.ravel() +y = Y.ravel() +z = Z.ravel() + +if 1: + # make some points 20 times more common than others, but same mean + xcond = (-1 < x) & (x < 1) + ycond = (-2 < y) & (y < 0) + cond = xcond & ycond + xnew = x[cond] + ynew = y[cond] + znew = z[cond] + for i in range(20): + x = np.hstack((x,xnew)) + y = np.hstack((y,ynew)) + z = np.hstack((z,znew)) + +xmin = x.min() +xmax = x.max() +ymin = y.min() +ymax = y.max() + +gridsize=30 + +plt.subplot(211) +plt.hexbin(x,y, C=z, gridsize=gridsize ) +plt.axis([xmin, xmax, ymin, ymax]) +cb = plt.colorbar() +cb.set_label('mean value') + +plt.subplot(212) +plt.hexbin(x,y, gridsize=gridsize ) +plt.axis([xmin, xmax, ymin, ymax]) +cb = plt.colorbar() +cb.set_label('N observations') + +plt.show() + Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-07-26 23:26:02 UTC (rev 5895) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-07-27 00:07:33 UTC (rev 5896) @@ -4941,24 +4941,35 @@ scatter.__doc__ = cbook.dedent(scatter.__doc__) % martist.kwdocd - def hexbin(self, x, y, gridsize = 100, bins = None, + def hexbin(self, x, y, C = None, gridsize = 100, bins = None, xscale = 'linear', yscale = 'linear', cmap=None, norm=None, vmin=None, vmax=None, alpha=1.0, linewidths=None, edgecolors='none', + reduce_C_function = np.mean, **kwargs): """ call signature:: - hexbin(x, y, gridsize = 100, bins = None, + hexbin(x, y, C = None, gridsize = 100, bins = None, xscale = 'linear', yscale = 'linear', cmap=None, norm=None, vmin=None, vmax=None, alpha=1.0, linewidths=None, edgecolors='none' + reduce_C_function = np.mean, **kwargs) Make a hexagonal binning plot of *x* versus *y*, where *x*, - *y* are 1-D sequences of the same length, *N*. + *y* are 1-D sequences of the same length, *N*. If *C* is None + (the default), this is a histogram of the number of occurences + of the observations at (x[i],y[i]). - *x* and/or *y* may be masked arrays, in which case only + If *C* is specified, it specifies values at the coordinate + (x[i],y[i]). These values are accumulated for each hexagonal + bin and then reduced according to *reduce_C_function*, which + defaults to numpy's mean function (np.mean). (If *C* is + specified, it must also be a 1-D sequence of the same length + as *x* and *y*.) + + *x*, *y* and/or *C* may be masked arrays, in which case only unmasked points will be plotted. Optional keyword arguments: @@ -5049,7 +5060,7 @@ self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs) - x, y = cbook.delete_masked_points(x, y) + x, y, C = cbook.delete_masked_points(x, y, C) # Set the size of the hexagon grid if iterable(gridsize): @@ -5087,22 +5098,59 @@ nx2 = nx ny2 = ny n = nx1*ny1+nx2*ny2 - counts = np.zeros(n) - lattice1 = counts[:nx1*ny1] - lattice2 = counts[nx1*ny1:] - lattice1.shape = (nx1,ny1) - lattice2.shape = (nx2,ny2) d1 = (x-ix1)**2 + 3.0 * (y-iy1)**2 d2 = (x-ix2-0.5)**2 + 3.0 * (y-iy2-0.5)**2 bdist = (d1<d2) - for i in range(len(x)): - if bdist[i]: - lattice1[ix1[i], iy1[i]]+=1 - else: - lattice2[ix2[i], iy2[i]]+=1 + if C is None: + accum = np.zeros(n) + # Create appropriate views into "accum" array. + lattice1 = accum[:nx1*ny1] + lattice2 = accum[nx1*ny1:] + lattice1.shape = (nx1,ny1) + lattice2.shape = (nx2,ny2) + for i in range(len(x)): + if bdist[i]: + lattice1[ix1[i], iy1[i]]+=1 + else: + lattice2[ix2[i], iy2[i]]+=1 + else: + # create accumulation arrays + lattice1 = np.empty((nx1,ny1),dtype=object) + for i in range(nx1): + for j in range(ny1): + lattice1[i,j] = [] + lattice2 = np.empty((nx2,ny2),dtype=object) + for i in range(nx2): + for j in range(ny2): + lattice2[i,j] = [] + + for i in range(len(x)): + if bdist[i]: + lattice1[ix1[i], iy1[i]].append( C[i] ) + else: + lattice2[ix2[i], iy2[i]].append( C[i] ) + + for i in range(nx1): + for j in range(ny1): + vals = lattice1[i,j] + if len(vals): + lattice1[i,j] = reduce( reduce_C_function, vals ) + else: + lattice1[i,j] = np.nan + for i in range(nx2): + for j in range(ny2): + vals = lattice2[i,j] + if len(vals): + lattice2[i,j] = reduce( reduce_C_function, vals ) + else: + lattice2[i,j] = np.nan + + accum = np.hstack(( lattice1.astype(float).ravel(), lattice2.astype(float).ravel() )) + good_idxs = ~np.isnan(accum) + px = xmin + sx * np.array([ 0.5, 0.5, 0.0, -0.5, -0.5, 0.0]) py = ymin + sy * np.array([-0.5, 0.5, 1.0, 0.5, -0.5, -1.0]) / 3.0 @@ -5112,6 +5160,11 @@ polygons[:,nx1*ny1:,0] = np.repeat(np.arange(nx2) + 0.5, ny2) polygons[:,nx1*ny1:,1] = np.tile(np.arange(ny2), nx2) + 0.5 + if C is not None: + # remove accumulation bins with no data + polygons = polygons[:,good_idxs,:] + accum = accum[good_idxs] + polygons = np.transpose(polygons, axes=[1,0,2]) polygons[:,:,0] *= sx polygons[:,:,1] *= sy @@ -5150,20 +5203,20 @@ transOffset = self.transData, ) - # Transform the counts if needed + # Transform accum if needed if bins=='log': - counts = np.log10(counts+1) + accum = np.log10(accum+1) elif bins!=None: if not iterable(bins): - minimum, maximum = min(counts), max(counts) + minimum, maximum = min(accum), max(accum) bins-=1 # one less edge than bins bins = minimum + (maximum-minimum)*np.arange(bins)/bins bins = np.sort(bins) - counts = bins.searchsorted(counts) + accum = bins.searchsorted(accum) if norm is not None: assert(isinstance(norm, mcolors.Normalize)) if cmap is not None: assert(isinstance(cmap, mcolors.Colormap)) - collection.set_array(counts) + collection.set_array(accum) collection.set_cmap(cmap) collection.set_norm(norm) collection.set_alpha(alpha) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2008-07-28 15:40:26
|
Revision: 5909 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5909&view=rev Author: jdh2358 Date: 2008-07-28 15:40:22 +0000 (Mon, 28 Jul 2008) Log Message: ----------- restored axes frame, made patch edge invisible Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/axes.py Added Paths: ----------- trunk/matplotlib/examples/user_interfaces/embedding_in_wx5.py Added: trunk/matplotlib/examples/user_interfaces/embedding_in_wx5.py =================================================================== --- trunk/matplotlib/examples/user_interfaces/embedding_in_wx5.py (rev 0) +++ trunk/matplotlib/examples/user_interfaces/embedding_in_wx5.py 2008-07-28 15:40:22 UTC (rev 5909) @@ -0,0 +1,48 @@ +import wx +import wx.aui +import matplotlib as mpl +from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas +from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as Toolbar + +class Plot(wx.Panel): + def __init__(self, parent, id = -1, dpi = None, **kwargs): + wx.Panel.__init__(self, parent, id=id, **kwargs) + self.figure = mpl.figure.Figure(dpi=dpi, figsize=(2,2)) + self.canvas = Canvas(self, -1, self.figure) + self.toolbar = Toolbar(self.canvas) + self.toolbar.Realize() + + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(self.canvas,1,wx.EXPAND) + sizer.Add(self.toolbar, 0 , wx.LEFT | wx.EXPAND) + self.SetSizer(sizer) + +class PlotNotebook(wx.Panel): + def __init__(self, parent, id = -1): + wx.Panel.__init__(self, parent, id=id) + self.nb = wx.aui.AuiNotebook(self) + sizer = wx.BoxSizer() + sizer.Add(self.nb, 1, wx.EXPAND) + self.SetSizer(sizer) + + def add(self,name="plot"): + page = Plot(self.nb) + self.nb.AddPage(page,name) + return page.figure + + +def demo(): + app = wx.PySimpleApp() + frame = wx.Frame(None,-1,'Plotter') + plotter = PlotNotebook(frame) + axes1 = plotter.add('figure 1').gca() + axes1.plot([1,2,3],[2,1,4]) + axes2 = plotter.add('figure 2').gca() + axes2.plot([1,2,3,4,5],[2,1,4,2,3]) + #axes1.figure.canvas.draw() + #axes2.figure.canvas.draw() + frame.Show() + app.MainLoop() + +if __name__ == "__main__": demo() + Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-07-28 14:12:09 UTC (rev 5908) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-07-28 15:40:22 UTC (rev 5909) @@ -845,12 +845,14 @@ self._set_artist_props(self.title) # the patch draws the background of the axes. we want this to - # be below the other artists; the axesPatch name is deprecated + # be below the other artists; the axesPatch name is + # deprecated. We use the frame to draw the edges so we are + # setting the edgecolor to None self.patch = self.axesPatch = self._gen_axes_patch() self.patch.set_figure(self.figure) self.patch.set_facecolor(self._axisbg) - self.patch.set_edgecolor(rcParams['axes.edgecolor']) - self.patch.set_linewidth(rcParams['axes.linewidth']) + self.patch.set_edgecolor('None') + self.patch.set_linewidth(0) self.patch.set_transform(self.transAxes) # the frame draws the border around the axes and we want this @@ -1504,6 +1506,10 @@ if self.legend_ is not None: artists.append(self.legend_) + 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() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2008-07-28 19:59:21
|
Revision: 5915 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5915&view=rev Author: jdh2358 Date: 2008-07-28 19:59:19 +0000 (Mon, 28 Jul 2008) Log Message: ----------- commented out seterr in npy -- ma looks broken here Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/geo_demo.py trunk/matplotlib/unit/memleak_hawaii3.py Modified: trunk/matplotlib/examples/pylab_examples/geo_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/geo_demo.py 2008-07-28 17:29:57 UTC (rev 5914) +++ trunk/matplotlib/examples/pylab_examples/geo_demo.py 2008-07-28 19:59:19 UTC (rev 5915) @@ -1,5 +1,5 @@ import numpy as np -np.seterr("raise") +#np.seterr("raise") from pylab import * Modified: trunk/matplotlib/unit/memleak_hawaii3.py =================================================================== --- trunk/matplotlib/unit/memleak_hawaii3.py 2008-07-28 17:29:57 UTC (rev 5914) +++ trunk/matplotlib/unit/memleak_hawaii3.py 2008-07-28 19:59:19 UTC (rev 5915) @@ -2,7 +2,7 @@ import os, sys, time, gc import matplotlib -matplotlib.use('Agg') +matplotlib.use('PDF') from matplotlib.cbook import report_memory import numpy as np This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <js...@us...> - 2008-07-31 11:52:13
|
Revision: 5933 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5933&view=rev Author: jswhit Date: 2008-07-31 11:52:10 +0000 (Thu, 31 Jul 2008) Log Message: ----------- added masked array support to griddata Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/mlab.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-07-30 17:30:19 UTC (rev 5932) +++ trunk/matplotlib/CHANGELOG 2008-07-31 11:52:10 UTC (rev 5933) @@ -1,3 +1,5 @@ +2008-07-31 Added masked array support to griddata. - JSW + 2008-07-26 Added optional C and reduce_C_function arguments to axes.hexbin(). This allows hexbin to accumulate the values of C based on the x,y coordinates and display in hexagonal Modified: trunk/matplotlib/lib/matplotlib/mlab.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mlab.py 2008-07-30 17:30:19 UTC (rev 5932) +++ trunk/matplotlib/lib/matplotlib/mlab.py 2008-07-31 11:52:10 UTC (rev 5933) @@ -2611,6 +2611,13 @@ raise TypeError("inputs xi and yi must have same number of dimensions (1 or 2)") if xi.ndim != 1 and xi.ndim != 2: raise TypeError("inputs xi and yi must be 1D or 2D.") + if not len(x)==len(y)==len(z): + raise TypeError("inputs x,y,z must all be 1D arrays of the same length") + # remove masked points. + if hasattr(z,'mask'): + x = x.compress(z.mask == False) + y = y.compress(z.mask == False) + z = z.compressed() if _use_natgrid: # use natgrid toolkit if available. if xi.ndim == 2: xi = xi[0,:] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-07-31 13:51:05
|
Revision: 5934 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5934&view=rev Author: mdboom Date: 2008-07-31 13:50:58 +0000 (Thu, 31 Jul 2008) Log Message: ----------- Deal with markers correctly for interpolating transformations. (Thanks Jae-Joon Lee for finding this.) Modified Paths: -------------- trunk/matplotlib/examples/api/custom_projection_example.py trunk/matplotlib/lib/matplotlib/lines.py trunk/matplotlib/lib/matplotlib/transforms.py Modified: trunk/matplotlib/examples/api/custom_projection_example.py =================================================================== --- trunk/matplotlib/examples/api/custom_projection_example.py 2008-07-31 11:52:10 UTC (rev 5933) +++ trunk/matplotlib/examples/api/custom_projection_example.py 2008-07-31 13:50:58 UTC (rev 5934) @@ -451,6 +451,7 @@ from pylab import * subplot(111, projection="hammer") +p = plot([-1, 1, 1], [-1, -1, 1], "o-") grid(True) show() Modified: trunk/matplotlib/lib/matplotlib/lines.py =================================================================== --- trunk/matplotlib/lib/matplotlib/lines.py 2008-07-31 11:52:10 UTC (rev 5933) +++ trunk/matplotlib/lib/matplotlib/lines.py 2008-07-31 13:50:58 UTC (rev 5934) @@ -432,7 +432,7 @@ gc.set_alpha(self._alpha) funcname = self._markers.get(self._marker, '_draw_nothing') if funcname != '_draw_nothing': - tpath, affine = self._transformed_path.get_transformed_path_and_affine() + tpath, affine = self._transformed_path.get_transformed_points_and_affine() markerFunc = getattr(self, funcname) markerFunc(renderer, gc, tpath, affine.frozen()) Modified: trunk/matplotlib/lib/matplotlib/transforms.py =================================================================== --- trunk/matplotlib/lib/matplotlib/transforms.py 2008-07-31 11:52:10 UTC (rev 5933) +++ trunk/matplotlib/lib/matplotlib/transforms.py 2008-07-31 13:50:58 UTC (rev 5934) @@ -2076,18 +2076,35 @@ self._transform = transform self.set_children(transform) self._transformed_path = None + self._transformed_points = None + def _revalidate(self): + if ((self._invalid & self.INVALID_NON_AFFINE == self.INVALID_NON_AFFINE) + or self._transformed_path is None): + self._transformed_path = \ + self._transform.transform_path_non_affine(self._path) + self._transformed_points = \ + Path(self._transform.transform_non_affine(self._path.vertices)) + self._invalid = 0 + + def get_transformed_points_and_affine(self): + """ + Return a copy of the child path, with the non-affine part of + the transform already applied, along with the affine part of + the path necessary to complete the transformation. Unlike + get_transformed_path_and_affine, no interpolation will be + performed. + """ + self._revalidate() + return self._transformed_points, self.get_affine() + def get_transformed_path_and_affine(self): """ Return a copy of the child path, with the non-affine part of the transform already applied, along with the affine part of the path necessary to complete the transformation. """ - if ((self._invalid & self.INVALID_NON_AFFINE == self.INVALID_NON_AFFINE) - or self._transformed_path is None): - self._transformed_path = \ - self._transform.transform_path_non_affine(self._path) - self._invalid = 0 + self._revalidate() return self._transformed_path, self.get_affine() def get_fully_transformed_path(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2008-07-31 19:08:14
|
Revision: 5941 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5941&view=rev Author: jdh2358 Date: 2008-07-31 19:08:08 +0000 (Thu, 31 Jul 2008) Log Message: ----------- bumbed release number Modified Paths: -------------- trunk/matplotlib/doc/pyplots/tex_demo.pdf trunk/matplotlib/lib/matplotlib/__init__.py Modified: trunk/matplotlib/doc/pyplots/tex_demo.pdf =================================================================== --- trunk/matplotlib/doc/pyplots/tex_demo.pdf 2008-07-31 19:05:30 UTC (rev 5940) +++ trunk/matplotlib/doc/pyplots/tex_demo.pdf 2008-07-31 19:08:08 UTC (rev 5941) @@ -4,9 +4,9 @@ << /Type /Catalog /Pages 3 0 R >> endobj 2 0 obj -<< /CreationDate (D:20080613153922-04'00') +<< /CreationDate (D:20080731010125-07'00') /Producer (matplotlib pdf backend) -/Creator (matplotlib 0.98.0, http://matplotlib.sf.net) >> +/Creator (matplotlib 0.98.3rc2, http://matplotlib.sf.net) >> endobj 3 0 obj << /Count 1 /Kids [ 4 0 R ] /Type /Pages >> @@ -22,28 +22,26 @@ 5 0 obj << /Filter /FlateDecode /Length 11 0 R >> stream -x\x9C\xCDYM\x8F]5\x9D\xB5\xFF\xC1\xEC\xCC.Yĩ\xBB\Fb\x83"Eb$\xA0H\xC0\x82\x8F2J\x830\xFC\xFD9\xF6}/\xFD\x9E}\xE9<u\xA4\xCE,\x92n\xFB\x96\xCB\xF6\xA9\xE3Se\xB7ħ\x91\xE3s\xFC{(R\xBC\x8EY?_\x8E\x9F\xE2\x8E\xDF\xE8\xF5O\xF4\x87a\xF7$dM\xFDsr\x8CP\xEF?G\xE3屡\x94\xF2p\xD2\xCD\xCE\xC3^~;ik.ɢ\xE3\xFFW\xCF\xE2\x97\xF1\x971\xC7ώ3 -X\x9C%+\xB0\x94\x96\x8C -{\x93ׅ3̤&Qe\xCB\xDCWS4\xF3 \xA2I\x85\xB3\xB5Z밯\x89$Gᚚre\xD5\xEC}\x89\x86i\xB0z\xE6\xC4\xD9+\xA9\xF6^\x85\x95!M\xE4DZ-g\xEE\xFD5i\x93\xC8M\x93\xCC\xEBlV\xD1_)9ܰk2f\xCD\xD4T[\xEF\xCFI)\xAE\x92 -{)R\xBC\xF5U֚\xAAE\xC6\xE4\xF5dV\xE7$\x8C\xEE\xECX\x93\x93Za\x92ޟ\x93U \xAC%5i\xE2Yͭ\xF7{b\xC1\xACثT\xAA\L\xB9\xEF\xA9q*\xD83\xDC37\xC3VǬ\xAD$,\xA6\xC1;\xBB\xB5\xB1\xF4\xDEl8;\xE7\\xF36'#4\xADH\xAC\xBE\xDCJ#3\xFD%e\xF2`%i\xAE\xE8sk\x87\xC3\xE4\x96c1ĥ5-\xA5#\x80 ![\xA2\x93I\x99K\xAA\xD5BƎ\xCD\xC5 -[\xB5\xD1\xDFN\x89ةW/J"#\xDA,\x82\xE5\x816X\x94a\x9DU\x8B\x8FU -\xA6\xCB9\x80\xA5eG<\xA8n\xF6\xAD\xD3k#(b\x8D\xC9ќ\x8D\xD49wzC\x87\xAF\x8B |
From: <md...@us...> - 2008-08-01 15:04:48
|
Revision: 5946 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5946&view=rev Author: mdboom Date: 2008-08-01 15:04:46 +0000 (Fri, 01 Aug 2008) Log Message: ----------- Merged revisions 5846-5945 via svnmerge from https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v0_91_maint ........ r5852 | sameerd | 2008-07-24 17:56:57 -0400 (Thu, 24 Jul 2008) | 3 lines Fixing edge cases in rec_join in branch ........ r5945 | mdboom | 2008-08-01 11:00:35 -0400 (Fri, 01 Aug 2008) | 2 lines Backport memory leak fixes in _ttconv.cpp ........ Modified Paths: -------------- trunk/matplotlib/CHANGELOG Property Changed: ---------------- trunk/matplotlib/ Property changes on: trunk/matplotlib ___________________________________________________________________ Modified: svnmerge-integrated - /branches/v0_91_maint:1-5845 + /branches/v0_91_maint:1-5945 Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-08-01 15:00:35 UTC (rev 5945) +++ trunk/matplotlib/CHANGELOG 2008-08-01 15:04:46 UTC (rev 5946) @@ -1,3 +1,5 @@ +2008-08-01 Backported memory leak fixes in _ttconv.cpp - MGD + 2008-07-31 Added masked array support to griddata. - JSW 2008-07-26 Added optional C and reduce_C_function arguments to @@ -48,6 +50,9 @@ 2008-07-17 Fix bug with NaNs at end of path (thanks, Andrew Straw for the report) - MGD +2008-07-16 Improve error handling in texmanager, thanks to Ian Henry + for reporting - DSD + 2008-07-12 Added support for external backends with the "module://my_backend" syntax - JDH This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-08-06 18:06:24
|
Revision: 5981 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5981&view=rev Author: efiring Date: 2008-08-06 18:06:21 +0000 (Wed, 06 Aug 2008) Log Message: ----------- Check for isfinite in get_path_extents. This is part of an experiment to make nan and inf be ignored equally throughout plotting; it may turn out to be unnecessary, in which case it should be reverted for the sake of efficiency. Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/nan_test.py trunk/matplotlib/src/_path.cpp Modified: trunk/matplotlib/examples/pylab_examples/nan_test.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/nan_test.py 2008-08-06 17:42:59 UTC (rev 5980) +++ trunk/matplotlib/examples/pylab_examples/nan_test.py 2008-08-06 18:06:21 UTC (rev 5981) @@ -3,10 +3,12 @@ Example: simple line plots with NaNs inserted. """ from pylab import * +import numpy as np t = arange(0.0, 1.0+0.01, 0.01) s = cos(2*2*pi*t) t[41:60] = NaN +#t[50:60] = np.inf subplot(2,1,1) plot(t, s, '-', lw=2) @@ -20,6 +22,7 @@ t[0] = NaN t[-1] = NaN plot(t, s, '-', lw=2) +title('Also with NaN in first and last point') xlabel('time (s)') ylabel('more nans') Modified: trunk/matplotlib/src/_path.cpp =================================================================== --- trunk/matplotlib/src/_path.cpp 2008-08-06 17:42:59 UTC (rev 5980) +++ trunk/matplotlib/src/_path.cpp 2008-08-06 18:06:21 UTC (rev 5981) @@ -280,6 +280,8 @@ { if ((code & agg::path_cmd_end_poly) == agg::path_cmd_end_poly) continue; + if (MPL_notisfinite64(x) || MPL_notisfinite64(y)) + continue; if (x < *x0) *x0 = x; if (y < *y0) *y0 = y; if (x > *x1) *x1 = x; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-08-11 12:48:59
|
Revision: 6018 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6018&view=rev Author: mdboom Date: 2008-08-11 12:48:50 +0000 (Mon, 11 Aug 2008) Log Message: ----------- Does simplify paths when NaN/inf is present. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/path.py trunk/matplotlib/src/_backend_agg.cpp trunk/matplotlib/src/_path.cpp trunk/matplotlib/src/agg_py_path_iterator.h Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-08-11 07:09:16 UTC (rev 6017) +++ trunk/matplotlib/CHANGELOG 2008-08-11 12:48:50 UTC (rev 6018) @@ -1,3 +1,9 @@ +2008-08-11 Fix more bugs in NaN/inf handling. In particular, path simplification + (which does not handle NaNs or infs) will be turned off automatically + when infs or NaNs are present. Also masked arrays are now converted + to arrays with NaNs for consistent handling of masks and NaNs + - MGD and EF + ================================================================= 2008-08-03 Released 0.98.3 at svn r5947 Modified: trunk/matplotlib/lib/matplotlib/path.py =================================================================== --- trunk/matplotlib/lib/matplotlib/path.py 2008-08-11 07:09:16 UTC (rev 6017) +++ trunk/matplotlib/lib/matplotlib/path.py 2008-08-11 12:48:50 UTC (rev 6018) @@ -56,6 +56,11 @@ :class:`Path` objects, as an optimization, do not store a *codes* at all, but have a default one provided for them by :meth:`iter_segments`. + + Note also that the vertices and codes arrays should be treated as + immutable -- there are a number of optimizations and assumptions + made up front in the constructor that will not change when the + data changes. """ # Path codes @@ -84,46 +89,29 @@ dimension. If *codes* is None, *vertices* will be treated as a series of - line segments. If *vertices* contains masked values, the - resulting path will be compressed, with ``MOVETO`` codes - inserted in the correct places to jump over the masked - regions. + line segments. + + If *vertices* contains masked values, they will be converted + to NaNs which are then handled correctly by the Agg + PathIterator and other consumers of path data, such as + :meth:`iter_segments`. """ if ma.isMaskedArray(vertices): - is_mask = True - mask = ma.getmask(vertices) + vertices = vertices.astype(np.float_).filled(np.nan) else: - is_mask = False vertices = np.asarray(vertices, np.float_) - mask = ma.nomask if codes is not None: codes = np.asarray(codes, self.code_type) assert codes.ndim == 1 assert len(codes) == len(vertices) - # The path being passed in may have masked values. However, - # the backends (and any affine transformations in matplotlib - # itself), are not expected to deal with masked arrays, so we - # must remove them from the array (using compressed), and add - # MOVETO commands to the codes array accordingly. - if is_mask: - if mask is not ma.nomask: - mask1d = np.logical_or.reduce(mask, axis=1) - gmask1d = np.invert(mask1d) - if codes is None: - codes = np.empty((len(vertices)), self.code_type) - codes.fill(self.LINETO) - codes[0] = self.MOVETO - vertices = vertices[gmask1d].filled() # ndarray - codes[np.roll(mask1d, 1)] = self.MOVETO - codes = codes[gmask1d] # np.compress is much slower - else: - vertices = np.asarray(vertices, np.float_) - assert vertices.ndim == 2 assert vertices.shape[1] == 2 + self.should_simplify = (codes is None and + np.all(np.isfinite(vertices)) and + len(vertices) >= 128) self.codes = codes self.vertices = vertices Modified: trunk/matplotlib/src/_backend_agg.cpp =================================================================== --- trunk/matplotlib/src/_backend_agg.cpp 2008-08-11 07:09:16 UTC (rev 6017) +++ trunk/matplotlib/src/_backend_agg.cpp 2008-08-11 12:48:50 UTC (rev 6018) @@ -387,7 +387,7 @@ double x0, y0, x1, y1; unsigned code; - if (path.total_vertices() > 15) + if (!path.should_simplify() || path.total_vertices() > 15) return false; code = path.vertex(&x0, &y0); @@ -420,11 +420,6 @@ return true; } -template<class Path> -bool should_simplify(Path& path) { - return !path.has_curves() && path.total_vertices() >= 128; -} - Py::Object RendererAgg::copy_from_bbox(const Py::Tuple& args) { //copy region in bbox to buffer and return swig/agg buffer object @@ -938,7 +933,7 @@ trans *= agg::trans_affine_scaling(1.0, -1.0); trans *= agg::trans_affine_translation(0.0, (double)height); bool snap = should_snap(path, trans); - bool simplify = should_simplify(path) && !face.first; + bool simplify = path.should_simplify() && !face.first; transformed_path_t tpath(path, trans); simplify_t simplified(tpath, snap, simplify, width, height); @@ -1236,6 +1231,10 @@ inline unsigned total_vertices() { return 5; } + + inline bool should_simplify() { + return false; + } }; public: Modified: trunk/matplotlib/src/_path.cpp =================================================================== --- trunk/matplotlib/src/_path.cpp 2008-08-11 07:09:16 UTC (rev 6017) +++ trunk/matplotlib/src/_path.cpp 2008-08-11 12:48:50 UTC (rev 6018) @@ -1120,7 +1120,7 @@ double width = Py::Float(args[2]); double height = Py::Float(args[3]); - bool simplify = !path.has_curves() && width != 0.0 && height != 0.0; + bool simplify = path.should_simplify() && width != 0.0 && height != 0.0; transformed_path_t tpath(path, trans); simplify_t simplified(tpath, false, simplify, width, height); Modified: trunk/matplotlib/src/agg_py_path_iterator.h =================================================================== --- trunk/matplotlib/src/agg_py_path_iterator.h 2008-08-11 07:09:16 UTC (rev 6017) +++ trunk/matplotlib/src/agg_py_path_iterator.h 2008-08-11 12:48:50 UTC (rev 6018) @@ -15,6 +15,7 @@ PyArrayObject* m_codes; size_t m_iterator; size_t m_total_vertices; + bool m_should_simplify; public: PathIterator(const Py::Object& path_obj) : @@ -22,6 +23,7 @@ { Py::Object vertices_obj = path_obj.getAttr("vertices"); Py::Object codes_obj = path_obj.getAttr("codes"); + Py::Object should_simplify_obj = path_obj.getAttr("should_simplify"); m_vertices = (PyArrayObject*)PyArray_FromObject (vertices_obj.ptr(), PyArray_DOUBLE, 2, 2); @@ -38,6 +40,7 @@ throw Py::ValueError("Invalid codes array."); } + m_should_simplify = bool(Py::Int(should_simplify_obj)); m_total_vertices = m_vertices->dimensions[0]; } @@ -100,9 +103,9 @@ return m_total_vertices; } - inline bool has_curves() + inline bool should_simplify() { - return m_codes; + return m_should_simplify; } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ds...@us...> - 2008-08-18 21:07:04
|
Revision: 6043 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6043&view=rev Author: dsdale Date: 2008-08-18 21:06:56 +0000 (Mon, 18 Aug 2008) Log Message: ----------- improved interactive pan/zoom in qt4agg backend on windows Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/backends/backend_qt4agg.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-08-18 20:18:56 UTC (rev 6042) +++ trunk/matplotlib/CHANGELOG 2008-08-18 21:06:56 UTC (rev 6043) @@ -1,3 +1,5 @@ +2008-08-18 improve interactive pan/zoom in qt4 backend on windows - DSD + 2008-08-11 Fix more bugs in NaN/inf handling. In particular, path simplification (which does not handle NaNs or infs) will be turned off automatically when infs or NaNs are present. Also masked arrays are now converted Modified: trunk/matplotlib/lib/matplotlib/backends/backend_qt4agg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_qt4agg.py 2008-08-18 20:18:56 UTC (rev 6042) +++ trunk/matplotlib/lib/matplotlib/backends/backend_qt4agg.py 2008-08-18 21:06:56 UTC (rev 6043) @@ -132,6 +132,8 @@ self.replot = True FigureCanvasAgg.draw(self) self.update() + # Added following line to improve realtime pan/zoom on windows: + QtGui.qApp.processEvents() def blit(self, bbox=None): """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <js...@us...> - 2008-08-22 19:19:09
|
Revision: 6047 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6047&view=rev Author: jswhit Date: 2008-08-22 19:19:07 +0000 (Fri, 22 Aug 2008) Log Message: ----------- fix quiver so masked values are not plotted. Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/quiver_demo.py trunk/matplotlib/lib/matplotlib/quiver.py Modified: trunk/matplotlib/examples/pylab_examples/quiver_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/quiver_demo.py 2008-08-21 15:29:12 UTC (rev 6046) +++ trunk/matplotlib/examples/pylab_examples/quiver_demo.py 2008-08-22 19:19:07 UTC (rev 6047) @@ -9,6 +9,7 @@ ''' from pylab import * +from numpy import ma X,Y = meshgrid( arange(0,2*pi,.2),arange(0,2*pi,.2) ) U = cos(X) @@ -64,6 +65,20 @@ axis([-1, 7, -1, 7]) title("triangular head; scale with x view; black edges") +#6 +figure() +M = zeros(U.shape, dtype='bool') +M[U.shape[0]/3:2*U.shape[0]/3,U.shape[1]/3:2*U.shape[1]/3] = True +U = ma.masked_array(U, mask=M) +V = ma.masked_array(V, mask=M) +Q = quiver( U, V) +qk = quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W', + fontproperties={'weight': 'bold'}) +l,r,b,t = axis() +dx, dy = r-l, t-b +axis([l-0.05*dx, r+0.05*dx, b-0.05*dy, t+0.05*dy]) +title('Minimal arguments, no kwargs - masked values') + show() Modified: trunk/matplotlib/lib/matplotlib/quiver.py =================================================================== --- trunk/matplotlib/lib/matplotlib/quiver.py 2008-08-21 15:29:12 UTC (rev 6046) +++ trunk/matplotlib/lib/matplotlib/quiver.py 2008-08-22 19:19:07 UTC (rev 6047) @@ -334,6 +334,12 @@ def __init__(self, ax, *args, **kw): self.ax = ax X, Y, U, V, C = self._parse_args(*args) + if C is not None: + X, Y, U, V, C = delete_masked_points(X.ravel(),Y.ravel(),U.ravel(), + V.ravel(),C.ravel()) + else: + X, Y, U, V = delete_masked_points(X.ravel(),Y.ravel(),U.ravel(), + V.ravel()) self.X = X self.Y = Y self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis])) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-08-25 22:14:40
|
Revision: 6049 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6049&view=rev Author: mdboom Date: 2008-08-25 22:14:33 +0000 (Mon, 25 Aug 2008) Log Message: ----------- Fix locale problems in SVG backend (thanks, Mathieu Leplatre for reporting) Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/backends/backend_svg.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-08-22 19:19:29 UTC (rev 6048) +++ trunk/matplotlib/CHANGELOG 2008-08-25 22:14:33 UTC (rev 6049) @@ -1,3 +1,5 @@ +2008-08-25 Fix locale problems in SVG backend - MGD + 2008-08-22 fix quiver so masked values are not plotted - JSW 2008-08-18 improve interactive pan/zoom in qt4 backend on windows - DSD Modified: trunk/matplotlib/lib/matplotlib/backends/backend_svg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2008-08-22 19:19:29 UTC (rev 6048) +++ trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2008-08-25 22:14:33 UTC (rev 6049) @@ -96,13 +96,13 @@ if seq is None: dashes = '' else: - dashes = 'stroke-dasharray: %s; stroke-dashoffset: %s;' % ( - ','.join(['%s'%val for val in seq]), offset) + dashes = 'stroke-dasharray: %s; stroke-dashoffset: %f;' % ( + ','.join(['%f'%val for val in seq]), offset) linewidth = gc.get_linewidth() if linewidth: - return 'fill: %s; stroke: %s; stroke-width: %s; ' \ - 'stroke-linejoin: %s; stroke-linecap: %s; %s opacity: %s' % ( + return 'fill: %s; stroke: %s; stroke-width: %f; ' \ + 'stroke-linejoin: %s; stroke-linecap: %s; %s opacity: %f' % ( fill, rgb2hex(gc.get_rgb()[:3]), linewidth, @@ -112,7 +112,7 @@ gc.get_alpha(), ) else: - return 'fill: %s; opacity: %s' % (\ + return 'fill: %s; opacity: %f' % (\ fill, gc.get_alpha(), ) @@ -126,7 +126,7 @@ elif cliprect is not None: x, y, w, h = cliprect.bounds y = self.height-(y+h) - path = '<rect x="%(x)s" y="%(y)s" width="%(w)s" height="%(h)s"/>' % locals() + path = '<rect x="%(x)f" y="%(y)f" width="%(w)f" height="%(h)f"/>' % locals() else: return None @@ -153,10 +153,10 @@ return rcParams['svg.image_noscale'] _path_commands = { - Path.MOVETO: 'M%s %s', - Path.LINETO: 'L%s %s', - Path.CURVE3: 'Q%s %s %s %s', - Path.CURVE4: 'C%s %s %s %s %s %s' + Path.MOVETO: 'M%f %f', + Path.LINETO: 'L%f %f', + Path.CURVE3: 'Q%f %f %f %f', + Path.CURVE4: 'C%f %f %f %f %f %f' } def _make_flip_transform(self, transform): @@ -258,7 +258,7 @@ trans[4] += trans[0] trans[5] += trans[3] trans[5] = -trans[5] - transstr = 'transform="matrix(%s %s %s %s %s %s)" '%tuple(trans) + transstr = 'transform="matrix(%f %f %f %f %f %f)" '%tuple(trans) assert trans[1] == 0 assert trans[2] == 0 numrows,numcols = im.get_size() @@ -269,7 +269,7 @@ h,w = im.get_size_out() self._svgwriter.write ( - '<image x="%s" y="%s" width="%s" height="%s" ' + '<image x="%f" y="%f" width="%f" height="%f" ' '%s xlink:href="'%(x/trans[0], (self.height-y)/trans[3]-h, w, h, transstr) ) @@ -323,12 +323,12 @@ if clipid is not None: svg.append('<g clip-path="url(#%s)">\n' % clipid) - svg.append('<g style="fill: %s; opacity: %s" transform="' % (color, gc.get_alpha())) + svg.append('<g style="fill: %s; opacity: %f" transform="' % (color, gc.get_alpha())) if angle != 0: - svg.append('translate(%s,%s)rotate(%1.1f)' % (x,y,-angle)) + svg.append('translate(%f,%f)rotate(%1.1f)' % (x,y,-angle)) elif x != 0 or y != 0: - svg.append('translate(%s,%s)' % (x, y)) - svg.append('scale(%s)">\n' % (fontsize / self.FONT_SCALE)) + svg.append('translate(%f,%f)' % (x, y)) + svg.append('scale(%f)">\n' % (fontsize / self.FONT_SCALE)) cmap = font.get_charmap() lastgind = None @@ -350,7 +350,7 @@ svg.append('<use xlink:href="#%s"' % charnum) if currx != 0: - svg.append(' x="%s"' % + svg.append(' x="%f"' % (currx * (self.FONT_SCALE / fontsize))) svg.append('/>\n') @@ -365,16 +365,16 @@ fontfamily = font.family_name fontstyle = prop.get_style() - style = ('font-size: %f; font-family: %s; font-style: %s; fill: %s; opacity: %s' % + style = ('font-size: %f; font-family: %s; font-style: %s; fill: %s; opacity: %f' % (fontsize, fontfamily,fontstyle, color, gc.get_alpha())) if angle!=0: - transform = 'transform="translate(%s,%s) rotate(%1.1f) translate(%s,%s)"' % (x,y,-angle,-x,-y) + transform = 'transform="translate(%f,%f) rotate(%1.1f) translate(%f,%f)"' % (x,y,-angle,-x,-y) # Inkscape doesn't support rotate(angle x y) else: transform = '' svg = """\ -<text style="%(style)s" x="%(x)s" y="%(y)s" %(transform)s>%(thetext)s</text> +<text style="%(style)s" x="%(x)f" y="%(y)f" %(transform)s>%(thetext)s</text> """ % locals() write(svg) @@ -396,17 +396,17 @@ currx, curry = 0.0, 0.0 for step in glyph.path: if step[0] == 0: # MOVE_TO - path_data.append("M%s %s" % + path_data.append("M%f %f" % (step[1], -step[2])) elif step[0] == 1: # LINE_TO - path_data.append("l%s %s" % + path_data.append("l%f %f" % (step[1] - currx, -step[2] - curry)) elif step[0] == 2: # CURVE3 - path_data.append("q%s %s %s %s" % + path_data.append("q%f %f %f %f" % (step[1] - currx, -step[2] - curry, step[3] - currx, -step[4] - curry)) elif step[0] == 3: # CURVE4 - path_data.append("c%s %s %s %s %s %s" % + path_data.append("c%f %f %f %f %f %f" % (step[1] - currx, -step[2] - curry, step[3] - currx, -step[4] - curry, step[5] - currx, -step[6] - curry)) @@ -460,16 +460,16 @@ svg = ['<g style="%s" transform="' % style] if angle != 0: - svg.append('translate(%s,%s)rotate(%1.1f)' + svg.append('translate(%f,%f)rotate(%1.1f)' % (x,y,-angle) ) else: - svg.append('translate(%s,%s)' % (x, y)) + svg.append('translate(%f,%f)' % (x, y)) svg.append('">\n') for font, fontsize, thetext, new_x, new_y_mtc, metrics in svg_glyphs: charid = self._get_char_def_id(font, thetext) - svg.append('<use xlink:href="#%s" transform="translate(%s,%s)scale(%s)"/>\n' % + svg.append('<use xlink:href="#%s" transform="translate(%f,%f)scale(%f)"/>\n' % (charid, new_x, -new_y_mtc, fontsize / self.FONT_SCALE)) svg.append('</g>\n') else: # not rcParams['svg.embed_char_paths'] @@ -488,15 +488,15 @@ svg.append('<tspan style="%s"' % style) xadvance = metrics.advance - svg.append(' textLength="%s"' % xadvance) + svg.append(' textLength="%f"' % xadvance) dx = new_x - curr_x if dx != 0.0: - svg.append(' dx="%s"' % dx) + svg.append(' dx="%f"' % dx) dy = new_y - curr_y if dy != 0.0: - svg.append(' dy="%s"' % dy) + svg.append(' dy="%f"' % dy) thetext = escape_xml_text(thetext) @@ -511,14 +511,14 @@ style = "fill: %s; stroke: none" % color svg.append('<g style="%s" transform="' % style) if angle != 0: - svg.append('translate(%s,%s) rotate(%1.1f)' + svg.append('translate(%f,%f) rotate(%1.1f)' % (x,y,-angle) ) else: - svg.append('translate(%s,%s)' % (x, y)) + svg.append('translate(%f,%f)' % (x, y)) svg.append('">\n') for x, y, width, height in svg_rects: - svg.append('<rect x="%s" y="%s" width="%s" height="%s" fill="black" stroke="none" />' % (x, -y + height, width, height)) + svg.append('<rect x="%f" y="%f" width="%f" height="%f" fill="black" stroke="none" />' % (x, -y + height, width, height)) svg.append("</g>") self.open_group("mathtext") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-08-28 12:42:55
|
Revision: 6052 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6052&view=rev Author: mdboom Date: 2008-08-28 12:42:52 +0000 (Thu, 28 Aug 2008) Log Message: ----------- Fix clip_on kwarg to work correctly. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/artist.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-08-26 13:24:00 UTC (rev 6051) +++ trunk/matplotlib/CHANGELOG 2008-08-28 12:42:52 UTC (rev 6052) @@ -1,3 +1,5 @@ +2008-08-28 Fix clip_on kwarg so it actually works correctly - MGD + 2008-08-25 Fix locale problems in SVG backend - MGD 2008-08-22 fix quiver so masked values are not plotted - JSW Modified: trunk/matplotlib/lib/matplotlib/artist.py =================================================================== --- trunk/matplotlib/lib/matplotlib/artist.py 2008-08-26 13:24:00 UTC (rev 6051) +++ trunk/matplotlib/lib/matplotlib/artist.py 2008-08-28 12:42:52 UTC (rev 6052) @@ -39,7 +39,7 @@ self._alpha = 1.0 self.clipbox = None self._clippath = None - self._clipon = False + self._clipon = True self._lod = False self._label = '' self._picker = None @@ -292,7 +292,6 @@ ACCEPTS: a :class:`matplotlib.transform.Bbox` instance """ self.clipbox = clipbox - self._clipon = clipbox is not None or self._clippath is not None self.pchanged() def set_clip_path(self, path, transform=None): @@ -341,7 +340,6 @@ print type(path), type(transform) raise TypeError("Invalid arguments to set_clip_path") - self._clipon = self.clipbox is not None or self._clippath is not None self.pchanged() def get_alpha(self): @@ -361,7 +359,7 @@ def get_clip_on(self): 'Return whether artist uses clipping' - return self._clipon and (self.clipbox is not None or self._clippath is not None) + return self._clipon def get_clip_box(self): 'Return artist clipbox' @@ -388,16 +386,17 @@ ACCEPTS: [True | False] """ self._clipon = b - if not b: - self.clipbox = None - self._clippath = None self.pchanged() def _set_gc_clip(self, gc): 'set the clip properly for the gc' - if self.clipbox is not None: - gc.set_clip_rectangle(self.clipbox) - gc.set_clip_path(self._clippath) + if self._clipon: + if self.clipbox is not None: + gc.set_clip_rectangle(self.clipbox) + gc.set_clip_path(self._clippath) + else: + gc.set_clip_rectangle(None) + gc.set_clip_path(None) def draw(self, renderer, *args, **kwargs): 'Derived classes drawing method' @@ -511,7 +510,7 @@ def findobj(self, match=None): """ pyplot signature: - findobj(o=gcf(), match=None) + findobj(o=gcf(), match=None) recursively find all :class:matplotlib.artist.Artist instances contained in self This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-08-28 12:45:40
|
Revision: 6053 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6053&view=rev Author: mdboom Date: 2008-08-28 12:45:37 +0000 (Thu, 28 Aug 2008) Log Message: ----------- Fix clip_on kwarg to work correctly. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/backend_bases.py trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py trunk/matplotlib/lib/matplotlib/backends/backend_ps.py trunk/matplotlib/lib/matplotlib/backends/backend_svg.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-08-28 12:42:52 UTC (rev 6052) +++ trunk/matplotlib/CHANGELOG 2008-08-28 12:45:37 UTC (rev 6053) @@ -1,3 +1,5 @@ +2008-08-28 Fix masked arrays with markers in non-Agg backends - MGD + 2008-08-28 Fix clip_on kwarg so it actually works correctly - MGD 2008-08-25 Fix locale problems in SVG backend - MGD Modified: trunk/matplotlib/lib/matplotlib/backend_bases.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backend_bases.py 2008-08-28 12:42:52 UTC (rev 6052) +++ trunk/matplotlib/lib/matplotlib/backend_bases.py 2008-08-28 12:45:37 UTC (rev 6053) @@ -97,10 +97,12 @@ once and reuse it multiple times. """ tpath = trans.transform_path(path) - for x, y in tpath.vertices: - self.draw_path(gc, marker_path, - marker_trans + transforms.Affine2D().translate(x, y), - rgbFace) + for vertices, codes in tpath.iter_segments(): + if len(vertices): + x,y = vertices[-2:] + self.draw_path(gc, marker_path, + marker_trans + transforms.Affine2D().translate(x, y), + rgbFace) def draw_path_collection(self, master_transform, cliprect, clippath, clippath_trans, paths, all_transforms, offsets, Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2008-08-28 12:42:52 UTC (rev 6052) +++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2008-08-28 12:45:37 UTC (rev 6053) @@ -1247,11 +1247,13 @@ output(Op.gsave) lastx, lasty = 0, 0 - for x, y in tpath.vertices: - dx, dy = x - lastx, y - lasty - output(1, 0, 0, 1, dx, dy, Op.concat_matrix, - marker, Op.use_xobject) - lastx, lasty = x, y + for vertices, code in tpath.iter_segments(): + if len(vertices): + x, y = vertices[-2:] + dx, dy = x - lastx, y - lasty + output(1, 0, 0, 1, dx, dy, Op.concat_matrix, + marker, Op.use_xobject) + lastx, lasty = x, y output(Op.grestore) def _setup_textpos(self, x, y, angle, oldx=0, oldy=0, oldangle=0): Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2008-08-28 12:42:52 UTC (rev 6052) +++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2008-08-28 12:45:37 UTC (rev 6053) @@ -510,8 +510,10 @@ ps_cmd.extend(['stroke', 'grestore', '} bind def']) tpath = trans.transform_path(path) - for x, y in tpath.vertices: - ps_cmd.append("%g %g o" % (x, y)) + for vertices, code in tpath.iter_segments(): + if len(vertices): + x, y = vertices[-2:] + ps_cmd.append("%g %g o" % (x, y)) ps = '\n'.join(ps_cmd) self._draw_ps(ps, gc, rgbFace, fill=False, stroke=False) Modified: trunk/matplotlib/lib/matplotlib/backends/backend_svg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2008-08-28 12:42:52 UTC (rev 6052) +++ trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2008-08-28 12:45:37 UTC (rev 6053) @@ -209,10 +209,12 @@ write('<g %s>' % clippath) trans_and_flip = self._make_flip_transform(trans) tpath = trans_and_flip.transform_path(path) - for x, y in tpath.vertices: - details = 'xlink:href="#%s" x="%f" y="%f"' % (name, x, y) - style = self._get_style(gc, rgbFace) - self._svgwriter.write ('<use style="%s" %s/>\n' % (style, details)) + for vertices, code in tpath.iter_segments(): + if len(vertices): + x, y = vertices[-2:] + details = 'xlink:href="#%s" x="%f" y="%f"' % (name, x, y) + style = self._get_style(gc, rgbFace) + self._svgwriter.write ('<use style="%s" %s/>\n' % (style, details)) write('</g>') def draw_path_collection(self, master_transform, cliprect, clippath, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-08-28 13:12:50
|
Revision: 6054 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6054&view=rev Author: mdboom Date: 2008-08-28 13:12:46 +0000 (Thu, 28 Aug 2008) Log Message: ----------- Fix step plots with log scale Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/lines.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-08-28 12:45:37 UTC (rev 6053) +++ trunk/matplotlib/CHANGELOG 2008-08-28 13:12:46 UTC (rev 6054) @@ -1,3 +1,5 @@ +2008-08-28 Fix step plots with log scale - MGD + 2008-08-28 Fix masked arrays with markers in non-Agg backends - MGD 2008-08-28 Fix clip_on kwarg so it actually works correctly - MGD Modified: trunk/matplotlib/lib/matplotlib/lines.py =================================================================== --- trunk/matplotlib/lib/matplotlib/lines.py 2008-08-28 12:45:37 UTC (rev 6053) +++ trunk/matplotlib/lib/matplotlib/lines.py 2008-08-28 13:12:46 UTC (rev 6054) @@ -14,7 +14,7 @@ from cbook import iterable, is_string_like, is_numlike, ls_mapper, dedent from colors import colorConverter from path import Path -from transforms import Affine2D, Bbox, TransformedPath +from transforms import Affine2D, Bbox, TransformedPath, IdentityTransform from matplotlib import rcParams # special-purpose marker identifiers: @@ -675,7 +675,8 @@ steps[0::2, 1], steps[1:-1:2, 1] = vertices[:, 1], vertices[1:, 1] path = Path(steps) - self._draw_solid(renderer, gc, path, trans) + path = path.transformed(self.get_transform()) + self._draw_solid(renderer, gc, path, IdentityTransform()) def _draw_steps_post(self, renderer, gc, path, trans): @@ -686,7 +687,8 @@ steps[0::2, 1], steps[1::2, 1] = vertices[:, 1], vertices[:-1, 1] path = Path(steps) - self._draw_solid(renderer, gc, path, trans) + path = path.transformed(self.get_transform()) + self._draw_solid(renderer, gc, path, IdentityTransform()) def _draw_steps_mid(self, renderer, gc, path, trans): @@ -700,7 +702,8 @@ steps[0::2, 1], steps[1::2, 1] = vertices[:, 1], vertices[:, 1] path = Path(steps) - self._draw_solid(renderer, gc, path, trans) + path = path.transformed(self.get_transform()) + self._draw_solid(renderer, gc, path, IdentityTransform()) def _draw_dashed(self, renderer, gc, path, trans): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mme...@us...> - 2008-08-28 13:50:42
|
Revision: 6055 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6055&view=rev Author: mmetz_bn Date: 2008-08-28 13:50:39 +0000 (Thu, 28 Aug 2008) Log Message: ----------- support for multi-hist with different length Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/examples/pylab_examples/histogram_demo_extended.py trunk/matplotlib/lib/matplotlib/axes.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-08-28 13:12:46 UTC (rev 6054) +++ trunk/matplotlib/CHANGELOG 2008-08-28 13:50:39 UTC (rev 6055) @@ -1,3 +1,6 @@ +2008-08-28 Added support for multiple histograms with data of + different length - MM + 2008-08-28 Fix step plots with log scale - MGD 2008-08-28 Fix masked arrays with markers in non-Agg backends - MGD Modified: trunk/matplotlib/examples/pylab_examples/histogram_demo_extended.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/histogram_demo_extended.py 2008-08-28 13:12:46 UTC (rev 6054) +++ trunk/matplotlib/examples/pylab_examples/histogram_demo_extended.py 2008-08-28 13:50:39 UTC (rev 6055) @@ -78,5 +78,16 @@ n, bins, patches = P.hist(x, 10, normed=1, histtype='barstacked') +# +# finally: make a multiple-histogram of data-sets with different length +# +x0 = mu + sigma*P.randn(10000) +x1 = mu + sigma*P.randn(7000) +x2 = mu + sigma*P.randn(3000) +P.figure() + +n, bins, patches = P.hist( [x0,x1,x2], 10, histtype='bar') + + P.show() \ No newline at end of file Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-08-28 13:12:46 UTC (rev 6054) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-08-28 13:50:39 UTC (rev 6055) @@ -6157,7 +6157,7 @@ - 'step' generates a lineplot that is by default unfilled - - 'stepfilled' generates a lineplot that this by default + - 'stepfilled' generates a lineplot that is by default filled. *align*: ['left' | 'mid' | 'right' ] @@ -6209,26 +6209,27 @@ raise DeprecationWarning( 'hist now uses the rwidth to give relative width and not absolute width') - # todo: make hist() work with list of arrays with different lengths - x = np.asarray(x).copy() - if len(x.shape)==2 and min(x.shape)==1: - x.shape = max(x.shape), + try: + x = np.transpose(np.asarray(x).copy()) + if len(x.shape)==1: + x.shape = (1,x.shape[0]) + elif len(x.shape)==2 and x.shape[1]<x.shape[0]: + warnings.warn('2D hist should be nsamples x nvariables; this looks transposed') + except ValueError: + # multiple hist with data of different length + if iterable(x[0]) and not is_string_like(x[0]): + tx = [] + for i in xrange(len(x)): + tx.append( np.asarray(x[i]).copy() ) + x = tx - if len(x.shape)==2 and x.shape[0]<x.shape[1]: - warnings.warn('2D hist should be nsamples x nvariables; this looks transposed') - - if len(x.shape)==2: - n = [] - for i in xrange(x.shape[1]): - # this will automatically overwrite bins, - # so that each histogram uses the same bins - m, bins = np.histogram(x[:,i], bins, range=range, - normed=bool(normed), new=True) - n.append(m) - else: - n, bins = np.histogram(x, bins, range=range, + n = [] + for i in xrange(len(x)): + # this will automatically overwrite bins, + # so that each histogram uses the same bins + m, bins = np.histogram(x[i], bins, range=range, normed=bool(normed), new=True) - n = [n,] + n.append(m) if cumulative: slc = slice(None) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-09-01 21:06:37
|
Revision: 6057 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6057&view=rev Author: efiring Date: 2008-09-01 21:06:34 +0000 (Mon, 01 Sep 2008) Log Message: ----------- Bilinear interp in NonUniformImage; slightly modified patch by Gregory Lielens Includes a bugfix in _image.pcolor2. Replaced pylab_examples/pcolor_nonuniform.py with the more aptly-named image_nonuniform.py, modified it to show both interpolation types, and added it to backend_driver.py. Modified Paths: -------------- trunk/matplotlib/examples/tests/backend_driver.py trunk/matplotlib/lib/matplotlib/image.py trunk/matplotlib/src/_image.cpp Added Paths: ----------- trunk/matplotlib/examples/pylab_examples/image_nonuniform.py Removed Paths: ------------- trunk/matplotlib/examples/pylab_examples/pcolor_nonuniform.py Added: trunk/matplotlib/examples/pylab_examples/image_nonuniform.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/image_nonuniform.py (rev 0) +++ trunk/matplotlib/examples/pylab_examples/image_nonuniform.py 2008-09-01 21:06:34 UTC (rev 6057) @@ -0,0 +1,55 @@ +''' +This illustrates the NonUniformImage class, which still needs +an axes method interface; either a separate interface, or a +generalization of imshow. +''' + +from matplotlib.pyplot import figure, show +import numpy as np +from matplotlib.image import NonUniformImage + +interp='nearest' + +x = np.linspace(-4, 4, 9) +x2 = x**3 +y = np.linspace(-4, 4, 9) +print 'Size %d points' % (len(x) * len(y)) +z = np.sqrt(x[np.newaxis,:]**2 + y[:,np.newaxis]**2) + +fig = figure() +fig.suptitle('NonUniformImage class') +ax = fig.add_subplot(221) +im = NonUniformImage(ax, interpolation=interp, extent=(-4,4,-4,4)) +im.set_data(x, y, z) +ax.images.append(im) +ax.set_xlim(-4,4) +ax.set_ylim(-4,4) +ax.set_title(interp) + +ax = fig.add_subplot(222) +im = NonUniformImage(ax, interpolation=interp, extent=(-64,64,-4,4)) +im.set_data(x2, y, z) +ax.images.append(im) +ax.set_xlim(-64,64) +ax.set_ylim(-4,4) +ax.set_title(interp) + +interp = 'bilinear' + +ax = fig.add_subplot(223) +im = NonUniformImage(ax, interpolation=interp, extent=(-4,4,-4,4)) +im.set_data(x, y, z) +ax.images.append(im) +ax.set_xlim(-4,4) +ax.set_ylim(-4,4) +ax.set_title(interp) + +ax = fig.add_subplot(224) +im = NonUniformImage(ax, interpolation=interp, extent=(-64,64,-4,4)) +im.set_data(x2, y, z) +ax.images.append(im) +ax.set_xlim(-64,64) +ax.set_ylim(-4,4) +ax.set_title(interp) + +show() Deleted: trunk/matplotlib/examples/pylab_examples/pcolor_nonuniform.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/pcolor_nonuniform.py 2008-08-30 10:11:37 UTC (rev 6056) +++ trunk/matplotlib/examples/pylab_examples/pcolor_nonuniform.py 2008-09-01 21:06:34 UTC (rev 6057) @@ -1,26 +0,0 @@ -from matplotlib.pyplot import figure, show -import numpy as np -from matplotlib.image import NonUniformImage - -x = np.arange(-4, 4, 0.005) -y = np.arange(-4, 4, 0.005) -print 'Size %d points' % (len(x) * len(y)) -z = np.sqrt(x[np.newaxis,:]**2 + y[:,np.newaxis]**2) - -fig = figure() -ax = fig.add_subplot(111) -im = NonUniformImage(ax, extent=(-4,4,-4,4)) -im.set_data(x, y, z) -ax.images.append(im) -ax.set_xlim(-4,4) -ax.set_ylim(-4,4) - -fig2 = figure() -ax = fig2.add_subplot(111) -x2 = x**3 -im = NonUniformImage(ax, extent=(-64,64,-4,4)) -im.set_data(x2, y, z) -ax.images.append(im) -ax.set_xlim(-64,64) -ax.set_ylim(-4,4) -show() Modified: trunk/matplotlib/examples/tests/backend_driver.py =================================================================== --- trunk/matplotlib/examples/tests/backend_driver.py 2008-08-30 10:11:37 UTC (rev 6056) +++ trunk/matplotlib/examples/tests/backend_driver.py 2008-09-01 21:06:34 UTC (rev 6057) @@ -66,6 +66,7 @@ 'image_demo2.py', 'image_masked.py', 'image_origin.py', + 'image_nonuniform.py', 'invert_axes.py', 'layer_images.py', 'legend_auto.py', Modified: trunk/matplotlib/lib/matplotlib/image.py =================================================================== --- trunk/matplotlib/lib/matplotlib/image.py 2008-08-30 10:11:37 UTC (rev 6056) +++ trunk/matplotlib/lib/matplotlib/image.py 2008-09-01 21:06:34 UTC (rev 6057) @@ -392,13 +392,14 @@ def __init__(self, ax, **kwargs ): + interp = kwargs.pop('interpolation', 'nearest') AxesImage.__init__(self, ax, **kwargs) + AxesImage.set_interpolation(self, interp) def make_image(self, magnification=1.0): if self._A is None: raise RuntimeError('You must first set the image array') - x0, y0, v_width, v_height = self.axes.viewLim.bounds l, b, r, t = self.axes.bbox.extents width = (round(r) + 0.5) - (round(l) - 0.5) @@ -407,10 +408,13 @@ height *= magnification im = _image.pcolor(self._Ax, self._Ay, self._A, height, width, - (x0, x0+v_width, y0, y0+v_height)) + (x0, x0+v_width, y0, y0+v_height), + self._interpd[self._interpolation]) + fc = self.axes.patch.get_facecolor() bg = mcolors.colorConverter.to_rgba(fc, 0) im.set_bg(*bg) + im.is_grayscale = self.is_grayscale return im def set_data(self, x, y, A): @@ -430,9 +434,11 @@ if len(A.shape) == 2: if A.dtype != np.uint8: A = (self.cmap(self.norm(A))*255).astype(np.uint8) + self.is_grayscale = self.cmap.is_gray() else: A = np.repeat(A[:,:,np.newaxis], 4, 2) A[:,:,3] = 255 + self.is_grayscale = True else: if A.dtype != np.uint8: A = (255*A).astype(np.uint8) @@ -441,6 +447,7 @@ B[:,:,0:3] = A B[:,:,3] = 255 A = B + self.is_grayscale = False self._A = A self._Ax = x self._Ay = y @@ -450,8 +457,8 @@ raise NotImplementedError('Method not supported') def set_interpolation(self, s): - if s != None and s != 'nearest': - raise NotImplementedError('Only nearest neighbor supported') + if s != None and not s in ('nearest','bilinear'): + raise NotImplementedError('Only nearest neighbor and bilinear interpolations are supported') AxesImage.set_interpolation(self, s) def get_extent(self): Modified: trunk/matplotlib/src/_image.cpp =================================================================== --- trunk/matplotlib/src/_image.cpp 2008-08-30 10:11:37 UTC (rev 6056) +++ trunk/matplotlib/src/_image.cpp 2008-09-01 21:06:34 UTC (rev 6057) @@ -1138,21 +1138,211 @@ return Py::asObject(imo); } +// utilities for irregular grids +void _bin_indices_middle(unsigned int *irows, int nrows, float *ys1, int ny,float dy, float y_min) +{ int i,j, j_last; + unsigned int * rowstart = irows; + float *ys2 = ys1+1; + float *yl = ys1 + ny ; + float yo = y_min + dy/2.0; + float ym = 0.5f*(*ys1 + *ys2); + // y/rows + j = 0; + j_last = j; + for (i=0;i<nrows;i++,yo+=dy,rowstart++) { + while(ys2 != yl && yo > ym) { + ys1 = ys2; + ys2 = ys1+1; + ym = 0.5f*(*ys1 + *ys2); + j++; + } + *rowstart = j - j_last; + j_last = j; + } +} +void _bin_indices_middle_linear(float *arows, unsigned int *irows, int nrows, float *y, int ny,float dy, float y_min) +{ int i; + int ii = 0; + int iilast = ny-1; + float sc = 1/dy; + int iy0 = (int)floor(sc * (y[ii] - y_min) ); + int iy1 = (int)floor(sc * (y[ii+1] - y_min) ); + float invgap=1.0f/(iy1-iy0); + for (i=0; i<nrows && i<=iy0; i++) { + irows[i] = 0; + arows[i] = 1.0; + //std::cerr<<"i="<<i<<" ii="<<0<<" a="<< arows[i]<< std::endl; + } + for (; i<nrows; i++) { + while (i > iy1 && ii < iilast) { + ii++; + iy0 = iy1; + iy1 = (int)floor(sc * (y[ii+1] - y_min)); + invgap=1.0f/(iy1-iy0); + } + if (i >= iy0 && i <= iy1) { + irows[i] = ii; + arows[i]=(iy1-i)*invgap; + //std::cerr<<"i="<<i<<" ii="<<ii<<" a="<< arows[i]<< std::endl; + } + else break; + } + for (; i<nrows; i++) { + irows[i] =iilast-1; + arows[i] = 0.0; + //std::cerr<<"i="<<i<<" ii="<<iilast-1<<" a="<< arows[i]<< std::endl; + } +} + +void _bin_indices(int *irows, int nrows, double *y, int ny, + double sc, double offs) +{ + int i; + if (sc*(y[ny-1] - y[0]) > 0) + { + int ii = 0; + int iilast = ny-1; + int iy0 = (int)floor(sc * (y[ii] - offs)); + int iy1 = (int)floor(sc * (y[ii+1] - offs)); + for (i=0; i<nrows && i<iy0; i++) { + irows[i] = -1; + } + for (; i<nrows; i++) { + while (i > iy1 && ii < iilast) { + ii++; + iy0 = iy1; + iy1 = (int)floor(sc * (y[ii+1] - offs)); + } + if (i >= iy0 && i <= iy1) irows[i] = ii; + else break; + } + for (; i<nrows; i++) { + irows[i] = -1; + } + } + else + { + int iilast = ny-1; + int ii = iilast; + int iy0 = (int)floor(sc * (y[ii] - offs)); + int iy1 = (int)floor(sc * (y[ii-1] - offs)); + for (i=0; i<nrows && i<iy0; i++) { + irows[i] = -1; + } + for (; i<nrows; i++) { + while (i > iy1 && ii > 1) { + ii--; + iy0 = iy1; + iy1 = (int)floor(sc * (y[ii-1] - offs)); + } + if (i >= iy0 && i <= iy1) irows[i] = ii-1; + else break; + } + for (; i<nrows; i++) { + irows[i] = -1; + } + } +} + +void _bin_indices_linear(float *arows, int *irows, int nrows, double *y, int ny, + double sc, double offs) +{ + int i; + if (sc*(y[ny-1] - y[0]) > 0) + { + int ii = 0; + int iilast = ny-1; + int iy0 = (int)floor(sc * (y[ii] - offs)); + int iy1 = (int)floor(sc * (y[ii+1] - offs)); + float invgap=1.0/(iy1-iy0); + for (i=0; i<nrows && i<iy0; i++) { + irows[i] = -1; + } + for (; i<nrows; i++) { + while (i > iy1 && ii < iilast) { + ii++; + iy0 = iy1; + iy1 = (int)floor(sc * (y[ii+1] - offs)); + invgap=1.0/(iy1-iy0); + } + if (i >= iy0 && i <= iy1) { + irows[i] = ii; + arows[i]=(iy1-i)*invgap; + } + else break; + } + for (; i<nrows; i++) { + irows[i] = -1; + } + } + else + { + int iilast = ny-1; + int ii = iilast; + int iy0 = (int)floor(sc * (y[ii] - offs)); + int iy1 = (int)floor(sc * (y[ii-1] - offs)); + float invgap=1.0/(iy1-iy0); + for (i=0; i<nrows && i<iy0; i++) { + irows[i] = -1; + } + for (; i<nrows; i++) { + while (i > iy1 && ii > 1) { + ii--; + iy0 = iy1; + iy1 = (int)floor(sc * (y[ii-1] - offs)); + invgap=1.0/(iy1-iy0); + } + if (i >= iy0 && i <= iy1) { + irows[i] = ii-1; + arows[i]=(i-iy0)*invgap; + } + else break; + } + for (; i<nrows; i++) { + irows[i] = -1; + } + } +} + + + char __image_module_pcolor__doc__[] = "pcolor(x, y, data, rows, cols, bounds)\n" "\n" -"Generate a psudo-color image from data on a non-univorm grid using\n" -"nearest neighbour interpolation.\n" +"Generate a pseudo-color image from data on a non-uniform grid using\n" +"nearest neighbour or linear interpolation.\n" "bounds = (x_min, x_max, y_min, y_max)\n" +"interpolation = NEAREST or BILINEAR \n" ; + +void _pcolor_cleanup(PyArrayObject* x, PyArrayObject* y, PyArrayObject *d, + unsigned int * rowstarts ,unsigned int*colstarts , + float *acols , float *arows) { + if (x) + Py_XDECREF(x); + if (y) + Py_XDECREF(y); + if(d) + Py_XDECREF(d); + if(rowstarts) + PyMem_Free(rowstarts); + if(colstarts) + PyMem_Free(colstarts); + if(acols) + PyMem_Free(acols); + if(arows) + PyMem_Free(arows); + return; +} + Py::Object _image_module::pcolor(const Py::Tuple& args) { _VERBOSE("_image_module::pcolor"); - if (args.length() != 6) - throw Py::TypeError("Incorrect number of arguments (6 expected)"); + if (args.length() != 7) + throw Py::TypeError("Incorrect number of arguments (7 expected)"); Py::Object xp = args[0]; Py::Object yp = args[1]; @@ -1160,6 +1350,7 @@ unsigned int rows = Py::Int(args[3]); unsigned int cols = Py::Int(args[4]); Py::Tuple bounds = args[5]; + unsigned int interpolation = Py::Int(args[6]); if (rows > 1 << 15 || cols > 1 << 15) { throw Py::ValueError("rows and cols must both be less than 32768"); @@ -1179,26 +1370,29 @@ // Check we have something to output to if (rows == 0 || cols ==0) throw Py::ValueError("Cannot scale to zero size"); - + + PyArrayObject *x = NULL; PyArrayObject *y = NULL; PyArrayObject *d = NULL; + unsigned int * rowstarts = NULL; unsigned int*colstarts = NULL; + float *acols = NULL; float *arows = NULL; + // Get numpy arrays - PyArrayObject *x = (PyArrayObject *) PyArray_ContiguousFromObject(xp.ptr(), PyArray_FLOAT, 1, 1); - if (x == NULL) + x = (PyArrayObject *) PyArray_ContiguousFromObject(xp.ptr(), PyArray_FLOAT, 1, 1); + if (x == NULL) { + _pcolor_cleanup(x,y,d,rowstarts,colstarts,acols,arows); throw Py::ValueError("x is of incorrect type (wanted 1D float)"); - PyArrayObject *y = (PyArrayObject *) PyArray_ContiguousFromObject(yp.ptr(), PyArray_FLOAT, 1, 1); + } + y = (PyArrayObject *) PyArray_ContiguousFromObject(yp.ptr(), PyArray_FLOAT, 1, 1); if (y == NULL) { - Py_XDECREF(x); - throw Py::ValueError("y is of incorrect type (wanted 1D float)"); + _pcolor_cleanup(x,y,d,rowstarts,colstarts,acols,arows); + throw Py::ValueError("y is of incorrect type (wanted 1D float)"); } - PyArrayObject *d = (PyArrayObject *) PyArray_ContiguousFromObject(dp.ptr(), PyArray_UBYTE, 3, 3); + d = (PyArrayObject *) PyArray_ContiguousFromObject(dp.ptr(), PyArray_UBYTE, 3, 3); if (d == NULL) { - Py_XDECREF(x); - Py_XDECREF(y); + _pcolor_cleanup(x,y,d,rowstarts,colstarts,acols,arows); throw Py::ValueError("data is of incorrect type (wanted 3D UInt8)"); } if (d->dimensions[2] != 4) { - Py_XDECREF(x); - Py_XDECREF(y); - Py_XDECREF(d); + _pcolor_cleanup(x,y,d,rowstarts,colstarts,acols,arows); throw Py::ValueError("data must be in RGBA format"); } @@ -1206,26 +1400,21 @@ int nx = x->dimensions[0]; int ny = y->dimensions[0]; if (nx != d->dimensions[1] || ny != d->dimensions[0]) { - Py_XDECREF(x); - Py_XDECREF(y); - Py_XDECREF(d); + _pcolor_cleanup(x,y,d,rowstarts,colstarts,acols,arows); throw Py::ValueError("data and axis dimensions do not match"); } // Allocate memory for pointer arrays - unsigned int * rowstarts = reinterpret_cast<unsigned int*>(PyMem_Malloc(sizeof(unsigned int)*rows)); - if (rowstarts == NULL) { - Py_XDECREF(x); - Py_XDECREF(y); - Py_XDECREF(d); + rowstarts = reinterpret_cast<unsigned int*>(PyMem_Malloc(sizeof(unsigned int)*rows)); + arows = reinterpret_cast<float *>(PyMem_Malloc(sizeof(float)*rows)); + if (rowstarts == NULL || arows == NULL ) { + _pcolor_cleanup(x,y,d,rowstarts,colstarts,acols,arows); throw Py::MemoryError("Cannot allocate memory for lookup table"); } - unsigned int * colstarts = reinterpret_cast<unsigned int*>(PyMem_Malloc(sizeof(unsigned int*)*cols)); - if (colstarts == NULL) { - Py_XDECREF(x); - Py_XDECREF(y); - Py_XDECREF(d); - PyMem_Free(rowstarts); + colstarts = reinterpret_cast<unsigned int*>(PyMem_Malloc(sizeof(unsigned int)*cols)); + acols = reinterpret_cast<float*>(PyMem_Malloc(sizeof(float)*cols)); + if (colstarts == NULL || acols == NULL) { + _pcolor_cleanup(x,y,d,rowstarts,colstarts,acols,arows); throw Py::MemoryError("Cannot allocate memory for lookup table"); } @@ -1238,54 +1427,17 @@ size_t NUMBYTES(rows * cols * 4); agg::int8u *buffer = new agg::int8u[NUMBYTES]; if (buffer == NULL) { - Py_XDECREF(x); - Py_XDECREF(y); - Py_XDECREF(d); - PyMem_Free(rowstarts); - PyMem_Free(colstarts); + _pcolor_cleanup(x,y,d,rowstarts,colstarts,acols,arows); throw Py::MemoryError("Could not allocate memory for image"); } + // Calculate the pointer arrays to map input x to output x - unsigned int i, j, j_last; + unsigned int i, j; unsigned int * colstart = colstarts; unsigned int * rowstart = rowstarts; float *xs1 = reinterpret_cast<float*>(x->data); float *ys1 = reinterpret_cast<float*>(y->data); - float *xs2 = xs1+1; - float *ys2 = ys1+1; - float *xl = xs1 + nx - 1; - float *yl = ys1 + ny - 1; - float xo = x_min + dx/2.0; - float yo = y_min + dy/2.0; - float xm = 0.5*(*xs1 + *xs2); - float ym = 0.5*(*ys1 + *ys2); - // x/cols - j = 0; - j_last = j; - for (i=0;i<cols;i++,xo+=dx,colstart++) { - while(xs2 != xl && xo > xm) { - xs1 = xs2; - xs2 = xs1+1; - xm = 0.5f*(*xs1 + *xs2); - j++; - } - *colstart = j - j_last; - j_last = j; - } - // y/rows - j = 0; - j_last = j; - for (i=0;i<rows;i++,yo+=dy,rowstart++) { - while(ys2 != yl && yo > ym) { - ys1 = ys2; - ys2 = ys1+1; - ym = 0.5f*(*ys1 + *ys2); - j++; - } - *rowstart = j - j_last; - j_last = j; - } // Copy data to output buffer @@ -1297,87 +1449,82 @@ agg::int8u * position = buffer; agg::int8u * oldposition = NULL; start = reinterpret_cast<unsigned char*>(d->data); - for(i=0;i<rows;i++,rowstart++) - { - if (i > 0 && *rowstart == 0) { - memcpy(position, oldposition, rowsize*sizeof(agg::int8u)); - oldposition = position; - position += rowsize; - } else { - oldposition = position; - start += *rowstart * inrowsize; - inposition = start; - for(j=0,colstart=colstarts;j<cols;j++,position+=4,colstart++) { - inposition += *colstart * 4; - memcpy(position, inposition, 4*sizeof(agg::int8u)); + int s0 = d->strides[0]; + int s1 = d->strides[1]; + + if(interpolation == Image::NEAREST) { + _bin_indices_middle(colstart, cols, xs1, nx,dx,x_min); + _bin_indices_middle(rowstart, rows, ys1, ny, dy,y_min); + for(i=0;i<rows;i++,rowstart++) + { + if (i > 0 && *rowstart == 0) { + memcpy(position, oldposition, rowsize*sizeof(agg::int8u)); + oldposition = position; + position += rowsize; + } else { + oldposition = position; + start += *rowstart * inrowsize; + inposition = start; + for(j=0,colstart=colstarts;j<cols;j++,position+=4,colstart++) { + inposition += *colstart * 4; + memcpy(position, inposition, 4*sizeof(agg::int8u)); + } } } } + else if(interpolation == Image::BILINEAR) { + _bin_indices_middle_linear(acols, colstart, cols, xs1, nx,dx,x_min); + _bin_indices_middle_linear(arows, rowstart, rows, ys1, ny, dy,y_min); + double a00,a01,a10,a11,alpha,beta; + + + agg::int8u * start00; + agg::int8u * start01; + agg::int8u * start10; + agg::int8u * start11; + // Copy data to output buffer + for (i=0; i<rows; i++) + { + for (j=0; j<cols; j++) + { + alpha=arows[i]; + beta=acols[j]; + + a00=alpha*beta; + a01=alpha*(1.0-beta); + a10=(1.0-alpha)*beta; + a11=1.0-a00-a01-a10; + + start00=(agg::int8u *)(start + s0*rowstart[i] + s1*colstart[j]); + start01=start00+s1; + start10=start00+s0; + start11=start10+s1; + position[0] =(agg::int8u)(start00[0]*a00+start01[0]*a01+start10[0]*a10+start11[0]*a11); + position[1] =(agg::int8u)(start00[1]*a00+start01[1]*a01+start10[1]*a10+start11[1]*a11); + position[2] =(agg::int8u)(start00[2]*a00+start01[2]*a01+start10[2]*a10+start11[2]*a11); + position[3] =(agg::int8u)(start00[3]*a00+start01[3]*a01+start10[3]*a10+start11[3]*a11); + position += 4; + } + } + + } + // Attatch output buffer to output buffer imo->rbufOut = new agg::rendering_buffer; imo->bufferOut = buffer; imo->rbufOut->attach(imo->bufferOut, imo->colsOut, imo->rowsOut, imo->colsOut * imo->BPP); - Py_XDECREF(x); - Py_XDECREF(y); - Py_XDECREF(d); - PyMem_Free(rowstarts); - PyMem_Free(colstarts); + + _pcolor_cleanup(x,y,d,rowstarts,colstarts,acols,arows); return Py::asObject(imo); -} + -void _bin_indices(int *irows, int nrows, double *y, int ny, - double sc, double offs) -{ - int i; - if (sc*(y[ny-1] - y[0]) > 0) - { - int ii = 0; - int iilast = ny-1; - int iy0 = (int)floor(sc * (y[ii] - offs)); - int iy1 = (int)floor(sc * (y[ii+1] - offs)); - for (i=0; i<nrows && i<iy0; i++) { - irows[i] = -1; - } - for (; i<nrows; i++) { - while (i > iy1 && ii < iilast) { - ii++; - iy0 = iy1; - iy1 = (int)floor(sc * (y[ii+1] - offs)); - } - if (i >= iy0 && i <= iy1) irows[i] = ii; - else break; - } - for (; i<nrows; i++) { - irows[i] = -1; - } - } - else - { - int iilast = ny-1; - int ii = iilast; - int iy0 = (int)floor(sc * (y[ii] - offs)); - int iy1 = (int)floor(sc * (y[ii-1] - offs)); - for (i=0; i<nrows && i<iy0; i++) { - irows[i] = -1; - } - for (; i<nrows; i++) { - while (i > iy1 && ii > 1) { - ii--; - iy0 = iy1; - iy1 = (int)floor(sc * (y[ii-1] - offs)); - } - if (i >= iy0 && i <= iy1) irows[i] = ii-1; - else break; - } - for (; i<nrows; i++) { - irows[i] = -1; - } - } + } + char __image_module_pcolor2__doc__[] = "pcolor2(x, y, data, rows, cols, bounds, bg)\n" "\n" @@ -1477,7 +1624,7 @@ Py_XDECREF(bg); throw Py::MemoryError("Cannot allocate memory for lookup table"); } - int * jcols = reinterpret_cast<int*>(PyMem_Malloc(sizeof(int*)*cols)); + int * jcols = reinterpret_cast<int*>(PyMem_Malloc(sizeof(int)*cols)); if (jcols == NULL) { Py_XDECREF(x); Py_XDECREF(y); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-09-01 21:09:11
|
Revision: 6058 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6058&view=rev Author: efiring Date: 2008-09-01 21:09:09 +0000 (Mon, 01 Sep 2008) Log Message: ----------- Update CHANGELOG for Lielens NonUniformImage patch Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/pyplot.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-09-01 21:06:34 UTC (rev 6057) +++ trunk/matplotlib/CHANGELOG 2008-09-01 21:09:09 UTC (rev 6058) @@ -1,3 +1,6 @@ +2008-09-01 Added support for bilinear interpolation in + NonUniformImage; patch by Gregory Lielens. - EF + 2008-08-28 Added support for multiple histograms with data of different length - MM Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-09-01 21:06:34 UTC (rev 6057) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-09-01 21:09:09 UTC (rev 6058) @@ -6216,7 +6216,7 @@ elif len(x.shape)==2 and x.shape[1]<x.shape[0]: warnings.warn('2D hist should be nsamples x nvariables; this looks transposed') except ValueError: - # multiple hist with data of different length + # multiple hist with data of different length if iterable(x[0]) and not is_string_like(x[0]): tx = [] for i in xrange(len(x)): Modified: trunk/matplotlib/lib/matplotlib/pyplot.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pyplot.py 2008-09-01 21:06:34 UTC (rev 6057) +++ trunk/matplotlib/lib/matplotlib/pyplot.py 2008-09-01 21:09:09 UTC (rev 6058) @@ -2354,7 +2354,7 @@ except: hold(b) raise - + hold(b) return ret if Axes.barbs.__doc__ is not None: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-09-03 19:15:30
|
Revision: 6061 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6061&view=rev Author: mdboom Date: 2008-09-03 19:15:22 +0000 (Wed, 03 Sep 2008) Log Message: ----------- [ 2091036 ] Using log axes with base 2 fails Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/scale.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-09-01 22:50:47 UTC (rev 6060) +++ trunk/matplotlib/CHANGELOG 2008-09-03 19:15:22 UTC (rev 6061) @@ -1,3 +1,5 @@ +2008-09-03 Fix log with base 2 - MGD + 2008-09-01 Added support for bilinear interpolation in NonUniformImage; patch by Gregory Lielens. - EF Modified: trunk/matplotlib/lib/matplotlib/scale.py =================================================================== --- trunk/matplotlib/lib/matplotlib/scale.py 2008-09-01 22:50:47 UTC (rev 6060) +++ trunk/matplotlib/lib/matplotlib/scale.py 2008-09-03 19:15:22 UTC (rev 6061) @@ -91,7 +91,7 @@ def transform(self, a): a = _mask_non_positives(a * 2.0) if isinstance(a, MaskedArray): - return ma.log2(a) + return ma.log(a) / np.log(2) return np.log2(a) def inverted(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-09-05 03:23:32
|
Revision: 6067 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6067&view=rev Author: efiring Date: 2008-09-05 03:23:30 +0000 (Fri, 05 Sep 2008) Log Message: ----------- Improve masked array support in collections and quiver Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/line_collection.py trunk/matplotlib/lib/matplotlib/collections.py trunk/matplotlib/lib/matplotlib/quiver.py Modified: trunk/matplotlib/examples/pylab_examples/line_collection.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/line_collection.py 2008-09-05 02:02:49 UTC (rev 6066) +++ trunk/matplotlib/examples/pylab_examples/line_collection.py 2008-09-05 03:23:30 UTC (rev 6067) @@ -1,33 +1,42 @@ -from pylab import * +import matplotlib.pyplot as plt from matplotlib.collections import LineCollection -from matplotlib.colors import ColorConverter -colorConverter = ColorConverter() +from matplotlib.colors import colorConverter +import numpy as np + # In order to efficiently plot many lines in a single set of axes, # Matplotlib has the ability to add the lines all at once. Here is a # simple example showing how it is done. -x = arange(200) +x = np.arange(100) # Here are many sets of y to plot vs x -ys = [x+i for i in x] +ys = x[:50, np.newaxis] + x[np.newaxis, :] -# We need to set the plot limits, the will not autoscale -ax = axes() -ax.set_xlim((amin(x),amax(x))) -ax.set_ylim((amin(amin(ys)),amax(amax(ys)))) +segs = np.zeros((50, 100, 2), float) +segs[:,:,1] = ys +segs[:,:,0] = x +# Mask some values to test masked array support: +segs = np.ma.masked_where((segs > 50) & (segs < 60), segs) + +# We need to set the plot limits. +ax = plt.axes() +ax.set_xlim(x.min(), x.max()) +ax.set_ylim(ys.min(), ys.max()) + # colors is sequence of rgba tuples # linestyle is a string or dash tuple. Legal string values are # solid|dashed|dashdot|dotted. The dash tuple is (offset, onoffseq) # where onoffseq is an even length tuple of on and off ink in points. # If linestyle is omitted, 'solid' is used # See matplotlib.collections.LineCollection for more information -line_segments = LineCollection([zip(x,y) for y in ys], # Make a sequence of x,y pairs +line_segments = LineCollection(segs, linewidths = (0.5,1,1.5,2), colors = [colorConverter.to_rgba(i) \ for i in ('b','g','r','c','m','y','k')], linestyle = 'solid') ax.add_collection(line_segments) -show() +ax.set_title('Line collection with masked arrays') +plt.show() Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2008-09-05 02:02:49 UTC (rev 6066) +++ trunk/matplotlib/lib/matplotlib/collections.py 2008-09-05 03:23:30 UTC (rev 6067) @@ -602,9 +602,13 @@ if closed: self._paths = [] for xy in verts: - xy = np.asarray(xy) - if len(xy) and (xy[0] != xy[-1]).any(): - xy = np.concatenate([xy, [xy[0]]]) + if np.ma.isMaskedArray(xy): + if len(xy) and (xy[0] != xy[-1]).any(): + xy = np.ma.concatenate([xy, [xy[0]]]) + else: + xy = np.asarray(xy) + if len(xy) and (xy[0] != xy[-1]).any(): + xy = np.concatenate([xy, [xy[0]]]) self._paths.append(mpath.Path(xy)) else: self._paths = [mpath.Path(xy) for xy in verts] @@ -819,10 +823,14 @@ def set_segments(self, segments): if segments is None: return - segments = [np.asarray(seg, np.float_) for seg in segments] + _segments = [] + for seg in segments: + if not np.ma.isMaskedArray(seg): + seg = np.asarray(seg, np.float_) + _segments.append(seg) if self._uniform_offsets is not None: - segments = self._add_offsets(segments) - self._paths = [mpath.Path(seg) for seg in segments] + _segments = self._add_offsets(_segments) + self._paths = [mpath.Path(seg) for seg in _segments] set_verts = set_segments # for compatibility with PolyCollection Modified: trunk/matplotlib/lib/matplotlib/quiver.py =================================================================== --- trunk/matplotlib/lib/matplotlib/quiver.py 2008-09-05 02:02:49 UTC (rev 6066) +++ trunk/matplotlib/lib/matplotlib/quiver.py 2008-09-05 03:23:30 UTC (rev 6067) @@ -57,7 +57,7 @@ match the column and row dimensions of *U*, then *X* and *Y* will be expanded with :func:`numpy.meshgrid`. -*U*, *V*, *C* may be masked arrays, but masked *X*, ** are not +*U*, *V*, *C* may be masked arrays, but masked *X*, *Y* are not supported at present. Keyword arguments: @@ -334,12 +334,6 @@ def __init__(self, ax, *args, **kw): self.ax = ax X, Y, U, V, C = self._parse_args(*args) - if C is not None: - X, Y, U, V, C = delete_masked_points(X.ravel(),Y.ravel(),U.ravel(), - V.ravel(),C.ravel()) - else: - X, Y, U, V = delete_masked_points(X.ravel(),Y.ravel(),U.ravel(), - V.ravel()) self.X = X self.Y = Y self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis])) @@ -357,7 +351,9 @@ kw.setdefault('facecolors', self.color) kw.setdefault('linewidths', (0,)) collections.PolyCollection.__init__(self, [], offsets=self.XY, - transOffset=ax.transData, **kw) + transOffset=ax.transData, + closed=False, + **kw) self.polykw = kw self.set_UVC(U, V, C) self._initialized = False @@ -420,7 +416,7 @@ self._init() if self._new_UV: verts = self._make_verts(self.U, self.V) - self.set_verts(verts) + self.set_verts(verts, closed=False) self._new_UV = False collections.PolyCollection.draw(self, renderer) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2008-09-05 13:15:26
|
Revision: 6068 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6068&view=rev Author: mdboom Date: 2008-09-05 13:15:20 +0000 (Fri, 05 Sep 2008) Log Message: ----------- Fix hatching in Postscript backend. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/backends/backend_ps.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-09-05 03:23:30 UTC (rev 6067) +++ trunk/matplotlib/CHANGELOG 2008-09-05 13:15:20 UTC (rev 6068) @@ -1,3 +1,5 @@ +2008-09-05 Fix hatching in PS backend - MGD + 2008-09-03 Fix log with base 2 - MGD 2008-09-01 Added support for bilinear interpolation in Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2008-09-05 03:23:30 UTC (rev 6067) +++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2008-09-05 13:15:20 UTC (rev 6068) @@ -800,10 +800,6 @@ write(ps.strip()) write("\n") - hatch = gc.get_hatch() - if hatch: - self.set_hatch(hatch) - if fill: if stroke: write("gsave\n") @@ -812,6 +808,11 @@ else: self.set_color(store=0, *rgbFace[:3]) write("fill\n") + + hatch = gc.get_hatch() + if hatch: + self.set_hatch(hatch) + if stroke: write("stroke\n") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2008-09-06 21:37:58
|
Revision: 6071 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6071&view=rev Author: efiring Date: 2008-09-06 21:37:53 +0000 (Sat, 06 Sep 2008) Log Message: ----------- Add star marker to Line2D and plot Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/examples/pylab_examples/line_styles.py trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/lines.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-09-05 15:37:01 UTC (rev 6070) +++ trunk/matplotlib/CHANGELOG 2008-09-06 21:37:53 UTC (rev 6071) @@ -1,3 +1,5 @@ +2008-09-06 Added 5-point star marker to plot command - EF + 2008-09-05 Fix hatching in PS backend - MGD 2008-09-03 Fix log with base 2 - MGD Modified: trunk/matplotlib/examples/pylab_examples/line_styles.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/line_styles.py 2008-09-05 15:37:01 UTC (rev 6070) +++ trunk/matplotlib/examples/pylab_examples/line_styles.py 2008-09-06 21:37:53 UTC (rev 6071) @@ -1,26 +1,36 @@ #!/usr/bin/env python -from pylab import * +# This should probably be replaced with a demo that shows all +# line and marker types in a single panel, with labels. -t = arange(0.0, 3.0, 0.05) -s = sin(2*pi*t) -styles = ('-', '--', ':', '.', 'o', '^', 'v', '<', '>', 's', '+') +import matplotlib.pyplot as plt +from matplotlib.lines import Line2D +import numpy as np + +t = np.arange(0.0, 1.0, 0.1) +s = np.sin(2*np.pi*t) +linestyles = ['_', '-', '--', ':'] +markers = [] +for m in Line2D.markers: + try: + if len(m) == 1 and m != ' ': + markers.append(m) + except TypeError: + pass + +styles = linestyles + markers + colors = ('b', 'g', 'r', 'c', 'm', 'y', 'k') axisNum = 0 for row in range(5): - for col in range(4): - s = sin(2*pi*t) + for col in range(5): axisNum += 1 - subplot(5,4,axisNum) + ax = plt.subplot(5, 5, axisNum) style = styles[axisNum % len(styles) ] color = colors[axisNum % len(colors) ] - plot(t,s, style + color) - # turn off the ticklabels if not first row or first col - if not gca().is_first_col(): - setp(gca(), 'yticklabels', []) - if not gca().is_last_row(): - setp(gca(), 'xticklabels', []) + plt.plot(t,s, style + color, markersize=10) + ax.set_yticklabels([]) + ax.set_xticklabels([]) -#savefig('line_styles', dpi=300) -show() +plt.show() Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-09-05 15:37:01 UTC (rev 6070) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-09-06 21:37:53 UTC (rev 6071) @@ -3030,6 +3030,7 @@ > # triangle right symbols s # square symbols + # plus symbols + * # star symbols x # cross symbols D # diamond symbols d # thin diamond symbols Modified: trunk/matplotlib/lib/matplotlib/lines.py =================================================================== --- trunk/matplotlib/lib/matplotlib/lines.py 2008-09-05 15:37:01 UTC (rev 6070) +++ trunk/matplotlib/lib/matplotlib/lines.py 2008-09-06 21:37:53 UTC (rev 6071) @@ -99,6 +99,7 @@ '4' : '_draw_tri_right', 's' : '_draw_square', 'p' : '_draw_pentagon', + '*' : '_draw_star', 'h' : '_draw_hexagon1', 'H' : '_draw_hexagon2', '+' : '_draw_plus', @@ -120,7 +121,8 @@ '' : '_draw_nothing', } - filled_markers = ('o', '^', 'v', '<', '>', 's', 'd', 'D', 'h', 'H', 'p') + filled_markers = ('o', '^', 'v', '<', '>', + 's', 'd', 'D', 'h', 'H', 'p', '*') zorder = 2 validCap = ('butt', 'round', 'projecting') @@ -573,7 +575,7 @@ """ Set the line marker - ACCEPTS: [ '+' | ',' | '.' | '1' | '2' | '3' | '4' + ACCEPTS: [ '+' | '*' | ',' | '.' | '1' | '2' | '3' | '4' | '<' | '>' | 'D' | 'H' | '^' | '_' | 'd' | 'h' | 'o' | 'p' | 's' | 'v' | 'x' | '|' | TICKUP | TICKDOWN | TICKLEFT | TICKRIGHT @@ -815,7 +817,15 @@ renderer.draw_markers(gc, Path.unit_regular_polygon(5), transform, path, path_trans, rgbFace) + def _draw_star(self, renderer, gc, path, path_trans): + offset = 0.5 * renderer.points_to_pixels(self._markersize) + transform = Affine2D().scale(offset) + rgbFace = self._get_rgb_face() + _starpath = Path.unit_regular_star(5, innerCircle=0.381966) + renderer.draw_markers(gc, _starpath, transform, + path, path_trans, rgbFace) + def _draw_hexagon1(self, renderer, gc, path, path_trans): offset = 0.5 * renderer.points_to_pixels(self._markersize) transform = Affine2D().scale(offset) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |