Revision: 3929 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3929&view=rev Author: mdboom Date: 2007-10-08 11:15:05 -0700 (Mon, 08 Oct 2007)
Log Message: ----------- Merged revisions 3925-3928 via svnmerge from http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib ........ r3926 | efiring | 2007-10-05 18:11:32 -0400 (Fri, 05 Oct 2007) | 2 lines Fixed numpification bug in pcolor argument handling ........ r3927 | mdboom | 2007-10-08 08:45:23 -0400 (Mon, 08 Oct 2007) | 2 lines Save image resolution in the PNG file. ........ Modified Paths: -------------- branches/transforms/lib/matplotlib/axes.py branches/transforms/lib/matplotlib/backends/backend_agg.py branches/transforms/lib/matplotlib/backends/backend_gtkagg.py branches/transforms/src/_backend_agg.cpp Property Changed: ---------------- branches/transforms/ Property changes on: branches/transforms ___________________________________________________________________ Name: svnmerge-integrated - /trunk/matplotlib:1-3924 + /trunk/matplotlib:1-3928 Modified: branches/transforms/lib/matplotlib/axes.py =================================================================== --- branches/transforms/lib/matplotlib/axes.py 2007-10-08 18:10:11 UTC (rev 3928) +++ branches/transforms/lib/matplotlib/axes.py 2007-10-08 18:15:05 UTC (rev 3929) @@ -4390,7 +4390,30 @@ return im + def _pcolorargs(self, funcname, *args): + if len(args)==1: + C = args[0] + numRows, numCols = C.shape + X, Y = npy.meshgrid(npy.arange(numCols+1), npy.arange(numRows+1) ) + elif len(args)==3: + X, Y, C = args + else: + raise TypeError( + 'Illegal arguments to %s; see help(%s)' % (funcname, funcname)) + Nx = X.shape[-1] + Ny = Y.shape[0] + if len(X.shape) <> 2 or X.shape[0] == 1: + x = X.reshape(1,Nx) + X = x.repeat(Ny, axis=0) + if len(Y.shape) <> 2 or Y.shape[1] == 1: + y = Y.reshape(Ny, 1) + Y = y.repeat(Nx, axis=1) + if X.shape != Y.shape: + raise TypeError( + 'Incompatible X, Y inputs to %s; see help(%s)' % (funcname, funcname)) + return X, Y, C + def pcolor(self, *args, **kwargs): """ pcolor(*args, **kwargs): pseudocolor plot of a 2-D array @@ -4502,25 +4525,9 @@ vmax = kwargs.pop('vmax', None) shading = kwargs.pop('shading', 'flat') - if len(args)==1: - C = args[0] - numRows, numCols = C.shape - X, Y = npy.meshgrid(npy.arange(numCols+1), npy.arange(numRows+1) ) - elif len(args)==3: - X, Y, C = args - numRows, numCols = C.shape - else: - raise TypeError, 'Illegal arguments to pcolor; see help(pcolor)' + X, Y, C = self._pcolorargs('pcolor', *args) + Ny, Nx = X.shape - Nx = X.shape[-1] - Ny = Y.shape[0] - if len(X.shape) <> 2 or X.shape[0] == 1: - X = X.ravel().resize((Ny, Nx)) - if len(Y.shape) <> 2 or Y.shape[1] == 1: - Y = Y.ravel().resize((Nx, Ny)).T - - - # convert to MA, if necessary. C = ma.asarray(C) X = ma.asarray(X) @@ -4655,23 +4662,9 @@ shading = kwargs.pop('shading', 'flat') edgecolors = kwargs.pop('edgecolors', 'None') - if len(args)==1: - C = args[0] - numRows, numCols = C.shape - X, Y = npy.meshgrid(npy.arange(numCols+1), npy.arange(numRows+1) ) - elif len(args)==3: - X, Y, C = args - numRows, numCols = C.shape - else: - raise TypeError, 'Illegal arguments to pcolormesh; see help(pcolormesh)' + X, Y, C = self._pcolorargs('pcolormesh', *args) + Ny, Nx = X.shape - Nx = X.shape[-1] - Ny = Y.shape[0] - if len(X.shape) <> 2 or X.shape[0] == 1: - X = X.ravel().resize((Ny, Nx)) - if len(Y.shape) <> 2 or Y.shape[1] == 1: - Y = Y.ravel().resize((Nx, Ny)).T - # convert to one dimensional arrays C = ma.ravel(C[0:Ny-1, 0:Nx-1]) # data point in each cell is value at lower left corner X = X.ravel() Modified: branches/transforms/lib/matplotlib/backends/backend_agg.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_agg.py 2007-10-08 18:10:11 UTC (rev 3928) +++ branches/transforms/lib/matplotlib/backends/backend_agg.py 2007-10-08 18:15:05 UTC (rev 3929) @@ -387,5 +387,5 @@ def print_png(self, filename, *args, **kwargs): self.draw() - self.get_renderer()._renderer.write_png(str(filename)) + self.get_renderer()._renderer.write_png(str(filename), self.figure.dpi.get()) Modified: branches/transforms/lib/matplotlib/backends/backend_gtkagg.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_gtkagg.py 2007-10-08 18:10:11 UTC (rev 3928) +++ branches/transforms/lib/matplotlib/backends/backend_gtkagg.py 2007-10-08 18:15:05 UTC (rev 3929) @@ -97,6 +97,8 @@ 0, 0, 0, 0, w, h) if DEBUG: print 'FigureCanvasGTKAgg.done' + def print_png(self, filename, *args, **kwargs): + return FigureCanvasAgg.print_png(self, filename, *args, **kwargs) """\ Traceback (most recent call last): Modified: branches/transforms/src/_backend_agg.cpp =================================================================== --- branches/transforms/src/_backend_agg.cpp 2007-10-08 18:10:11 UTC (rev 3928) +++ branches/transforms/src/_backend_agg.cpp 2007-10-08 18:15:05 UTC (rev 3929) @@ -1072,7 +1072,7 @@ { _VERBOSE("RendererAgg::write_png"); - args.verify_length(1); + args.verify_length(1, 2); FILE *fp; Py::Object o = Py::Object(args[0]); @@ -1133,6 +1133,13 @@ width, height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + // Save the dpi of the image in the file + if (args.size() == 2) { + double dpi = Py::Float(args[1]); + size_t dots_per_meter = (size_t)(dpi / (2.54 / 100.0)); + png_set_pHYs(png_ptr, info_ptr, dots_per_meter, dots_per_meter, PNG_RESOLUTION_METER); + } // this a a color image! sig_bit.gray = 0; @@ -1718,7 +1725,7 @@ add_varargs_method("write_rgba", &RendererAgg::write_rgba, "write_rgba(fname)"); add_varargs_method("write_png", &RendererAgg::write_png, - "write_png(fname)"); + "write_png(fname, dpi=None)"); add_varargs_method("tostring_rgb", &RendererAgg::tostring_rgb, "s = tostring_rgb()"); add_varargs_method("tostring_argb", &RendererAgg::tostring_argb, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins