You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(115) |
Aug
(120) |
Sep
(137) |
Oct
(170) |
Nov
(461) |
Dec
(263) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(120) |
Feb
(74) |
Mar
(35) |
Apr
(74) |
May
(245) |
Jun
(356) |
Jul
(240) |
Aug
(115) |
Sep
(78) |
Oct
(225) |
Nov
(98) |
Dec
(271) |
2009 |
Jan
(132) |
Feb
(84) |
Mar
(74) |
Apr
(56) |
May
(90) |
Jun
(79) |
Jul
(83) |
Aug
(296) |
Sep
(214) |
Oct
(76) |
Nov
(82) |
Dec
(66) |
2010 |
Jan
(46) |
Feb
(58) |
Mar
(51) |
Apr
(77) |
May
(58) |
Jun
(126) |
Jul
(128) |
Aug
(64) |
Sep
(50) |
Oct
(44) |
Nov
(48) |
Dec
(54) |
2011 |
Jan
(68) |
Feb
(52) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
|
|
|
|
|
|
1
(4) |
2
(9) |
3
(23) |
4
(34) |
5
(31) |
6
(25) |
7
(10) |
8
(7) |
9
(1) |
10
(18) |
11
(3) |
12
(18) |
13
(13) |
14
(6) |
15
(9) |
16
(6) |
17
(10) |
18
(12) |
19
(1) |
20
(8) |
21
(5) |
22
|
23
|
24
|
25
|
26
(4) |
27
(2) |
28
(4) |
29
|
30
|
31
|
|
|
|
|
|
Revision: 4747 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4747&view=rev Author: astraw Date: 2007年12月16日 11:28:46 -0800 (2007年12月16日) Log Message: ----------- Add test for rec2csv and csv2rec roundtrip not losing precision. Added Paths: ----------- trunk/matplotlib/unit/mlab_unit.py Added: trunk/matplotlib/unit/mlab_unit.py =================================================================== --- trunk/matplotlib/unit/mlab_unit.py (rev 0) +++ trunk/matplotlib/unit/mlab_unit.py 2007年12月16日 19:28:46 UTC (rev 4747) @@ -0,0 +1,38 @@ +import unittest +import matplotlib.mlab as mlab +import numpy +import StringIO + +class TestMlab(unittest.TestCase): + def test_csv2rec_closefile(self): + # If passed a file-like object, rec2csv should not close it. + ra=numpy.rec.array([(123, 1197346475.0137341), (456, 123.456)], + dtype=[('a', '<i8'), ('b', '<f8')]) + fh = StringIO.StringIO() + mlab.rec2csv( ra, fh ) + self.failIf( fh.closed ) + + def test_csv2rec_roundtrip(self): + # Make sure double-precision floats pass through. + + # A bug in numpy (fixed in r4602) meant that numpy scalars + # lost precision when passing through repr(). csv2rec was + # affected by this. This test will only pass on numpy >= + # 1.0.5. + ra=numpy.rec.array([(123, 1197346475.0137341), (456, 123.456)], + dtype=[('a', '<i8'), ('b', '<f8')]) + rec2csv_closes_files = True + if rec2csv_closes_files: + fh = 'mlab_unit_tmp.csv' + else: + fh = StringIO.StringIO() + mlab.rec2csv( ra, fh ) + if not rec2csv_closes_files: + fh.seek(0) + ra2 = mlab.csv2rec(fh) + for name in ra.dtype.names: + #print name, repr(ra[name]), repr(ra2[name]) + self.failUnless( numpy.all(ra[name] == ra2[name]) ) # should not fail with numpy 1.0.5 + +if __name__=='__main__': + unittest.main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4746 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4746&view=rev Author: jswhit Date: 2007年12月16日 05:45:45 -0800 (2007年12月16日) Log Message: ----------- refine install instructions. Modified Paths: -------------- trunk/toolkits/basemap/README Modified: trunk/toolkits/basemap/README =================================================================== --- trunk/toolkits/basemap/README 2007年12月15日 21:33:38 UTC (rev 4745) +++ trunk/toolkits/basemap/README 2007年12月16日 13:45:45 UTC (rev 4746) @@ -87,12 +87,16 @@ 4) To test, cd to the examples directory and run 'python simpletest.py'. On linux, if you get an import error (with a message about not finding libgeos.so) you may need to set the LD_LIBRARY_PATH environment -to include $GEOS_DIR/lib. +to include $GEOS_DIR/lib. To run all the examples (except those that +have extra dependenices or require an internet connection), execute +'python run_all.py'. 5) if you want the full-resolution coastlines, download basemap-data-fullres-X.Y.Z.tar.gz (about 70 mb), untar it, cd into basemap-data-fullres-X.Y.Z and -run 'python setup-data.py install'. +run 'python setup-data.py install'. The fullres dataset does not +change with every basemap release, so you may need to look back +a couple of releases on the download page to find it. **Contact** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4745 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4745&view=rev Author: jdh2358 Date: 2007年12月15日 13:33:38 -0800 (2007年12月15日) Log Message: ----------- changed %g to %r for rec2csv Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/mlab.py trunk/matplotlib/lib/matplotlib/mpl-data/matplotlib.conf.template Modified: trunk/matplotlib/lib/matplotlib/mlab.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mlab.py 2007年12月15日 20:27:51 UTC (rev 4744) +++ trunk/matplotlib/lib/matplotlib/mlab.py 2007年12月15日 21:33:38 UTC (rev 4745) @@ -2233,12 +2233,12 @@ return self.toval(x) def toval(self, x): - return str(x) + return repr(x) class FormatString(FormatObj): def tostr(self, x): - return '"%s"'%self.toval(x) + return '"%r"'%self.toval(x) class FormatFormatStr(FormatObj): @@ -2317,7 +2317,7 @@ format = copy.deepcopy(format) if isinstance(format, FormatFloat): format.scale = 1. # override scaling for storage - format.fmt = '%g' # maximal precision + format.fmt = '%r' return format def rec2csv(r, fname, delimiter=',', formatd=None): Modified: trunk/matplotlib/lib/matplotlib/mpl-data/matplotlib.conf.template =================================================================== --- trunk/matplotlib/lib/matplotlib/mpl-data/matplotlib.conf.template 2007年12月15日 20:27:51 UTC (rev 4744) +++ trunk/matplotlib/lib/matplotlib/mpl-data/matplotlib.conf.template 2007年12月15日 21:33:38 UTC (rev 4745) @@ -3,32 +3,32 @@ # This is a sample matplotlib configuration file. It should be placed # in HOME/.matplotlib/matplotlibrc (unix/linux like systems) and # C:\Documents and Settings\yourname\.matplotlib (win32 systems) -# +# # By default, the installer will overwrite the existing file in the install # path, so if you want to preserve yours, please move it to your HOME dir and # set the environment variable if necessary. -# +# # This file is best viewed in a editor which supports ini or conf mode syntax # highlighting. -# +# # Blank lines, or lines starting with a comment symbol, are ignored, # as are trailing comments. Other lines must have the format -# +# # key = val optional comment -# +# # val should be valid python syntax, just as you would use when setting # properties using rcParams. This should become more obvious by inspecting # the default values listed herein. -# +# # Colors: for the color values below, you can either use # - a matplotlib color string, such as r | k | b # - an rgb tuple, such as (1.0, 0.5, 0.0) # - a hex string, such as #ff00ff or ff00ff # - a scalar grayscale intensity such as 0.75 # - a legal html color name, eg red | blue | darkslategray -# +# # Interactivity: see http://matplotlib.sourceforge.net/interactive.html. -# +# # ### CONFIGURATION BEGINS HERE ### # a value of type 'str' @@ -42,7 +42,7 @@ # 'Africa/Abidjan' or 'Africa/Accra' or 'Africa/Addis_Ababa' or # 'Africa/Algiers' or 'Africa/Asmara' or 'Africa/Asmera' or 'Africa/Bamako' or # 'Africa/Bangui' or 'Africa/Banjul' or 'Africa/Bissau' or 'Africa/Blantyre' -# <...snipped 156 lines...> +# <...snipped 156 lines...> # 'US/Michigan' or 'US/Mountain' or 'US/Pacific' or 'US/Pacific-New' or # 'US/Samoa' or 'UTC' or 'Universal' or 'W-SU' or 'WET' or 'Zulu' or # 'posixrules' @@ -108,10 +108,10 @@ [[ps]] # 3 or 42 fonttype = 3 - # 'auto' or 'letter' or 'legal' or 'ledger' or 'A0' or 'A1' or 'A2' or - # 'A3' or 'A4' or 'A5' or 'A6' or 'A7' or 'A8' or 'A9' or 'A10' or - # 'B0' or 'B1' or 'B2' or 'B3' or 'B4' or 'B5' or 'B6' or 'B7' or 'B8' - # or 'B9' or 'B10' + # auto | letter | legal | ledger | A0 | A1 | A2 | + # A3 | A4 | A5 | A6 | A7 | A8 | A9 | A10 | + # B0 | B1 | B2 | B3 | B4 | B5 | B6 | B7 | B8 + # | B9 | B10 papersize = 'letter' # a value of type 'bool' useafm = False @@ -216,7 +216,7 @@ # 'Accent' or 'Accent_r' or 'Blues' or 'Blues_r' or 'BrBG' or 'BrBG_r' or # 'BuGn' or 'BuGn_r' or 'BuPu' or 'BuPu_r' or 'Dark2' or 'Dark2_r' or # 'GnBu' or 'GnBu_r' or 'Greens' or 'Greens_r' or 'Greys' or 'Greys_r' or - # <...snipped 16 lines...> + # <...snipped 16 lines...> # 'pink_r' or 'prism' or 'prism_r' or 'spectral' or 'spectral_r' or # 'spring' or 'spring_r' or 'summer' or 'summer_r' or 'winter' or # 'winter_r' @@ -404,4 +404,4 @@ # a value of type 'float' pad = 4.0 # a value of type 'float' - size = 2.0 \ No newline at end of file + size = 2.0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4744 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4744&view=rev Author: jswhit Date: 2007年12月15日 12:27:51 -0800 (2007年12月15日) Log Message: ----------- don't use setuptools Modified Paths: -------------- trunk/toolkits/basemap/lib/matplotlib/toolkits/__init__.py Modified: trunk/toolkits/basemap/lib/matplotlib/toolkits/__init__.py =================================================================== --- trunk/toolkits/basemap/lib/matplotlib/toolkits/__init__.py 2007年12月15日 19:31:32 UTC (rev 4743) +++ trunk/toolkits/basemap/lib/matplotlib/toolkits/__init__.py 2007年12月15日 20:27:51 UTC (rev 4744) @@ -1,4 +1,4 @@ -try: - __import__('pkg_resources').declare_namespace(__name__) -except ImportError: - pass # must not have setuptools +#try: +# __import__('pkg_resources').declare_namespace(__name__) +#except ImportError: +# pass # must not have setuptools This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4743 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4743&view=rev Author: jswhit Date: 2007年12月15日 11:31:32 -0800 (2007年12月15日) Log Message: ----------- add setupegg-data.py Modified Paths: -------------- trunk/toolkits/basemap/MANIFEST-data Modified: trunk/toolkits/basemap/MANIFEST-data =================================================================== --- trunk/toolkits/basemap/MANIFEST-data 2007年12月15日 19:10:31 UTC (rev 4742) +++ trunk/toolkits/basemap/MANIFEST-data 2007年12月15日 19:31:32 UTC (rev 4743) @@ -2,6 +2,7 @@ LICENSE_data README setup-data.py +setupegg-data.py lib/matplotlib/toolkits/basemap/data/__init__.py lib/matplotlib/toolkits/basemap/data/countries_f.dat lib/matplotlib/toolkits/basemap/data/countriesmeta_f.dat This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4742 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4742&view=rev Author: jswhit Date: 2007年12月15日 11:10:31 -0800 (2007年12月15日) Log Message: ----------- new file Added Paths: ----------- trunk/toolkits/basemap/setupegg-data.py Added: trunk/toolkits/basemap/setupegg-data.py =================================================================== --- trunk/toolkits/basemap/setupegg-data.py (rev 0) +++ trunk/toolkits/basemap/setupegg-data.py 2007年12月15日 19:10:31 UTC (rev 4742) @@ -0,0 +1,6 @@ +""" +Poor man's setuptools script... +""" + +from setuptools import setup +execfile('setup-data.py') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4741 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4741&view=rev Author: jswhit Date: 2007年12月15日 11:02:17 -0800 (2007年12月15日) Log Message: ----------- add LD_LIBRARY_PATH to instructions. Modified Paths: -------------- trunk/toolkits/basemap/README Modified: trunk/toolkits/basemap/README =================================================================== --- trunk/toolkits/basemap/README 2007年12月15日 18:18:03 UTC (rev 4740) +++ trunk/toolkits/basemap/README 2007年12月15日 19:02:17 UTC (rev 4741) @@ -82,9 +82,14 @@ > make; make install 3) cd back to the top level basemap directory (basemap-X.Y.Z) and -run the usual 'python setup.py install'. +run the usual 'python setup.py install'. -4) if you want the full-resolution coastlines, download +4) To test, cd to the examples directory and run 'python simpletest.py'. +On linux, if you get an import error (with a message about not +finding libgeos.so) you may need to set the LD_LIBRARY_PATH environment +to include $GEOS_DIR/lib. + +5) if you want the full-resolution coastlines, download basemap-data-fullres-X.Y.Z.tar.gz (about 70 mb), untar it, cd into basemap-data-fullres-X.Y.Z and run 'python setup-data.py install'. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4740 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4740&view=rev Author: jswhit Date: 2007年12月15日 10:18:03 -0800 (2007年12月15日) Log Message: ----------- don't use namespace packages Modified Paths: -------------- trunk/toolkits/basemap/lib/dap/__init__.py trunk/toolkits/basemap/lib/matplotlib/__init__.py Modified: trunk/toolkits/basemap/lib/dap/__init__.py =================================================================== --- trunk/toolkits/basemap/lib/dap/__init__.py 2007年12月15日 13:39:05 UTC (rev 4739) +++ trunk/toolkits/basemap/lib/dap/__init__.py 2007年12月15日 18:18:03 UTC (rev 4740) @@ -9,4 +9,7 @@ For more information about the protocol, please check http://opendap.org. """ -__import__('pkg_resources').declare_namespace(__name__) +#try: +# __import__('pkg_resources').declare_namespace(__name__) +#except ImportError: +# pass # must not have setuptools Modified: trunk/toolkits/basemap/lib/matplotlib/__init__.py =================================================================== --- trunk/toolkits/basemap/lib/matplotlib/__init__.py 2007年12月15日 13:39:05 UTC (rev 4739) +++ trunk/toolkits/basemap/lib/matplotlib/__init__.py 2007年12月15日 18:18:03 UTC (rev 4740) @@ -1,4 +1,4 @@ -try: - __import__('pkg_resources').declare_namespace(__name__) -except ImportError: - pass # must not have setuptools +#try: +# __import__('pkg_resources').declare_namespace(__name__) +#except ImportError: +# pass # must not have setuptools This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4739 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4739&view=rev Author: jswhit Date: 2007年12月15日 05:39:05 -0800 (2007年12月15日) Log Message: ----------- add title Modified Paths: -------------- trunk/toolkits/basemap/examples/plotsst.py Modified: trunk/toolkits/basemap/examples/plotsst.py =================================================================== --- trunk/toolkits/basemap/examples/plotsst.py 2007年12月15日 02:33:26 UTC (rev 4738) +++ trunk/toolkits/basemap/examples/plotsst.py 2007年12月15日 13:39:05 UTC (rev 4739) @@ -3,7 +3,8 @@ # read in sea-surface temperature and ice data # can be a local file, a URL for a remote opendap dataset, # or (if PyNIO is installed) a GRIB or HDF file. -ncfile = NetCDFFile('http://nomads.ncdc.noaa.gov:8085/thredds/dodsC/oisst/2007/AVHRR/sst4-navy-eot.20071213.nc') +date = '20071214' +ncfile = NetCDFFile('http://nomads.ncdc.noaa.gov:8085/thredds/dodsC/oisst/'+date[0:4]+'/AVHRR/sst4-navy-eot.'+date+'.nc') # read sst. Will automatically create a masked array using # missing_value variable attribute. sst = ncfile.variables['sst'][:] @@ -25,6 +26,7 @@ # create Basemap instance for mollweide projection. # coastlines not used, so resolution set to None to skip # continent processing (this speeds things up a bit) +#m = Basemap(projection='ortho',lon_0=-110,lat_0=20,resolution=None) m = Basemap(projection='moll',lon_0=lons.mean(),lat_0=0,resolution=None) # compute map projection coordinates of grid. x, y = m(*numpy.meshgrid(lons, lats)) @@ -40,5 +42,6 @@ m.drawmeridians(numpy.arange(0.,420.,60.)) # draw horizontal colorbar. pylab.colorbar(im1,orientation='horizontal') -# display the plot. +# display the plot with a title. +pylab.title('SST and ICE analysis for %s'%date) pylab.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4738 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4738&view=rev Author: jswhit Date: 2007年12月14日 18:33:26 -0800 (2007年12月14日) Log Message: ----------- remove setuptools requirement. Modified Paths: -------------- trunk/toolkits/basemap/examples/plotsst.py trunk/toolkits/basemap/setup-data.py trunk/toolkits/basemap/setup.py Modified: trunk/toolkits/basemap/examples/plotsst.py =================================================================== --- trunk/toolkits/basemap/examples/plotsst.py 2007年12月15日 00:12:13 UTC (rev 4737) +++ trunk/toolkits/basemap/examples/plotsst.py 2007年12月15日 02:33:26 UTC (rev 4738) @@ -3,7 +3,7 @@ # read in sea-surface temperature and ice data # can be a local file, a URL for a remote opendap dataset, # or (if PyNIO is installed) a GRIB or HDF file. -ncfile = NetCDFFile('http://nomads.ncdc.noaa.gov:8085/thredds/dodsC/oisst/2007/AVHRR/sst4-navy-eot.20071201.nc') +ncfile = NetCDFFile('http://nomads.ncdc.noaa.gov:8085/thredds/dodsC/oisst/2007/AVHRR/sst4-navy-eot.20071213.nc') # read sst. Will automatically create a masked array using # missing_value variable attribute. sst = ncfile.variables['sst'][:] @@ -33,7 +33,7 @@ # missing values over land will show up this color. m.drawmapboundary(fill_color='0.3') # plot ice, then with pcolor -im1 = m.pcolor(x,y,sst,shading='flat',cmap=pylab.cm.gist_ncar) +im1 = m.pcolor(x,y,sst,shading='flat',cmap=pylab.cm.jet) im2 = m.pcolor(x,y,ice,shading='flat',cmap=pylab.cm.gist_gray) # draw parallels and meridians, but don't bother labelling them. m.drawparallels(numpy.arange(-90.,120.,30.)) Modified: trunk/toolkits/basemap/setup-data.py =================================================================== --- trunk/toolkits/basemap/setup-data.py 2007年12月15日 00:12:13 UTC (rev 4737) +++ trunk/toolkits/basemap/setup-data.py 2007年12月15日 02:33:26 UTC (rev 4738) @@ -1,13 +1,4 @@ import sys, glob, os -if 'setuptools' in sys.modules: -# Are we running with setuptools? -# if so, need to specify all the packages in heirarchy - additional_params = {'namespace_packages' : ['matplotlib.toolkits']} - packages.extend(['matplotlib', 'matplotlib.toolkits']) - setup = setuptools.setup -else: - additional_params = {} - from distutils.core import setup packages = ['matplotlib.toolkits.basemap.data'] package_dirs = {'':'lib'} boundaryfiles = glob.glob("lib/matplotlib/toolkits/basemap/data/*_f.dat") Modified: trunk/toolkits/basemap/setup.py =================================================================== --- trunk/toolkits/basemap/setup.py 2007年12月15日 00:12:13 UTC (rev 4737) +++ trunk/toolkits/basemap/setup.py 2007年12月15日 02:33:26 UTC (rev 4738) @@ -1,16 +1,5 @@ import sys, glob, os from distutils.core import setup -major, minor1, minor2, s, tmp = sys.version_info -if major==2 and minor1<=3: - # setuptools monkeypatches distutils.core.Distribution to support - # package_data - try: import setuptools - except ImportError: - raise SystemExit(""" -matplotlib requires setuptools for installation. Please download -http://peak.telecommunity.com/dist/ez_setup.py and run it (as su if -you are doing a system wide install) to install the proper version of -setuptools for your system""") from distutils.core import Extension from distutils.util import convert_path import numpy This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4737 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4737&view=rev Author: jswhit Date: 2007年12月14日 16:12:13 -0800 (2007年12月14日) Log Message: ----------- add ice to plot. Modified Paths: -------------- trunk/toolkits/basemap/examples/plotsst.py Modified: trunk/toolkits/basemap/examples/plotsst.py =================================================================== --- trunk/toolkits/basemap/examples/plotsst.py 2007年12月14日 21:16:38 UTC (rev 4736) +++ trunk/toolkits/basemap/examples/plotsst.py 2007年12月15日 00:12:13 UTC (rev 4737) @@ -1,12 +1,14 @@ from matplotlib.toolkits.basemap import Basemap, NetCDFFile import pylab, numpy -# read in sea-surface temperature data +# read in sea-surface temperature and ice data # can be a local file, a URL for a remote opendap dataset, # or (if PyNIO is installed) a GRIB or HDF file. ncfile = NetCDFFile('http://nomads.ncdc.noaa.gov:8085/thredds/dodsC/oisst/2007/AVHRR/sst4-navy-eot.20071201.nc') # read sst. Will automatically create a masked array using # missing_value variable attribute. sst = ncfile.variables['sst'][:] +# read ice. +ice = ncfile.variables['ice'][:] # read lats and lons (representing centers of grid boxes). lats = ncfile.variables['lat'][:] lons = ncfile.variables['lon'][:] @@ -30,12 +32,13 @@ # color background of map projection region. # missing values over land will show up this color. m.drawmapboundary(fill_color='0.3') -# plot with pcolor -im = m.pcolor(x,y,sst,shading='flat',cmap=pylab.cm.gist_ncar) +# plot ice, then with pcolor +im1 = m.pcolor(x,y,sst,shading='flat',cmap=pylab.cm.gist_ncar) +im2 = m.pcolor(x,y,ice,shading='flat',cmap=pylab.cm.gist_gray) # draw parallels and meridians, but don't bother labelling them. m.drawparallels(numpy.arange(-90.,120.,30.)) m.drawmeridians(numpy.arange(0.,420.,60.)) # draw horizontal colorbar. -pylab.colorbar(orientation='horizontal') +pylab.colorbar(im1,orientation='horizontal') # display the plot. pylab.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4736 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4736&view=rev Author: jswhit Date: 2007年12月14日 13:16:38 -0800 (2007年12月14日) Log Message: ----------- took out namespace package stuff (because I don't understand it, and it apparently is not needed). Modified Paths: -------------- trunk/toolkits/basemap/setup.py Modified: trunk/toolkits/basemap/setup.py =================================================================== --- trunk/toolkits/basemap/setup.py 2007年12月14日 20:12:18 UTC (rev 4735) +++ trunk/toolkits/basemap/setup.py 2007年12月14日 21:16:38 UTC (rev 4736) @@ -1,4 +1,5 @@ import sys, glob, os +from distutils.core import setup major, minor1, minor2, s, tmp = sys.version_info if major==2 and minor1<=3: # setuptools monkeypatches distutils.core.Distribution to support @@ -132,16 +133,6 @@ packages = packages + ['httplib2'] package_dirs['httlib2'] = os.path.join('lib','httplib2') -if 'setuptools' in sys.modules: -# Are we running with setuptools? -# if so, need to specify all the packages in heirarchy - additional_params = {'namespace_packages' : ['matplotlib.toolkits']} - packages.extend(['matplotlib', 'matplotlib.toolkits']) - setup = setuptools.setup -else: - additional_params = {} - from distutils.core import setup - # Specify all the required mpl data pyproj_datafiles = ['data/epsg', 'data/esri', 'data/esri.extra', 'data/GL27', 'data/nad.lst', 'data/nad27', 'data/nad83', 'data/ntv2_out.dist', 'data/other.extra', 'data/pj_out27.dist', 'data/pj_out83.dist', 'data/proj_def.dat', 'data/README', 'data/td_out.dist', 'data/test27', 'data/test83', 'data/testntv2', 'data/testvarious', 'data/world'] boundaryfiles = [] @@ -175,6 +166,5 @@ packages = packages, package_dir = package_dirs, ext_modules = extensions, - package_data = package_data, - **additional_params + package_data = package_data ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4735 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4735&view=rev Author: mdboom Date: 2007年12月14日 12:12:18 -0800 (2007年12月14日) Log Message: ----------- Merged revisions 4726-4734 via svnmerge from http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib ........ r4726 | jdh2358 | 2007年12月13日 13:17:33 -0500 (2007年12月13日) | 2 lines removed namespace declaration from toolkits __init__ ........ r4728 | mdboom | 2007年12月13日 13:30:45 -0500 (2007年12月13日) | 2 lines Update API_CHANGES and CHANGELOG for stuff since 0.91.1 ........ r4730 | jdh2358 | 2007年12月13日 17:40:33 -0500 (2007年12月13日) | 2 lines noted rec2gtk and recexcel moves in CHANGELOG ........ Modified Paths: -------------- branches/transforms/API_CHANGES branches/transforms/CHANGELOG branches/transforms/lib/matplotlib/toolkits/__init__.py Property Changed: ---------------- branches/transforms/ Property changes on: branches/transforms ___________________________________________________________________ Name: svnmerge-integrated - /trunk/matplotlib:1-4725 + /trunk/matplotlib:1-4734 Modified: branches/transforms/API_CHANGES =================================================================== --- branches/transforms/API_CHANGES 2007年12月14日 20:08:22 UTC (rev 4734) +++ branches/transforms/API_CHANGES 2007年12月14日 20:12:18 UTC (rev 4735) @@ -169,6 +169,9 @@ END OF TRANSFORMS REFACTORING + A warning is issued when an image is drawn on log-scaled + axes, since it will not log-scale the image data. + Moved rec2gtk to matplotlib.toolkits.gtktools Moved rec2excel to matplotlib.toolkits.exceltools @@ -182,8 +185,6 @@ Changed cbook.is_file_like to cbook.is_writable_file_like and corrected behavior. - Moved mlab.csv2rec -> recutils.csv2rec - Added ax kwarg to pyplot.colorbar and Figure.colorbar so that one can specify the axes object from which space for the colorbar is to be taken, if one does not want to make the colorbar axes Modified: branches/transforms/CHANGELOG =================================================================== --- branches/transforms/CHANGELOG 2007年12月14日 20:08:22 UTC (rev 4734) +++ branches/transforms/CHANGELOG 2007年12月14日 20:12:18 UTC (rev 4735) @@ -1,9 +1,16 @@ -2007年12月10日 Fix SVG text rendering bug. +2007年12月13日 Moved rec2gtk to matplotlib.toolkits.gtktools and rec2excel + to matplotlib.toolkits.exceltools - JDH -2007年12月10日 Increase accuracy of circle and ellipse drawing by using an 8-piece - bezier approximation, rather than a 4-piece one. Fix PDF, SVG and - Cairo backends so they can draw paths (meaning ellipses as well). +2007年12月12日 Support alpha-blended text in the Agg and Svg backends - + MGD +2007年12月10日 Fix SVG text rendering bug. - MGD + +2007年12月10日 Increase accuracy of circle and ellipse drawing by using an + 8-piece bezier approximation, rather than a 4-piece one. + Fix PDF, SVG and Cairo backends so they can draw paths + (meaning ellipses as well). - MGD + 2007年12月07日 Issue a warning when drawing an image on a non-linear axis. - MGD 2007年12月06日 let widgets.Cursor initialize to the lower x and y bounds @@ -18,6 +25,10 @@ (This was a regression since 0.90 caused by the refactoring of font_manager.py) - MGD +2007年12月05日 Support arbitrary rotation of usetex text in Agg backend. - MGD + +2007年12月04日 Support '|' as a character in mathtext - MGD + =============================================================== 2007年11月27日 Released 0.91.1 at revision 4517 Modified: branches/transforms/lib/matplotlib/toolkits/__init__.py =================================================================== --- branches/transforms/lib/matplotlib/toolkits/__init__.py 2007年12月14日 20:08:22 UTC (rev 4734) +++ branches/transforms/lib/matplotlib/toolkits/__init__.py 2007年12月14日 20:12:18 UTC (rev 4735) @@ -1,4 +1,4 @@ -try: - __import__('pkg_resources').declare_namespace(__name__) -except ImportError: - pass # must not have setuptools +#try: +# __import__('pkg_resources').declare_namespace(__name__) +#except ImportError: +# pass # must not have setuptools This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4733 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4733&view=rev Author: mdboom Date: 2007年12月14日 12:07:59 -0800 (2007年12月14日) Log Message: ----------- First pass at symmetrical log plots. Expose xscale() and yscale() through pyplot. Modified Paths: -------------- branches/transforms/lib/matplotlib/axes.py branches/transforms/lib/matplotlib/pyplot.py branches/transforms/lib/matplotlib/scale.py branches/transforms/lib/matplotlib/ticker.py Added Paths: ----------- branches/transforms/examples/symlog_demo.py Added: branches/transforms/examples/symlog_demo.py =================================================================== --- branches/transforms/examples/symlog_demo.py (rev 0) +++ branches/transforms/examples/symlog_demo.py 2007年12月14日 20:07:59 UTC (rev 4733) @@ -0,0 +1,29 @@ +#!/usr/bin/env python +from pylab import * + +dt = 1.0 +x = arange(-50.0, 50.0, dt) +y = arange(0, 100.0, dt) + +subplot(311) +plot(x, y) +xscale('symlog') +ylabel('symlogx') +grid(True) +gca().xaxis.grid(True, which='minor') # minor grid on too + +subplot(312) +plot(y, x) +yscale('symlog') +ylabel('symlogy') + + +subplot(313) +plot(x, npy.sin(x / 3.0)) +xscale('symlog') +yscale('symlog') +grid(True) +ylabel('symlog both') + +savefig('log_demo') +show() Property changes on: branches/transforms/examples/symlog_demo.py ___________________________________________________________________ Name: svn:executable + * Modified: branches/transforms/lib/matplotlib/axes.py =================================================================== --- branches/transforms/lib/matplotlib/axes.py 2007年12月14日 16:28:34 UTC (rev 4732) +++ branches/transforms/lib/matplotlib/axes.py 2007年12月14日 20:07:59 UTC (rev 4733) @@ -741,8 +741,6 @@ self.xaxis.cla() self.yaxis.cla() - self.set_xscale('linear') - self.set_yscale('linear') self.ignore_existing_data_limits = True self.callbacks = cbook.CallbackRegistry(('xlim_changed', 'ylim_changed')) @@ -768,6 +766,8 @@ self.collections = [] # collection.Collection instances self._autoscaleon = True + self.set_xscale('linear') + self.set_yscale('linear') self.grid(self._gridOn) props = font_manager.FontProperties(size=rcParams['axes.titlesize']) @@ -1654,6 +1654,7 @@ ", ".join(mscale.get_scale_names())) return self.xaxis.get_scale() + # MGDTODO: Update docstring def set_xscale(self, value, **kwargs): """ SET_XSCALE(value) @@ -1673,6 +1674,7 @@ ACCEPTS: [%(scale)s] """ % {'scale': ' | '.join([repr(x) for x in mscale.get_scale_names()])} self.xaxis.set_scale(value, **kwargs) + self.autoscale_view() self._update_transScale() def get_xticks(self, minor=False): @@ -1833,6 +1835,7 @@ ACCEPTS: %(scale)s """ % {'scale': ' | '.join([repr(x) for x in mscale.get_scale_names()])} self.yaxis.set_scale(value, **kwargs) + self.autoscale_view() self._update_transScale() def get_yticks(self, minor=False): @@ -1992,6 +1995,7 @@ lim = self.viewLim.frozen(), trans = self.transData.frozen(), trans_inverse = self.transData.inverted().frozen(), + bbox = self.bbox.frozen(), x = x, y = y ) @@ -2044,9 +2048,11 @@ p = self._pan_start dx = x - p.x dy = y - p.y + if dx == 0 and dy == 0: + return if button == 1: dx, dy = format_deltas(key, dx, dy) - result = self.bbox.frozen().translated(-dx, -dy) \ + result = p.bbox.translated(-dx, -dy) \ .transformed(p.trans_inverse) elif button == 3: try: Modified: branches/transforms/lib/matplotlib/pyplot.py =================================================================== --- branches/transforms/lib/matplotlib/pyplot.py 2007年12月14日 16:28:34 UTC (rev 4732) +++ branches/transforms/lib/matplotlib/pyplot.py 2007年12月14日 20:07:59 UTC (rev 4733) @@ -12,6 +12,7 @@ from matplotlib.axes import Axes from matplotlib.projections import PolarAxes from matplotlib import mlab # for csv2rec in plotfile +from matplotlib.scale import get_scale_names from matplotlib import cm from matplotlib.cm import get_cmap @@ -726,8 +727,32 @@ return ret +# MGDTODO: Update docstring +def xscale(*args, **kwargs): + """ + SET_XSCALE(value) + Set the xscaling: %(scale)s + """ % {'scale': ' | '.join([repr(x) for x in get_scale_names()])} + ax = gca() + ret = ax.set_xscale(*args, **kwargs) + draw_if_interactive() + return ret + +# MGDTODO: Update docstring +def yscale(*args, **kwargs): + """ + SET_YSCALE(value) + + Set the yscaling: %(scale)s + """ % {'scale': ' | '.join([repr(x) for x in get_scale_names()])} + ax = gca() + ret = ax.set_yscale(*args, **kwargs) + draw_if_interactive() + return ret + + def xticks(*args, **kwargs): """ Set/Get the xlimits of the current ticklocs, labels Modified: branches/transforms/lib/matplotlib/scale.py =================================================================== --- branches/transforms/lib/matplotlib/scale.py 2007年12月14日 16:28:34 UTC (rev 4732) +++ branches/transforms/lib/matplotlib/scale.py 2007年12月14日 20:07:59 UTC (rev 4733) @@ -3,7 +3,7 @@ MaskedArray = ma.MaskedArray from ticker import NullFormatter, ScalarFormatter, LogFormatterMathtext -from ticker import NullLocator, LogLocator, AutoLocator +from ticker import NullLocator, LogLocator, AutoLocator, SymmetricalLogLocator from transforms import Transform, IdentityTransform class ScaleBase(object): @@ -12,10 +12,10 @@ def limit_range_for_scale(self, vmin, vmax, minpos): return vmin, vmax - + class LinearScale(ScaleBase): name = 'linear' - + def __init__(self, axis, **kwargs): pass @@ -24,7 +24,7 @@ axis.set_major_formatter(ScalarFormatter()) axis.set_minor_locator(NullLocator()) axis.set_minor_formatter(NullFormatter()) - + def get_transform(self): return IdentityTransform() @@ -33,7 +33,7 @@ if mask.any(): return ma.MaskedArray(a, mask=mask) return a - + class LogScale(ScaleBase): name = 'log' @@ -41,13 +41,14 @@ input_dims = 1 output_dims = 1 is_separable = True - + base = 10.0 + def transform(self, a): a = _mask_non_positives(a * 10.0) if isinstance(a, MaskedArray): return ma.log10(a) return npy.log10(a) - + def inverted(self): return LogScale.InvertedLog10Transform() @@ -55,7 +56,8 @@ input_dims = 1 output_dims = 1 is_separable = True - + base = 10.0 + def transform(self, a): return ma.power(10.0, a) / 10.0 @@ -66,13 +68,14 @@ input_dims = 1 output_dims = 1 is_separable = True - + base = 2.0 + def transform(self, a): a = _mask_non_positives(a * 2.0) if isinstance(a, MaskedArray): return ma.log2(a) return npy.log2(a) - + def inverted(self): return LogScale.InvertedLog2Transform() @@ -80,7 +83,8 @@ input_dims = 1 output_dims = 1 is_separable = True - + base = 2.0 + def transform(self, a): return ma.power(2.0, a) / 2.0 @@ -91,13 +95,14 @@ input_dims = 1 output_dims = 1 is_separable = True - + base = npy.e + def transform(self, a): a = _mask_non_positives(a * npy.e) if isinstance(a, MaskedArray): return ma.log(a) return npy.log(a) - + def inverted(self): return LogScale.InvertedNaturalLogTransform() @@ -105,54 +110,55 @@ input_dims = 1 output_dims = 1 is_separable = True - + base = npy.e + def transform(self, a): return ma.power(npy.e, a) / npy.e def inverted(self): return LogScale.Log2Transform() - + class LogTransform(Transform): input_dims = 1 output_dims = 1 is_separable = True - + def __init__(self, base): Transform.__init__(self) - self._base = base - + self.base = base + def transform(self, a): - a = _mask_non_positives(a * self._base) + a = _mask_non_positives(a * self.base) if isinstance(a, MaskedArray): - return ma.log10(a) / npy.log(self._base) - return npy.log(a) / npy.log(self._base) - + return ma.log(a) / npy.log(self.base) + return npy.log(a) / npy.log(self.base) + def inverted(self): - return LogScale.InvertedLogTransform(self._base) + return LogScale.InvertedLogTransform(self.base) class InvertedLogTransform(Transform): input_dims = 1 output_dims = 1 is_separable = True - + def __init__(self, base): Transform.__init__(self) - self._base = base + self.base = base def transform(self, a): - return ma.power(self._base, a) / self._base + return ma.power(self.base, a) / self.base def inverted(self): - return LogScale.LogTransform(self._base) + return LogScale.LogTransform(self.base) - + def __init__(self, axis, **kwargs): if axis.axis_name == 'x': base = kwargs.pop('basex', 10.0) - subs = kwargs.pop('subsx', []) + subs = kwargs.pop('subsx', None) else: base = kwargs.pop('basey', 10.0) - subs = kwargs.pop('subsy', []) + subs = kwargs.pop('subsy', None) if base == 10.0: self._transform = self.Log10Transform() @@ -163,25 +169,104 @@ else: self._transform = self.LogTransform(base) - self._base = base - self._subs = subs + self.base = base + self.subs = subs def set_default_locators_and_formatters(self, axis): - axis.set_major_locator(LogLocator(self._base)) - axis.set_major_formatter(LogFormatterMathtext(self._base)) - axis.set_minor_locator(LogLocator(self._base, self._subs)) + axis.set_major_locator(LogLocator(self.base)) + axis.set_major_formatter(LogFormatterMathtext(self.base)) + axis.set_minor_locator(LogLocator(self.base, self.subs)) axis.set_minor_formatter(NullFormatter()) - + def get_transform(self): return self._transform def limit_range_for_scale(self, vmin, vmax, minpos): return (vmin <= 0.0 and minpos or vmin, vmax <= 0.0 and minpos or vmax) - + +class SymmetricalLogScale(ScaleBase): + name = 'symlog' + + class SymmetricalLogTransform(Transform): + input_dims = 1 + output_dims = 1 + is_separable = True + + def __init__(self, base, linthresh): + Transform.__init__(self) + self.base = base + self.linthresh = linthresh + self._log_base = npy.log(base) + self._linadjust = (npy.log(linthresh) / self._log_base) / linthresh + + def transform(self, a): + sign = npy.sign(npy.asarray(a)) + masked = ma.masked_inside(a, -self.linthresh, self.linthresh, copy=False) + log = sign * ma.log(npy.abs(masked)) / self._log_base + if masked.mask.any(): + return npy.asarray(ma.where(masked.mask, + a * self._linadjust, + log)) + else: + return npy.asarray(log) + + def inverted(self): + return SymmetricalLogScale.InvertedSymmetricalLogTransform(self.base, self.linthresh) + + class InvertedSymmetricalLogTransform(Transform): + input_dims = 1 + output_dims = 1 + is_separable = True + + def __init__(self, base, linthresh): + Transform.__init__(self) + self.base = base + self.linthresh = linthresh + self._log_base = npy.log(base) + self._log_linthresh = npy.log(linthresh) / self._log_base + self._linadjust = linthresh / (npy.log(linthresh) / self._log_base) + + def transform(self, a): + return npy.where(a <= self._log_linthresh, + npy.where(a >= -self._log_linthresh, + a * self._linadjust, + -(npy.power(self.base, -a))), + npy.power(self.base, a)) + + def inverted(self): + return SymmetricalLogScale.SymmetricalLogTransform(self.base) + + def __init__(self, axis, **kwargs): + if axis.axis_name == 'x': + base = kwargs.pop('basex', 10.0) + linthresh = kwargs.pop('linthreshx', 2.0) + subs = kwargs.pop('subsx', None) + else: + base = kwargs.pop('basey', 10.0) + linthresh = kwargs.pop('linthreshy', 2.0) + subs = kwargs.pop('subsy', None) + + self._transform = self.SymmetricalLogTransform(base, linthresh) + + self.base = base + self.linthresh = linthresh + self.subs = subs + + def set_default_locators_and_formatters(self, axis): + axis.set_major_locator(SymmetricalLogLocator(self.get_transform())) + axis.set_major_formatter(LogFormatterMathtext(self.base)) + axis.set_minor_locator(SymmetricalLogLocator(self.get_transform(), self.subs)) + axis.set_minor_formatter(NullFormatter()) + + def get_transform(self): + return self._transform + + _scale_mapping = { - 'linear' : LinearScale, - 'log' : LogScale + 'linear' : LinearScale, + 'log' : LogScale, + 'symlog' : SymmetricalLogScale } def scale_factory(scale, axis, **kwargs): scale = scale.lower() @@ -190,7 +275,7 @@ if not _scale_mapping.has_key(scale): raise ValueError("Unknown scale type '%s'" % scale) - + return _scale_mapping[scale](axis, **kwargs) def get_scale_names(): Modified: branches/transforms/lib/matplotlib/ticker.py =================================================================== --- branches/transforms/lib/matplotlib/ticker.py 2007年12月14日 16:28:34 UTC (rev 4732) +++ branches/transforms/lib/matplotlib/ticker.py 2007年12月14日 20:07:59 UTC (rev 4733) @@ -131,14 +131,14 @@ def set_data_interval(self, vmin, vmax): self.dataLim.intervalx = vmin, vmax - + def set_axis(self, axis): self.axis = axis def create_dummy_axis(self): if self.axis is None: self.axis = self.DummyAxis() - + def set_view_interval(self, vmin, vmax): self.axis.set_view_interval(vmin, vmax) @@ -149,7 +149,7 @@ self.set_view_interval(vmin, vmax) self.set_data_interval(vmin, vmax) - + class Formatter(TickHelper): """ Convert the tick location to a string @@ -459,13 +459,18 @@ vmin, vmax = self.axis.get_view_interval() d = abs(vmax - vmin) b=self._base + if x == 0.0: + return '0' + sign = npy.sign(x) # only label the decades - fx = math.log(x)/math.log(b) + fx = math.log(abs(x))/math.log(b) isDecade = self.is_decade(fx) if not isDecade and self.labelOnlyBase: s = '' elif x>10000: s= '%1.0e'%x elif x<1: s = '%1.0e'%x else : s = self.pprint_val(x,d) + if sign == -1: + return '-%s' % s return s def format_data(self,value): @@ -516,8 +521,11 @@ self.verify_intervals() d = abs(self.viewInterval.span()) b=self._base + if x == 0: + return '0' + sign = npy.sign(x) # only label the decades - fx = math.log(x)/math.log(b) + fx = math.log(abs(x))/math.log(b) isDecade = self.is_decade(fx) if not isDecade and self.labelOnlyBase: s = '' #if 0: pass @@ -526,6 +534,8 @@ #elif x<1: s = '10^%d'%fx elif fx<1: s = '%1.0e'%fx else : s = self.pprint_val(fx,d) + if sign == -1: + return '-%s' % s return s @@ -538,22 +548,30 @@ 'Return the format for tick val x at position pos' b = self._base # only label the decades - fx = math.log(x)/math.log(b) + if x == 0: + return '0ドル$' + sign = npy.sign(x) + fx = math.log(abs(x))/math.log(b) isDecade = self.is_decade(fx) usetex = rcParams['text.usetex'] + if sign == -1: + sign_string = '-' + else: + sign_string = '' + if not isDecade and self.labelOnlyBase: s = '' elif not isDecade: if usetex: - s = r'$%d^{%.2f}$'% (b, fx) + s = r'$%s%d^{%.2f}$'% (sign_string, b, fx) else: - s = '$\mathdefault{%d^{%.2f}}$'% (b, fx) + s = '$\mathdefault{%s%d^{%.2f}}$'% (sign_string, b, fx) else: if usetex: - s = r'$%d^{%d}$'% (b, self.nearest_long(fx)) + s = r'$%s%d^{%d}$'% (sign_string, b, self.nearest_long(fx)) else: - s = r'$\mathdefault{%d^{%d}}$'% (b, self.nearest_long(fx)) + s = r'$\mathdefault{%s%d^{%d}}$'% (sign_string, b, self.nearest_long(fx)) return s @@ -928,13 +946,12 @@ if vmin <= 0.0: raise ValueError( "Data has no positive values, and therefore can not be log-scaled.") - + vmin = math.log(vmin)/math.log(b) vmax = math.log(vmax)/math.log(b) if vmax<vmin: vmin, vmax = vmax, vmin - ticklocs = [] numdec = math.floor(vmax)-math.ceil(vmin) @@ -949,9 +966,14 @@ while numdec/stride+1 > self.numticks: stride += 1 - for decadeStart in b**npy.arange(math.floor(vmin), - math.ceil(vmax)+stride, stride): - ticklocs.extend( subs*decadeStart ) + decades = npy.arange(math.floor(vmin), + math.ceil(vmax)+stride, stride) + if len(subs) > 1 or subs[0] != 1.0: + ticklocs = [] + for decadeStart in b**decades: + ticklocs.extend( subs*decadeStart ) + else: + ticklocs = b**decades return npy.array(ticklocs) @@ -979,6 +1001,80 @@ result = mtransforms.nonsingular(vmin, vmax) return result +class SymmetricalLogLocator(Locator): + """ + Determine the tick locations for log axes + """ + + def __init__(self, transform, subs=[1.0]): + """ + place ticks on the location= base**i*subs[j] + """ + self._transform = transform + self._subs = subs + self.numticks = 15 + + def _set_numticks(self): + self.numticks = 15 # todo; be smart here; this is just for dev + + def __call__(self): + 'Return the locations of the ticks' + b = self._transform.base + + vmin, vmax = self.axis.get_view_interval() + vmin, vmax = self._transform.transform_point((vmin, vmax)) + if vmax<vmin: + vmin, vmax = vmax, vmin + numdec = math.floor(vmax)-math.ceil(vmin) + + if self._subs is None: + if numdec>10: subs = npy.array([1.0]) + elif numdec>6: subs = npy.arange(2.0, b, 2.0) + else: subs = npy.arange(2.0, b) + else: + subs = npy.asarray(self._subs) + + stride = 1 + while numdec/stride+1 > self.numticks: + stride += 1 + + decades = npy.arange(math.floor(vmin), math.ceil(vmax)+stride, stride) + if len(subs) > 1 or subs[0] != 1.0: + ticklocs = [] + for decade in decades: + ticklocs.extend(subs * (npy.sign(decade) * b ** npy.abs(decade))) + else: + ticklocs = npy.sign(decades) * b ** npy.abs(decades) + return npy.array(ticklocs) + + def autoscale(self): + 'Try to choose the view limits intelligently' + b = self._transform.base + vmin, vmax = self.axis.get_data_interval() + if vmax<vmin: + vmin, vmax = vmax, vmin + + if not is_decade(abs(vmin), b): + if vmin < 0: + vmin = -decade_up(-vmin, b) + else: + vmin = decade_down(vmin, b) + if not is_decade(abs(vmax), b): + if vmax < 0: + vmax = -decade_down(-vmax, b) + else: + vmax = decade_up(vmax, b) + + if vmin == vmax: + if vmin < 0: + vmin = -decade_up(-vmin, b) + vmax = -decade_down(-vmax, b) + else: + vmin = decade_down(vmin, b) + vmax = decade_up(vmax, b) + result = mtransforms.nonsingular(vmin, vmax) + return result + class AutoLocator(MaxNLocator): def __init__(self): MaxNLocator.__init__(self, nbins=9, steps=[1, 2, 5, 10]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4734 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4734&view=rev Author: mdboom Date: 2007年12月14日 12:08:22 -0800 (2007年12月14日) Log Message: ----------- Fix minimum value of bars so it looks correct upon zooming. Modified Paths: -------------- branches/transforms/examples/polar_bar.py Modified: branches/transforms/examples/polar_bar.py =================================================================== --- branches/transforms/examples/polar_bar.py 2007年12月14日 20:07:59 UTC (rev 4733) +++ branches/transforms/examples/polar_bar.py 2007年12月14日 20:08:22 UTC (rev 4734) @@ -13,7 +13,7 @@ theta = npy.arange(0.0, 2*npy.pi, 2*npy.pi/N) radii = 10*npy.random.rand(N) width = npy.pi/4*npy.random.rand(N) -bars = ax.bar(theta, radii, width=width, bottom=0.1) +bars = ax.bar(theta, radii, width=width, bottom=0.0) for r,bar in zip(radii, bars): bar.set_facecolor( cm.jet(r/10.)) bar.set_alpha(0.5) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4732 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4732&view=rev Author: jswhit Date: 2007年12月14日 08:28:34 -0800 (2007年12月14日) Log Message: ----------- look in /opt/local for geos lib (macports installs there) Modified Paths: -------------- trunk/toolkits/basemap/setup.py Modified: trunk/toolkits/basemap/setup.py =================================================================== --- trunk/toolkits/basemap/setup.py 2007年12月14日 13:01:36 UTC (rev 4731) +++ trunk/toolkits/basemap/setup.py 2007年12月14日 16:28:34 UTC (rev 4732) @@ -52,7 +52,7 @@ if GEOS_dir is None: # if GEOS_dir not set, check a few standard locations. - GEOS_dirs = ['/usr/local','/sw','/opt',os.path.expanduser('~')] + GEOS_dirs = ['/usr/local','/sw','/opt','/opt/local',os.path.expanduser('~')] for direc in GEOS_dirs: geos_version = check_geosversion(direc) print 'checking for GEOS lib in %s ....' % direc This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4731 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4731&view=rev Author: jswhit Date: 2007年12月14日 05:01:36 -0800 (2007年12月14日) Log Message: ----------- get rid of reference to numerix in docstring Modified Paths: -------------- trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py Modified: trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py =================================================================== --- trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py 2007年12月13日 22:40:33 UTC (rev 4730) +++ trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py 2007年12月14日 13:01:36 UTC (rev 4731) @@ -2698,7 +2698,7 @@ points in datain are masked. To avoid this, do the interpolation in two passes, first with order=1 (producing dataout1), then with order=0 (producing dataout2). Then replace all the masked values in dataout1 - with the corresponding elements in dataout2 (using numerix.where). + with the corresponding elements in dataout2 (using numpy.where). This effectively uses nearest neighbor interpolation if any of the four surrounding points in datain are masked, and bilinear interpolation otherwise. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4730 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4730&view=rev Author: jdh2358 Date: 2007年12月13日 14:40:33 -0800 (2007年12月13日) Log Message: ----------- noted rec2gtk and recexcel moves in CHANGELOG Modified Paths: -------------- trunk/matplotlib/CHANGELOG Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2007年12月13日 18:42:54 UTC (rev 4729) +++ trunk/matplotlib/CHANGELOG 2007年12月13日 22:40:33 UTC (rev 4730) @@ -1,3 +1,6 @@ +2007年12月13日 Moved rec2gtk to matplotlib.toolkits.gtktools and rec2excel + to matplotlib.toolkits.exceltools - JDH + 2007年12月12日 Support alpha-blended text in the Agg and Svg backends - MGD This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4729 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4729&view=rev Author: mdboom Date: 2007年12月13日 10:42:54 -0800 (2007年12月13日) Log Message: ----------- Fix some regular expressions. Modified Paths: -------------- branches/transforms/lib/matplotlib/fontconfig_pattern.py branches/transforms/lib/matplotlib/mathtext.py Modified: branches/transforms/lib/matplotlib/fontconfig_pattern.py =================================================================== --- branches/transforms/lib/matplotlib/fontconfig_pattern.py 2007年12月13日 18:30:45 UTC (rev 4728) +++ branches/transforms/lib/matplotlib/fontconfig_pattern.py 2007年12月13日 18:42:54 UTC (rev 4729) @@ -35,8 +35,8 @@ See here for a rough specification of these patterns: http://www.fontconfig.org/fontconfig-user.html """ - + _constants = { 'thin' : ('weight', 'light'), 'extralight' : ('weight', 'light'), @@ -63,12 +63,12 @@ 'extraexpanded' : ('width', 'extra-expanded'), 'ultraexpanded' : ('width', 'ultra-expanded') } - + def __init__(self): family = Regex(r'([^%s]|(\\[%s]))*' % (family_punc, family_punc)) \ .setParseAction(self._family) - size = Regex(r'[0-9.]+') \ + size = Regex(r"([0-9]+\.?[0-9]*|\.[0-9]+)") \ .setParseAction(self._size) name = Regex(r'[a-z]+') \ .setParseAction(self._name) @@ -79,7 +79,7 @@ families =(family + ZeroOrMore( Literal(',') - + family) + + family) ).setParseAction(self._families) point_sizes =(size @@ -118,10 +118,10 @@ self._parser.parseString(pattern) except self.ParseException, e: raise ValueError("Could not parse font string: '%s'\n%s" % (pattern, e)) - + self._properties = None return props - + def _family(self, s, loc, tokens): return [family_unescape(r'1円', tokens[0])] @@ -141,7 +141,7 @@ def _point_sizes(self, s, loc, tokens): self._properties['size'] = tokens return [] - + def _property(self, s, loc, tokens): if len(tokens) == 1: if tokens[0] in self._constants: Modified: branches/transforms/lib/matplotlib/mathtext.py =================================================================== --- branches/transforms/lib/matplotlib/mathtext.py 2007年12月13日 18:30:45 UTC (rev 4728) +++ branches/transforms/lib/matplotlib/mathtext.py 2007年12月13日 18:42:54 UTC (rev 4729) @@ -1984,7 +1984,7 @@ autoDelim = Forward().setParseAction(self.auto_sized_delimiter) self._expression = Forward().setParseAction(self.finish).setName("finish") - float = Regex(r"-?[0-9]*(\.[0-9]+)?") + float = Regex(r"[-+]?([0-9]+\.?[0-9]*|\.[0-9]+)") lbrace = Literal('{').suppress() rbrace = Literal('}').suppress() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4728 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4728&view=rev Author: mdboom Date: 2007年12月13日 10:30:45 -0800 (2007年12月13日) Log Message: ----------- Update API_CHANGES and CHANGELOG for stuff since 0.91.1 Modified Paths: -------------- trunk/matplotlib/API_CHANGES trunk/matplotlib/CHANGELOG Modified: trunk/matplotlib/API_CHANGES =================================================================== --- trunk/matplotlib/API_CHANGES 2007年12月13日 18:21:25 UTC (rev 4727) +++ trunk/matplotlib/API_CHANGES 2007年12月13日 18:30:45 UTC (rev 4728) @@ -1,3 +1,6 @@ + A warning is issued when an image is drawn on log-scaled + axes, since it will not log-scale the image data. + Moved rec2gtk to matplotlib.toolkits.gtktools Moved rec2excel to matplotlib.toolkits.exceltools @@ -2,3 +5,2 @@ - Removed, dead/experimental ExampleInfo, Namespace and Importer @@ -11,7 +13,7 @@ Changed cbook.is_file_like to cbook.is_writable_file_like and corrected behavior. - + Added ax kwarg to pyplot.colorbar and Figure.colorbar so that one can specify the axes object from which space for the colorbar is to be taken, if one does not want to make the colorbar axes Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2007年12月13日 18:21:25 UTC (rev 4727) +++ trunk/matplotlib/CHANGELOG 2007年12月13日 18:30:45 UTC (rev 4728) @@ -1,9 +1,13 @@ -2007年12月10日 Fix SVG text rendering bug. +2007年12月12日 Support alpha-blended text in the Agg and Svg backends - + MGD -2007年12月10日 Increase accuracy of circle and ellipse drawing by using an 8-piece - bezier approximation, rather than a 4-piece one. Fix PDF, SVG and - Cairo backends so they can draw paths (meaning ellipses as well). +2007年12月10日 Fix SVG text rendering bug. - MGD +2007年12月10日 Increase accuracy of circle and ellipse drawing by using an + 8-piece bezier approximation, rather than a 4-piece one. + Fix PDF, SVG and Cairo backends so they can draw paths + (meaning ellipses as well). - MGD + 2007年12月07日 Issue a warning when drawing an image on a non-linear axis. - MGD 2007年12月06日 let widgets.Cursor initialize to the lower x and y bounds @@ -18,6 +22,10 @@ (This was a regression since 0.90 caused by the refactoring of font_manager.py) - MGD +2007年12月05日 Support arbitrary rotation of usetex text in Agg backend. - MGD + +2007年12月04日 Support '|' as a character in mathtext - MGD + =============================================================== 2007年11月27日 Released 0.91.1 at revision 4517 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4727 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4727&view=rev Author: mdboom Date: 2007年12月13日 10:21:25 -0800 (2007年12月13日) Log Message: ----------- Merged revisions 4715-4725 via svnmerge from http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib ........ r4718 | mdboom | 2007年12月13日 08:40:40 -0500 (2007年12月13日) | 2 lines Updated to numpy names. ........ r4720 | jdh2358 | 2007年12月13日 11:06:59 -0500 (2007年12月13日) | 2 lines moved optional rec2* packages out of mlab and into toolkits ........ r4722 | jdh2358 | 2007年12月13日 13:12:11 -0500 (2007年12月13日) | 2 lines added gtktools and exceltools to toolkits ........ Modified Paths: -------------- branches/transforms/API_CHANGES branches/transforms/CODING_GUIDE branches/transforms/examples/figimage_demo.py branches/transforms/examples/logo.py branches/transforms/examples/mri_demo.py branches/transforms/lib/matplotlib/image.py branches/transforms/lib/matplotlib/mlab.py branches/transforms/src/_backend_agg.cpp branches/transforms/src/_image.cpp Added Paths: ----------- branches/transforms/lib/matplotlib/toolkits/exceltools.py branches/transforms/lib/matplotlib/toolkits/gtktools.py Property Changed: ---------------- branches/transforms/ Property changes on: branches/transforms ___________________________________________________________________ Name: svnmerge-integrated - /trunk/matplotlib:1-4714 + /trunk/matplotlib:1-4725 Modified: branches/transforms/API_CHANGES =================================================================== --- branches/transforms/API_CHANGES 2007年12月13日 18:17:33 UTC (rev 4726) +++ branches/transforms/API_CHANGES 2007年12月13日 18:21:25 UTC (rev 4727) @@ -169,6 +169,10 @@ END OF TRANSFORMS REFACTORING + Moved rec2gtk to matplotlib.toolkits.gtktools + + Moved rec2excel to matplotlib.toolkits.exceltools + Removed, dead/experimental ExampleInfo, Namespace and Importer code from matplotlib/__init__.py 0.91.1 Released Modified: branches/transforms/CODING_GUIDE =================================================================== --- branches/transforms/CODING_GUIDE 2007年12月13日 18:17:33 UTC (rev 4726) +++ branches/transforms/CODING_GUIDE 2007年12月13日 18:21:25 UTC (rev 4727) @@ -113,6 +113,16 @@ .emacs will cause emacs to strip trailing white space on save for python, C and C++ + +When importing modules from the matplotlib namespace + + import matplotlib.cbook as cbook # DO + from matplotlib import cbook #DONT + +because the latter is ambiguous whether cbook is a module or a +function to the new developer. The former makes it explcit that you +are importing a module or package. + ; and similarly for c++-mode-hook and c-mode-hook (add-hook 'python-mode-hook (lambda () Modified: branches/transforms/examples/figimage_demo.py =================================================================== --- branches/transforms/examples/figimage_demo.py 2007年12月13日 18:17:33 UTC (rev 4726) +++ branches/transforms/examples/figimage_demo.py 2007年12月13日 18:21:25 UTC (rev 4727) @@ -13,7 +13,7 @@ im1 = figimage(Z, xo=50, yo=0) im2 = figimage(Z, xo=100, yo=100, alpha=.8) #gray() # overrides current and sets default -#savefig('figimage_demo') +savefig('figimage_demo') show() Modified: branches/transforms/examples/logo.py =================================================================== --- branches/transforms/examples/logo.py 2007年12月13日 18:17:33 UTC (rev 4726) +++ branches/transforms/examples/logo.py 2007年12月13日 18:21:25 UTC (rev 4727) @@ -5,7 +5,7 @@ # convert data to mV x = 1000*0.1*fromstring( - file('data/membrane.dat', 'rb').read(), Float32) + file('data/membrane.dat', 'rb').read(), float32) # 0.0005 is the sample interval t = 0.0005*arange(len(x)) figure(1, figsize=(7,1), dpi=100) Modified: branches/transforms/examples/mri_demo.py =================================================================== --- branches/transforms/examples/mri_demo.py 2007年12月13日 18:17:33 UTC (rev 4726) +++ branches/transforms/examples/mri_demo.py 2007年12月13日 18:21:25 UTC (rev 4727) @@ -3,7 +3,7 @@ # data are 256x256 16 bit integers dfile = 'data/s1045.ima' -im = fromstring(file(dfile, 'rb').read(), UInt16).astype(Float) +im = fromstring(file(dfile, 'rb').read(), uint16).astype(float) im.shape = 256, 256 #imshow(im, ColormapJet(256)) Modified: branches/transforms/lib/matplotlib/image.py =================================================================== --- branches/transforms/lib/matplotlib/image.py 2007年12月13日 18:17:33 UTC (rev 4726) +++ branches/transforms/lib/matplotlib/image.py 2007年12月13日 18:21:25 UTC (rev 4727) @@ -23,6 +23,7 @@ from matplotlib._image import * class AxesImage(martist.Artist, cm.ScalarMappable): + zorder = 1 def __init__(self, ax, cmap = None, @@ -508,18 +509,21 @@ self.update_dict['array'] = True class FigureImage(martist.Artist, cm.ScalarMappable): + zorder = 1 def __init__(self, fig, cmap = None, norm = None, offsetx = 0, offsety = 0, origin=None, + **kwargs ): """ cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 + kwargs are an optional list of Artist keyword args """ martist.Artist.__init__(self) cm.ScalarMappable.__init__(self, norm, cmap) @@ -528,6 +532,7 @@ self.figure = fig self.ox = offsetx self.oy = offsety + self.update(kwargs) def contains(self, mouseevent): """Test whether the mouse event occured within the image. Modified: branches/transforms/lib/matplotlib/mlab.py =================================================================== --- branches/transforms/lib/matplotlib/mlab.py 2007年12月13日 18:17:33 UTC (rev 4726) +++ branches/transforms/lib/matplotlib/mlab.py 2007年12月13日 18:21:25 UTC (rev 4727) @@ -48,13 +48,13 @@ * rec2csv : store record array in CSV file * rec2excel : store record array in excel worksheet - required pyExcelerator - * rec2gtk : put record array in GTK treeview - requires gtk + * csv2rec : import record array from CSV file with type inspection * rec_append_field : add a field/array to record array * rec_drop_fields : drop fields from record array * rec_join : join two record arrays on sequence of fields -For the rec viewer clases (rec2csv, rec2excel and rec2gtk), there are +For the rec viewer clases (rec2csv, rec2excel), there are a bunch of Format objects you can pass into the functions that will do things like color negative values red, set percent formatting and scaling, etc. @@ -1978,7 +1978,7 @@ join record arrays r1 and r2 on key; key is a tuple of field names. if r1 and r2 have equal values on all the keys in the key tuple, then their fields will be merged into a new record array - containing the union of the fields of r1 and r2 + containing the intersection of the fields of r1 and r2 """ for name in key: @@ -2343,373 +2343,5 @@ writer.writerow([func(val) for func, val in zip(funcs, row)]) fh.close() -# if pyExcelerator is installed, provide an excel view -try: - import pyExcelerator as excel -except ImportError: - pass -else: - def xlformat_factory(format): - """ - copy the format, perform any overrides, and attach an xlstyle instance - copied format is returned - """ - format = copy.deepcopy(format) - - - xlstyle = excel.XFStyle() - if isinstance(format, FormatFloat): - zeros = ''.join(['0']*format.precision) - xlstyle.num_format_str = '#,##0.%s;[RED]-#,##0.%s'%(zeros, zeros) - elif isinstance(format, FormatInt): - xlstyle.num_format_str = '#,##;[RED]-#,##' - elif isinstance(format, FormatPercent): - zeros = ''.join(['0']*format.precision) - xlstyle.num_format_str = '0.%s%%;[RED]-0.%s%%'%(zeros, zeros) - format.scale = 1. - else: - xlstyle = None - - format.xlstyle = xlstyle - - return format - - def rec2excel(r, ws, formatd=None, rownum=0, colnum=0): - """ - save record array r to excel pyExcelerator worksheet ws - starting at rownum. if ws is string like, assume it is a - filename and save to it - - start writing at rownum, colnum - - formatd is a dictionary mapping dtype name -> FormatXL instances - - The next rownum after writing is returned - """ - - autosave = False - if cbook.is_string_like(ws): - filename = ws - wb = excel.Workbook() - ws = wb.add_sheet('worksheet') - autosave = True - - - if formatd is None: - formatd = dict() - - formats = [] - font = excel.Font() - font.bold = True - - stylehdr = excel.XFStyle() - stylehdr.font = font - - for i, name in enumerate(r.dtype.names): - dt = r.dtype[name] - format = formatd.get(name) - if format is None: - format = defaultformatd.get(dt.type, FormatObj()) - - format = xlformat_factory(format) - ws.write(rownum, colnum+i, name, stylehdr) - formats.append(format) - - rownum+=1 - - - ind = npy.arange(len(r.dtype.names)) - for row in r: - for i in ind: - val = row[i] - format = formats[i] - val = format.toval(val) - if format.xlstyle is None: - ws.write(rownum, colnum+i, val) - else: - if safe_isnan(val): - ws.write(rownum, colnum+i, 'NaN') - else: - ws.write(rownum, colnum+i, val, format.xlstyle) - rownum += 1 - - if autosave: - wb.save(filename) - return rownum - - - - -# if gtk is installed, provide a gtk view -try: - import gtk, gobject -except ImportError: - pass -except RuntimeError: - pass -else: - - - def gtkformat_factory(format, colnum): - """ - copy the format, perform any overrides, and attach an gtk style attrs - - - xalign = 0. - cell = None - - """ - - format = copy.copy(format) - format.xalign = 0. - format.cell = None - - def negative_red_cell(column, cell, model, thisiter): - val = model.get_value(thisiter, colnum) - try: val = float(val) - except: cell.set_property('foreground', 'black') - else: - if val<0: - cell.set_property('foreground', 'red') - else: - cell.set_property('foreground', 'black') - - - if isinstance(format, FormatFloat) or isinstance(format, FormatInt): - format.cell = negative_red_cell - format.xalign = 1. - elif isinstance(format, FormatDate): - format.xalign = 1. - return format - - - - class SortedStringsScrolledWindow(gtk.ScrolledWindow): - """ - A simple treeview/liststore assuming all columns are strings. - Supports ascending/descending sort by clicking on column header - """ - - def __init__(self, colheaders, formatterd=None): - """ - xalignd if not None, is a dict mapping col header to xalignent (default 1) - - formatterd if not None, is a dict mapping col header to a ColumnFormatter - """ - - - gtk.ScrolledWindow.__init__(self) - self.colheaders = colheaders - self.seq = None # not initialized with accts - self.set_shadow_type(gtk.SHADOW_ETCHED_IN) - self.set_policy(gtk.POLICY_AUTOMATIC, - gtk.POLICY_AUTOMATIC) - - types = [gobject.TYPE_STRING] * len(colheaders) - model = self.model = gtk.ListStore(*types) - - - treeview = gtk.TreeView(self.model) - treeview.show() - treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE) - treeview.set_rules_hint(True) - - - class Clicked: - def __init__(self, parent, i): - self.parent = parent - self.i = i - self.num = 0 - - def __call__(self, column): - ind = [] - dsu = [] - for rownum, thisiter in enumerate(self.parent.iters): - val = model.get_value(thisiter, self.i) - try: val = float(val.strip().rstrip('%')) - except ValueError: pass - if npy.isnan(val): val = npy.inf # force nan to sort uniquely - dsu.append((val, rownum)) - dsu.sort() - if not self.num%2: dsu.reverse() - - vals, otherind = zip(*dsu) - ind.extend(otherind) - - self.parent.model.reorder(ind) - newiters = [] - for i in ind: - newiters.append(self.parent.iters[i]) - self.parent.iters = newiters[:] - for i, thisiter in enumerate(self.parent.iters): - key = tuple([self.parent.model.get_value(thisiter, j) for j in range(len(colheaders))]) - self.parent.rownumd[i] = key - - self.num+=1 - - - if formatterd is None: - formatterd = dict() - - formatterd = formatterd.copy() - - for i, header in enumerate(colheaders): - renderer = gtk.CellRendererText() - if header not in formatterd: - formatterd[header] = ColumnFormatter() - formatter = formatterd[header] - - column = gtk.TreeViewColumn(header, renderer, text=i) - renderer.set_property('xalign', formatter.xalign) - column.connect('clicked', Clicked(self, i)) - column.set_property('clickable', True) - - if formatter.cell is not None: - column.set_cell_data_func(renderer, formatter.cell) - - treeview.append_column(column) - - - - self.formatterd = formatterd - self.lastcol = column - self.add(treeview) - self.treeview = treeview - self.clear() - - def clear(self): - self.iterd = dict() - self.iters = [] # an ordered list of iters - self.rownumd = dict() # a map from rownum -> symbol - self.model.clear() - self.datad = dict() - - - def flat(self, row): - seq = [] - for i,val in enumerate(row): - formatter = self.formatterd.get(self.colheaders[i]) - seq.extend([i,formatter.tostr(val)]) - return seq - - def __delete_selected(self, *unused): # untested - - - keyd = dict([(thisiter, key) for key, thisiter in self.iterd.values()]) - for row in self.get_selected(): - key = tuple(row) - thisiter = self.iterd[key] - self.model.remove(thisiter) - del self.datad[key] - del self.iterd[key] - self.iters.remove(thisiter) - - for i, thisiter in enumerate(self.iters): - self.rownumd[i] = keyd[thisiter] - - - - def delete_row(self, row): - key = tuple(row) - thisiter = self.iterd[key] - self.model.remove(thisiter) - - - del self.datad[key] - del self.iterd[key] - self.rownumd[len(self.iters)] = key - self.iters.remove(thisiter) - - for rownum, thiskey in self.rownumd.items(): - if thiskey==key: del self.rownumd[rownum] - - def add_row(self, row): - thisiter = self.model.append() - self.model.set(thisiter, *self.flat(row)) - key = tuple(row) - self.datad[key] = row - self.iterd[key] = thisiter - self.rownumd[len(self.iters)] = key - self.iters.append(thisiter) - - def update_row(self, rownum, newrow): - key = self.rownumd[rownum] - thisiter = self.iterd[key] - newkey = tuple(newrow) - - self.rownumd[rownum] = newkey - del self.datad[key] - del self.iterd[key] - self.datad[newkey] = newrow - self.iterd[newkey] = thisiter - - - self.model.set(thisiter, *self.flat(newrow)) - - def get_row(self, rownum): - key = self.rownumd[rownum] - return self.datad[key] - - def get_selected(self): - selected = [] - def foreach(model, path, iter, selected): - selected.append(model.get_value(iter, 0)) - - self.treeview.get_selection().selected_foreach(foreach, selected) - return selected - - - - def rec2gtk(r, formatd=None, rownum=0, autowin=True): - """ - save record array r to excel pyExcelerator worksheet ws - starting at rownum. if ws is string like, assume it is a - filename and save to it - - formatd is a dictionary mapping dtype name -> FormatXL instances - - This function creates a SortedStringsScrolledWindow (derived - from gtk.ScrolledWindow) and returns it. if autowin is True, - a gtk.Window is created, attached to the - SortedStringsScrolledWindow instance, shown and returned. If - autowin=False, the caller is responsible for adding the - SortedStringsScrolledWindow instance to a gtk widget and - showing it. - """ - - - - if formatd is None: - formatd = dict() - - formats = [] - for i, name in enumerate(r.dtype.names): - dt = r.dtype[name] - format = formatd.get(name) - if format is None: - format = defaultformatd.get(dt.type, FormatObj()) - #print 'gtk fmt factory', i, name, format, type(format) - format = gtkformat_factory(format, i) - formatd[name] = format - - - colheaders = r.dtype.names - scroll = SortedStringsScrolledWindow(colheaders, formatd) - - ind = npy.arange(len(r.dtype.names)) - for row in r: - scroll.add_row(row) - - - if autowin: - win = gtk.Window() - win.set_default_size(800,600) - win.add(scroll) - win.show_all() - scroll.win = win - - return scroll - - Copied: branches/transforms/lib/matplotlib/toolkits/exceltools.py (from rev 4722, trunk/matplotlib/lib/matplotlib/toolkits/exceltools.py) =================================================================== --- branches/transforms/lib/matplotlib/toolkits/exceltools.py (rev 0) +++ branches/transforms/lib/matplotlib/toolkits/exceltools.py 2007年12月13日 18:21:25 UTC (rev 4727) @@ -0,0 +1,120 @@ +""" +Some io tools for excel -- requires pypyExcelerator + +Example usage: + + import matplotlib.mlab as mlab + import matplotlib.toolkits.exceltools as exceltools + + r = mlab.csv2rec('somefile.csv', checkrows=0) + + formatd = dict( + weight = mlab.FormatFloat(2), + change = mlab.FormatPercent(2), + cost = mlab.FormatThousands(2), + ) + + + exceltools.rec2excel(r, 'test.xls', formatd=formatd) + mlab.rec2csv(r, 'test.csv', formatd=formatd) + +""" +import copy +import numpy as npy +import pyExcelerator as excel +import matplotlib.cbook as cbook +import matplotlib.mlab as mlab + + +def xlformat_factory(format): + """ + copy the format, perform any overrides, and attach an xlstyle instance + copied format is returned + """ + format = copy.deepcopy(format) + + + + xlstyle = excel.XFStyle() + if isinstance(format, mlab.FormatPercent): + zeros = ''.join(['0']*format.precision) + xlstyle.num_format_str = '0.%s%%;[RED]-0.%s%%'%(zeros, zeros) + format.scale = 1. + elif isinstance(format, mlab.FormatFloat): + zeros = ''.join(['0']*format.precision) + xlstyle.num_format_str = '#,##0.%s;[RED]-#,##0.%s'%(zeros, zeros) + elif isinstance(format, mlab.FormatInt): + xlstyle.num_format_str = '#,##;[RED]-#,##' + else: + xlstyle = None + + format.xlstyle = xlstyle + + return format + +def rec2excel(r, ws, formatd=None, rownum=0, colnum=0): + """ + save record array r to excel pyExcelerator worksheet ws + starting at rownum. if ws is string like, assume it is a + filename and save to it + + start writing at rownum, colnum + + formatd is a dictionary mapping dtype name -> mlab.Format instances + + The next rownum after writing is returned + """ + + autosave = False + if cbook.is_string_like(ws): + filename = ws + wb = excel.Workbook() + ws = wb.add_sheet('worksheet') + autosave = True + + + if formatd is None: + formatd = dict() + + formats = [] + font = excel.Font() + font.bold = True + + stylehdr = excel.XFStyle() + stylehdr.font = font + + for i, name in enumerate(r.dtype.names): + dt = r.dtype[name] + format = formatd.get(name) + if format is None: + format = mlab.defaultformatd.get(dt.type, mlab.FormatObj()) + + format = xlformat_factory(format) + ws.write(rownum, colnum+i, name, stylehdr) + formats.append(format) + + rownum+=1 + + + ind = npy.arange(len(r.dtype.names)) + for row in r: + for i in ind: + val = row[i] + format = formats[i] + val = format.toval(val) + if format.xlstyle is None: + ws.write(rownum, colnum+i, val) + else: + if mlab.safe_isnan(val): + ws.write(rownum, colnum+i, 'NaN') + else: + ws.write(rownum, colnum+i, val, format.xlstyle) + rownum += 1 + + if autosave: + wb.save(filename) + return rownum + + + + Copied: branches/transforms/lib/matplotlib/toolkits/gtktools.py (from rev 4722, trunk/matplotlib/lib/matplotlib/toolkits/gtktools.py) =================================================================== --- branches/transforms/lib/matplotlib/toolkits/gtktools.py (rev 0) +++ branches/transforms/lib/matplotlib/toolkits/gtktools.py 2007年12月13日 18:21:25 UTC (rev 4727) @@ -0,0 +1,299 @@ +""" + +Some gtk specific tools and widgets + + * rec2gtk : put record array in GTK treeview - requires gtk + +Example usage + + import matplotlib.mlab as mlab + import matplotlib.toolkits.gtktools as gtktools + + r = mlab.csv2rec('somefile.csv', checkrows=0) + + formatd = dict( + weight = mlab.FormatFloat(2), + change = mlab.FormatPercent(2), + cost = mlab.FormatThousands(2), + ) + + + exceltools.rec2excel(r, 'test.xls', formatd=formatd) + mlab.rec2csv(r, 'test.csv', formatd=formatd) + + + import gtk + scroll = gtktools.rec2gtk(r, formatd=formatd) + win = gtk.Window() + win.set_size_request(600,800) + win.add(scroll) + win.show_all() + gtk.main() + +""" +import copy +import gtk, gobject +import numpy as npy +import matplotlib.cbook as cbook +import matplotlib.mlab as mlab + +def gtkformat_factory(format, colnum): + """ + copy the format, perform any overrides, and attach an gtk style attrs + + + xalign = 0. + cell = None + + """ + + format = copy.copy(format) + format.xalign = 0. + format.cell = None + + def negative_red_cell(column, cell, model, thisiter): + val = model.get_value(thisiter, colnum) + try: val = float(val) + except: cell.set_property('foreground', 'black') + else: + if val<0: + cell.set_property('foreground', 'red') + else: + cell.set_property('foreground', 'black') + + + if isinstance(format, mlab.FormatFloat) or isinstance(format, mlab.FormatInt): + format.cell = negative_red_cell + format.xalign = 1. + elif isinstance(format, mlab.FormatDate): + format.xalign = 1. + return format + + + +class SortedStringsScrolledWindow(gtk.ScrolledWindow): + """ + A simple treeview/liststore assuming all columns are strings. + Supports ascending/descending sort by clicking on column header + """ + + def __init__(self, colheaders, formatterd=None): + """ + xalignd if not None, is a dict mapping col header to xalignent (default 1) + + formatterd if not None, is a dict mapping col header to a ColumnFormatter + """ + + + gtk.ScrolledWindow.__init__(self) + self.colheaders = colheaders + self.seq = None # not initialized with accts + self.set_shadow_type(gtk.SHADOW_ETCHED_IN) + self.set_policy(gtk.POLICY_AUTOMATIC, + gtk.POLICY_AUTOMATIC) + + types = [gobject.TYPE_STRING] * len(colheaders) + model = self.model = gtk.ListStore(*types) + + + treeview = gtk.TreeView(self.model) + treeview.show() + treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE) + treeview.set_rules_hint(True) + + + class Clicked: + def __init__(self, parent, i): + self.parent = parent + self.i = i + self.num = 0 + + def __call__(self, column): + ind = [] + dsu = [] + for rownum, thisiter in enumerate(self.parent.iters): + val = model.get_value(thisiter, self.i) + try: val = float(val.strip().rstrip('%')) + except ValueError: pass + if npy.isnan(val): val = npy.inf # force nan to sort uniquely + dsu.append((val, rownum)) + dsu.sort() + if not self.num%2: dsu.reverse() + + vals, otherind = zip(*dsu) + ind.extend(otherind) + + self.parent.model.reorder(ind) + newiters = [] + for i in ind: + newiters.append(self.parent.iters[i]) + self.parent.iters = newiters[:] + for i, thisiter in enumerate(self.parent.iters): + key = tuple([self.parent.model.get_value(thisiter, j) for j in range(len(colheaders))]) + self.parent.rownumd[i] = key + + self.num+=1 + + + if formatterd is None: + formatterd = dict() + + formatterd = formatterd.copy() + + for i, header in enumerate(colheaders): + renderer = gtk.CellRendererText() + if header not in formatterd: + formatterd[header] = ColumnFormatter() + formatter = formatterd[header] + + column = gtk.TreeViewColumn(header, renderer, text=i) + renderer.set_property('xalign', formatter.xalign) + column.connect('clicked', Clicked(self, i)) + column.set_property('clickable', True) + + if formatter.cell is not None: + column.set_cell_data_func(renderer, formatter.cell) + + treeview.append_column(column) + + + + self.formatterd = formatterd + self.lastcol = column + self.add(treeview) + self.treeview = treeview + self.clear() + + def clear(self): + self.iterd = dict() + self.iters = [] # an ordered list of iters + self.rownumd = dict() # a map from rownum -> symbol + self.model.clear() + self.datad = dict() + + + def flat(self, row): + seq = [] + for i,val in enumerate(row): + formatter = self.formatterd.get(self.colheaders[i]) + seq.extend([i,formatter.tostr(val)]) + return seq + + def __delete_selected(self, *unused): # untested + + + keyd = dict([(thisiter, key) for key, thisiter in self.iterd.values()]) + for row in self.get_selected(): + key = tuple(row) + thisiter = self.iterd[key] + self.model.remove(thisiter) + del self.datad[key] + del self.iterd[key] + self.iters.remove(thisiter) + + for i, thisiter in enumerate(self.iters): + self.rownumd[i] = keyd[thisiter] + + + + def delete_row(self, row): + key = tuple(row) + thisiter = self.iterd[key] + self.model.remove(thisiter) + + + del self.datad[key] + del self.iterd[key] + self.rownumd[len(self.iters)] = key + self.iters.remove(thisiter) + + for rownum, thiskey in self.rownumd.items(): + if thiskey==key: del self.rownumd[rownum] + + def add_row(self, row): + thisiter = self.model.append() + self.model.set(thisiter, *self.flat(row)) + key = tuple(row) + self.datad[key] = row + self.iterd[key] = thisiter + self.rownumd[len(self.iters)] = key + self.iters.append(thisiter) + + def update_row(self, rownum, newrow): + key = self.rownumd[rownum] + thisiter = self.iterd[key] + newkey = tuple(newrow) + + self.rownumd[rownum] = newkey + del self.datad[key] + del self.iterd[key] + self.datad[newkey] = newrow + self.iterd[newkey] = thisiter + + + self.model.set(thisiter, *self.flat(newrow)) + + def get_row(self, rownum): + key = self.rownumd[rownum] + return self.datad[key] + + def get_selected(self): + selected = [] + def foreach(model, path, iter, selected): + selected.append(model.get_value(iter, 0)) + + self.treeview.get_selection().selected_foreach(foreach, selected) + return selected + + + +def rec2gtk(r, formatd=None, rownum=0, autowin=True): + """ + save record array r to excel pyExcelerator worksheet ws + starting at rownum. if ws is string like, assume it is a + filename and save to it + + formatd is a dictionary mapping dtype name -> mlab.Format instances + + This function creates a SortedStringsScrolledWindow (derived + from gtk.ScrolledWindow) and returns it. if autowin is True, + a gtk.Window is created, attached to the + SortedStringsScrolledWindow instance, shown and returned. If + autowin=False, the caller is responsible for adding the + SortedStringsScrolledWindow instance to a gtk widget and + showing it. + """ + + + + if formatd is None: + formatd = dict() + + formats = [] + for i, name in enumerate(r.dtype.names): + dt = r.dtype[name] + format = formatd.get(name) + if format is None: + format = mlab.defaultformatd.get(dt.type, mlab.FormatObj()) + #print 'gtk fmt factory', i, name, format, type(format) + format = gtkformat_factory(format, i) + formatd[name] = format + + + colheaders = r.dtype.names + scroll = SortedStringsScrolledWindow(colheaders, formatd) + + ind = npy.arange(len(r.dtype.names)) + for row in r: + scroll.add_row(row) + + + if autowin: + win = gtk.Window() + win.set_default_size(800,600) + win.add(scroll) + win.show_all() + scroll.win = win + + return scroll + Modified: branches/transforms/src/_backend_agg.cpp =================================================================== --- branches/transforms/src/_backend_agg.cpp 2007年12月13日 18:17:33 UTC (rev 4726) +++ branches/transforms/src/_backend_agg.cpp 2007年12月13日 18:21:25 UTC (rev 4727) @@ -253,7 +253,7 @@ alphaMaskRenderingBuffer = new agg::rendering_buffer; alphaMaskRenderingBuffer->attach(alphaBuffer, width, height, stride); alphaMask = new alpha_mask_type(*alphaMaskRenderingBuffer); - //jdh + pixfmtAlphaMask = new agg::pixfmt_gray8(*alphaMaskRenderingBuffer); rendererBaseAlphaMask = new renderer_base_alpha_mask_type(*pixfmtAlphaMask); rendererAlphaMask = new renderer_alpha_mask_type(*rendererBaseAlphaMask); Modified: branches/transforms/src/_image.cpp =================================================================== --- branches/transforms/src/_image.cpp 2007年12月13日 18:17:33 UTC (rev 4726) +++ branches/transforms/src/_image.cpp 2007年12月13日 18:21:25 UTC (rev 4727) @@ -299,7 +299,7 @@ Py::Object Image::get_matrix(const Py::Tuple& args) { - _VERBOSE("Image::get_size"); + _VERBOSE("Image::get_matrix"); args.verify_length(0); @@ -520,7 +520,7 @@ Py::Object Image::get_size_out(const Py::Tuple& args) { - _VERBOSE("Image::get_size"); + _VERBOSE("Image::get_size_out"); args.verify_length(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4726 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4726&view=rev Author: jdh2358 Date: 2007年12月13日 10:17:33 -0800 (2007年12月13日) Log Message: ----------- removed namespace declaration from toolkits __init__ Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/toolkits/__init__.py Modified: trunk/matplotlib/lib/matplotlib/toolkits/__init__.py =================================================================== --- trunk/matplotlib/lib/matplotlib/toolkits/__init__.py 2007年12月13日 18:13:49 UTC (rev 4725) +++ trunk/matplotlib/lib/matplotlib/toolkits/__init__.py 2007年12月13日 18:17:33 UTC (rev 4726) @@ -1,4 +1,4 @@ -try: - __import__('pkg_resources').declare_namespace(__name__) -except ImportError: - pass # must not have setuptools +#try: +# __import__('pkg_resources').declare_namespace(__name__) +#except ImportError: +# pass # must not have setuptools This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4725 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4725&view=rev Author: mdboom Date: 2007年12月13日 10:13:49 -0800 (2007年12月13日) Log Message: ----------- Minor speedup in mathtext parsing. Modified Paths: -------------- branches/transforms/lib/matplotlib/mathtext.py Modified: branches/transforms/lib/matplotlib/mathtext.py =================================================================== --- branches/transforms/lib/matplotlib/mathtext.py 2007年12月13日 18:13:04 UTC (rev 4724) +++ branches/transforms/lib/matplotlib/mathtext.py 2007年12月13日 18:13:49 UTC (rev 4725) @@ -147,7 +147,9 @@ from matplotlib.pyparsing import Combine, Group, Optional, Forward, \ Literal, OneOrMore, ZeroOrMore, ParseException, Empty, \ ParseResults, Suppress, oneOf, StringEnd, ParseFatalException, \ - FollowedBy, Regex + FollowedBy, Regex, ParserElement +# Enable packrat parsing +ParserElement.enablePackrat() from matplotlib.afm import AFM from matplotlib.cbook import Bunch, get_realpath_and_stat, \ @@ -1982,7 +1984,7 @@ autoDelim = Forward().setParseAction(self.auto_sized_delimiter) self._expression = Forward().setParseAction(self.finish).setName("finish") - float = Regex(r"-?[0-9]+\.?[0-9]*") + float = Regex(r"-?[0-9]*(\.[0-9]+)?") lbrace = Literal('{').suppress() rbrace = Literal('}').suppress() @@ -2001,14 +2003,13 @@ latex2efont = oneOf(['math' + x for x in self._fontnames]) space =(FollowedBy(bslash) - + (Literal(r'\ ') - | Literal(r'\/') - | Literal(r',円') - | Literal(r'\;') - | Literal(r'\quad') - | Literal(r'\qquad') - | Literal(r'\!') - ) + + oneOf([r'\ ', + r'\/', + r',円', + r'\;', + r'\quad', + r'\qquad', + r'\!']) ).setParseAction(self.space).setName('space') customspace =(Literal(r'\hspace') @@ -2055,19 +2056,13 @@ + latex2efont) frac = Group( - Suppress( - bslash - + Literal("frac") - ) + Suppress(Literal(r"\frac")) + ((group + group) | Error(r"Expected \frac{num}{den}")) ).setParseAction(self.frac).setName("frac") sqrt = Group( - Suppress( - bslash - + Literal("sqrt") - ) + Suppress(Literal(r"\sqrt")) + Optional( Suppress(Literal("[")) + Group( @@ -2096,9 +2091,7 @@ | subsuper ) - subsuperop =(Literal("_") - | Literal("^") - ) + subsuperop = oneOf(["_", "^"]) subsuper << Group( ( Optional(placeable) @@ -2127,8 +2120,7 @@ ^ simple ).setParseAction(self.math).setName("math") - math_delim =(~bslash - + Literal('$')) + math_delim = ~bslash + Literal('$') non_math = Regex(r"(?:(?:\\[$])|[^$])*" ).setParseAction(self.non_math).setName("non_math").leaveWhitespace() @@ -2144,8 +2136,6 @@ ) ) + StringEnd() - self._expression.enablePackrat() - self.clear() def clear(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4724 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4724&view=rev Author: mdboom Date: 2007年12月13日 10:13:04 -0800 (2007年12月13日) Log Message: ----------- Clarify comment. Modified Paths: -------------- branches/transforms/lib/matplotlib/patches.py Modified: branches/transforms/lib/matplotlib/patches.py =================================================================== --- branches/transforms/lib/matplotlib/patches.py 2007年12月13日 18:12:51 UTC (rev 4723) +++ branches/transforms/lib/matplotlib/patches.py 2007年12月13日 18:13:04 UTC (rev 4724) @@ -910,8 +910,8 @@ class Arc(Ellipse): """ - An elliptical arc. Because it performs various optimizations, it may not be - filled. + An elliptical arc. Because it performs various optimizations, it + can not be filled. """ def __str__(self): return "Arc(%d,%d;%dx%d)"%(self.center[0],self.center[1],self.width,self.height) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4722 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4722&view=rev Author: jdh2358 Date: 2007年12月13日 10:12:11 -0800 (2007年12月13日) Log Message: ----------- added gtktools and exceltools to toolkits Added Paths: ----------- trunk/matplotlib/lib/matplotlib/toolkits/exceltools.py trunk/matplotlib/lib/matplotlib/toolkits/gtktools.py Added: trunk/matplotlib/lib/matplotlib/toolkits/exceltools.py =================================================================== --- trunk/matplotlib/lib/matplotlib/toolkits/exceltools.py (rev 0) +++ trunk/matplotlib/lib/matplotlib/toolkits/exceltools.py 2007年12月13日 18:12:11 UTC (rev 4722) @@ -0,0 +1,120 @@ +""" +Some io tools for excel -- requires pypyExcelerator + +Example usage: + + import matplotlib.mlab as mlab + import matplotlib.toolkits.exceltools as exceltools + + r = mlab.csv2rec('somefile.csv', checkrows=0) + + formatd = dict( + weight = mlab.FormatFloat(2), + change = mlab.FormatPercent(2), + cost = mlab.FormatThousands(2), + ) + + + exceltools.rec2excel(r, 'test.xls', formatd=formatd) + mlab.rec2csv(r, 'test.csv', formatd=formatd) + +""" +import copy +import numpy as npy +import pyExcelerator as excel +import matplotlib.cbook as cbook +import matplotlib.mlab as mlab + + +def xlformat_factory(format): + """ + copy the format, perform any overrides, and attach an xlstyle instance + copied format is returned + """ + format = copy.deepcopy(format) + + + + xlstyle = excel.XFStyle() + if isinstance(format, mlab.FormatPercent): + zeros = ''.join(['0']*format.precision) + xlstyle.num_format_str = '0.%s%%;[RED]-0.%s%%'%(zeros, zeros) + format.scale = 1. + elif isinstance(format, mlab.FormatFloat): + zeros = ''.join(['0']*format.precision) + xlstyle.num_format_str = '#,##0.%s;[RED]-#,##0.%s'%(zeros, zeros) + elif isinstance(format, mlab.FormatInt): + xlstyle.num_format_str = '#,##;[RED]-#,##' + else: + xlstyle = None + + format.xlstyle = xlstyle + + return format + +def rec2excel(r, ws, formatd=None, rownum=0, colnum=0): + """ + save record array r to excel pyExcelerator worksheet ws + starting at rownum. if ws is string like, assume it is a + filename and save to it + + start writing at rownum, colnum + + formatd is a dictionary mapping dtype name -> mlab.Format instances + + The next rownum after writing is returned + """ + + autosave = False + if cbook.is_string_like(ws): + filename = ws + wb = excel.Workbook() + ws = wb.add_sheet('worksheet') + autosave = True + + + if formatd is None: + formatd = dict() + + formats = [] + font = excel.Font() + font.bold = True + + stylehdr = excel.XFStyle() + stylehdr.font = font + + for i, name in enumerate(r.dtype.names): + dt = r.dtype[name] + format = formatd.get(name) + if format is None: + format = mlab.defaultformatd.get(dt.type, mlab.FormatObj()) + + format = xlformat_factory(format) + ws.write(rownum, colnum+i, name, stylehdr) + formats.append(format) + + rownum+=1 + + + ind = npy.arange(len(r.dtype.names)) + for row in r: + for i in ind: + val = row[i] + format = formats[i] + val = format.toval(val) + if format.xlstyle is None: + ws.write(rownum, colnum+i, val) + else: + if mlab.safe_isnan(val): + ws.write(rownum, colnum+i, 'NaN') + else: + ws.write(rownum, colnum+i, val, format.xlstyle) + rownum += 1 + + if autosave: + wb.save(filename) + return rownum + + + + Added: trunk/matplotlib/lib/matplotlib/toolkits/gtktools.py =================================================================== --- trunk/matplotlib/lib/matplotlib/toolkits/gtktools.py (rev 0) +++ trunk/matplotlib/lib/matplotlib/toolkits/gtktools.py 2007年12月13日 18:12:11 UTC (rev 4722) @@ -0,0 +1,299 @@ +""" + +Some gtk specific tools and widgets + + * rec2gtk : put record array in GTK treeview - requires gtk + +Example usage + + import matplotlib.mlab as mlab + import matplotlib.toolkits.gtktools as gtktools + + r = mlab.csv2rec('somefile.csv', checkrows=0) + + formatd = dict( + weight = mlab.FormatFloat(2), + change = mlab.FormatPercent(2), + cost = mlab.FormatThousands(2), + ) + + + exceltools.rec2excel(r, 'test.xls', formatd=formatd) + mlab.rec2csv(r, 'test.csv', formatd=formatd) + + + import gtk + scroll = gtktools.rec2gtk(r, formatd=formatd) + win = gtk.Window() + win.set_size_request(600,800) + win.add(scroll) + win.show_all() + gtk.main() + +""" +import copy +import gtk, gobject +import numpy as npy +import matplotlib.cbook as cbook +import matplotlib.mlab as mlab + +def gtkformat_factory(format, colnum): + """ + copy the format, perform any overrides, and attach an gtk style attrs + + + xalign = 0. + cell = None + + """ + + format = copy.copy(format) + format.xalign = 0. + format.cell = None + + def negative_red_cell(column, cell, model, thisiter): + val = model.get_value(thisiter, colnum) + try: val = float(val) + except: cell.set_property('foreground', 'black') + else: + if val<0: + cell.set_property('foreground', 'red') + else: + cell.set_property('foreground', 'black') + + + if isinstance(format, mlab.FormatFloat) or isinstance(format, mlab.FormatInt): + format.cell = negative_red_cell + format.xalign = 1. + elif isinstance(format, mlab.FormatDate): + format.xalign = 1. + return format + + + +class SortedStringsScrolledWindow(gtk.ScrolledWindow): + """ + A simple treeview/liststore assuming all columns are strings. + Supports ascending/descending sort by clicking on column header + """ + + def __init__(self, colheaders, formatterd=None): + """ + xalignd if not None, is a dict mapping col header to xalignent (default 1) + + formatterd if not None, is a dict mapping col header to a ColumnFormatter + """ + + + gtk.ScrolledWindow.__init__(self) + self.colheaders = colheaders + self.seq = None # not initialized with accts + self.set_shadow_type(gtk.SHADOW_ETCHED_IN) + self.set_policy(gtk.POLICY_AUTOMATIC, + gtk.POLICY_AUTOMATIC) + + types = [gobject.TYPE_STRING] * len(colheaders) + model = self.model = gtk.ListStore(*types) + + + treeview = gtk.TreeView(self.model) + treeview.show() + treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE) + treeview.set_rules_hint(True) + + + class Clicked: + def __init__(self, parent, i): + self.parent = parent + self.i = i + self.num = 0 + + def __call__(self, column): + ind = [] + dsu = [] + for rownum, thisiter in enumerate(self.parent.iters): + val = model.get_value(thisiter, self.i) + try: val = float(val.strip().rstrip('%')) + except ValueError: pass + if npy.isnan(val): val = npy.inf # force nan to sort uniquely + dsu.append((val, rownum)) + dsu.sort() + if not self.num%2: dsu.reverse() + + vals, otherind = zip(*dsu) + ind.extend(otherind) + + self.parent.model.reorder(ind) + newiters = [] + for i in ind: + newiters.append(self.parent.iters[i]) + self.parent.iters = newiters[:] + for i, thisiter in enumerate(self.parent.iters): + key = tuple([self.parent.model.get_value(thisiter, j) for j in range(len(colheaders))]) + self.parent.rownumd[i] = key + + self.num+=1 + + + if formatterd is None: + formatterd = dict() + + formatterd = formatterd.copy() + + for i, header in enumerate(colheaders): + renderer = gtk.CellRendererText() + if header not in formatterd: + formatterd[header] = ColumnFormatter() + formatter = formatterd[header] + + column = gtk.TreeViewColumn(header, renderer, text=i) + renderer.set_property('xalign', formatter.xalign) + column.connect('clicked', Clicked(self, i)) + column.set_property('clickable', True) + + if formatter.cell is not None: + column.set_cell_data_func(renderer, formatter.cell) + + treeview.append_column(column) + + + + self.formatterd = formatterd + self.lastcol = column + self.add(treeview) + self.treeview = treeview + self.clear() + + def clear(self): + self.iterd = dict() + self.iters = [] # an ordered list of iters + self.rownumd = dict() # a map from rownum -> symbol + self.model.clear() + self.datad = dict() + + + def flat(self, row): + seq = [] + for i,val in enumerate(row): + formatter = self.formatterd.get(self.colheaders[i]) + seq.extend([i,formatter.tostr(val)]) + return seq + + def __delete_selected(self, *unused): # untested + + + keyd = dict([(thisiter, key) for key, thisiter in self.iterd.values()]) + for row in self.get_selected(): + key = tuple(row) + thisiter = self.iterd[key] + self.model.remove(thisiter) + del self.datad[key] + del self.iterd[key] + self.iters.remove(thisiter) + + for i, thisiter in enumerate(self.iters): + self.rownumd[i] = keyd[thisiter] + + + + def delete_row(self, row): + key = tuple(row) + thisiter = self.iterd[key] + self.model.remove(thisiter) + + + del self.datad[key] + del self.iterd[key] + self.rownumd[len(self.iters)] = key + self.iters.remove(thisiter) + + for rownum, thiskey in self.rownumd.items(): + if thiskey==key: del self.rownumd[rownum] + + def add_row(self, row): + thisiter = self.model.append() + self.model.set(thisiter, *self.flat(row)) + key = tuple(row) + self.datad[key] = row + self.iterd[key] = thisiter + self.rownumd[len(self.iters)] = key + self.iters.append(thisiter) + + def update_row(self, rownum, newrow): + key = self.rownumd[rownum] + thisiter = self.iterd[key] + newkey = tuple(newrow) + + self.rownumd[rownum] = newkey + del self.datad[key] + del self.iterd[key] + self.datad[newkey] = newrow + self.iterd[newkey] = thisiter + + + self.model.set(thisiter, *self.flat(newrow)) + + def get_row(self, rownum): + key = self.rownumd[rownum] + return self.datad[key] + + def get_selected(self): + selected = [] + def foreach(model, path, iter, selected): + selected.append(model.get_value(iter, 0)) + + self.treeview.get_selection().selected_foreach(foreach, selected) + return selected + + + +def rec2gtk(r, formatd=None, rownum=0, autowin=True): + """ + save record array r to excel pyExcelerator worksheet ws + starting at rownum. if ws is string like, assume it is a + filename and save to it + + formatd is a dictionary mapping dtype name -> mlab.Format instances + + This function creates a SortedStringsScrolledWindow (derived + from gtk.ScrolledWindow) and returns it. if autowin is True, + a gtk.Window is created, attached to the + SortedStringsScrolledWindow instance, shown and returned. If + autowin=False, the caller is responsible for adding the + SortedStringsScrolledWindow instance to a gtk widget and + showing it. + """ + + + + if formatd is None: + formatd = dict() + + formats = [] + for i, name in enumerate(r.dtype.names): + dt = r.dtype[name] + format = formatd.get(name) + if format is None: + format = mlab.defaultformatd.get(dt.type, mlab.FormatObj()) + #print 'gtk fmt factory', i, name, format, type(format) + format = gtkformat_factory(format, i) + formatd[name] = format + + + colheaders = r.dtype.names + scroll = SortedStringsScrolledWindow(colheaders, formatd) + + ind = npy.arange(len(r.dtype.names)) + for row in r: + scroll.add_row(row) + + + if autowin: + win = gtk.Window() + win.set_default_size(800,600) + win.add(scroll) + win.show_all() + scroll.win = win + + return scroll + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.