From: <jr...@us...> - 2009-04-01 17:28:21
|
Revision: 7020 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7020&view=rev Author: jrevans Date: 2009-04-01 17:28:11 +0000 (Wed, 01 Apr 2009) Log Message: ----------- Updated 'fill' to handle unitized data. Added a unit-test for it. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/test/mplTest/units/__init__.py Added Paths: ----------- trunk/matplotlib/test/test_plots/TestFill.py trunk/matplotlib/test/test_plots/baseline/TestFill/ trunk/matplotlib/test/test_plots/baseline/TestFill/fill_units.png Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-03-31 17:59:53 UTC (rev 7019) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-04-01 17:28:11 UTC (rev 7020) @@ -216,9 +216,10 @@ if self.axes.xaxis is not None and self.axes.yaxis is not None: bx = self.axes.xaxis.update_units(x) by = self.axes.yaxis.update_units(y) - # right now multicol is not supported if either x or y are - # unit enabled but this can be fixed.. - if bx or by: return x, y, False + if bx: + x = self.axes.convert_xunits(x) + if by: + y = self.axes.convert_yunits(y) x = ma.asarray(x) y = ma.asarray(y) @@ -310,8 +311,6 @@ ret.append(seg) def makefill(x, y): - x = self.axes.convert_xunits(x) - y = self.axes.convert_yunits(y) facecolor = self._get_next_cycle_color() seg = mpatches.Polygon(np.hstack( (x[:,np.newaxis],y[:,np.newaxis])), @@ -358,8 +357,6 @@ def makefill(x, y): facecolor = color - x = self.axes.convert_xunits(x) - y = self.axes.convert_yunits(y) seg = mpatches.Polygon(np.hstack( (x[:,np.newaxis],y[:,np.newaxis])), facecolor = facecolor, Modified: trunk/matplotlib/test/mplTest/units/__init__.py =================================================================== --- trunk/matplotlib/test/mplTest/units/__init__.py 2009-03-31 17:59:53 UTC (rev 7019) +++ trunk/matplotlib/test/mplTest/units/__init__.py 2009-04-01 17:28:11 UTC (rev 7020) @@ -71,6 +71,7 @@ # Angles deg = UnitDbl( 1.0, "deg" ) +rad = UnitDbl( 1.0, "rad" ) # Time sec = UnitDbl( 1.0, "sec" ) Added: trunk/matplotlib/test/test_plots/TestFill.py =================================================================== --- trunk/matplotlib/test/test_plots/TestFill.py (rev 0) +++ trunk/matplotlib/test/test_plots/TestFill.py 2009-04-01 17:28:11 UTC (rev 7020) @@ -0,0 +1,87 @@ +#======================================================================= +"""The Fill unit-test class implementation.""" +#======================================================================= + +from mplTest import * + +#======================================================================= +# Add import modules below. +import matplotlib +matplotlib.use( "Agg", warn = False ) + +import pylab +import numpy as npy +from datetime import datetime +# +#======================================================================= + +#======================================================================= +class TestFill( MplTestCase ): + """Test the various axes fill methods.""" + + # Uncomment any appropriate tags + tags = [ + # 'gui', # requires the creation of a gui window + 'agg', # uses agg in the backend + 'agg-only', # uses only agg in the backend + # 'wx', # uses wx in the backend + # 'qt', # uses qt in the backend + # 'ps', # uses the postscript backend + # 'units', # uses units in the test + 'PIL', # uses PIL for image comparison + ] + + #-------------------------------------------------------------------- + def setUp( self ): + """Setup any data needed for the unit test.""" + units.register() + + #-------------------------------------------------------------------- + def tearDown( self ): + """Clean-up any generated files here.""" + pass + + #-------------------------------------------------------------------- + def test_fill_units( self ): + """Test the fill method with unitized-data.""" + + fname = self.outFile( "fill_units.png" ) + + # generate some data + t = units.Epoch( "ET", dt=datetime(2009, 4, 27) ) + value = 10.0 * units.deg + day = units.Duration( "ET", 24.0 * 60.0 * 60.0 ) + + fig = pylab.figure() + + # Top-Left + ax1 = fig.add_subplot( 221 ) + ax1.plot( [t], [value], yunits='deg', color='red' ) + ax1.fill( [733525.0, 733525.0, 733526.0, 733526.0], + [0.0, 0.0, 90.0, 0.0], 'b' ) + + # Top-Right + ax2 = fig.add_subplot( 222 ) + ax2.plot( [t], [value], yunits='deg', color='red' ) + ax2.fill( [t, t, t+day, t+day], + [0.0, 0.0, 90.0, 0.0], 'b' ) + + # Bottom-Left + ax3 = fig.add_subplot( 223 ) + ax3.plot( [t], [value], yunits='deg', color='red' ) + ax1.fill( [733525.0, 733525.0, 733526.0, 733526.0], + [0*units.deg, 0*units.deg, 90*units.deg, 0*units.deg], 'b' ) + + # Bottom-Right + ax4 = fig.add_subplot( 224 ) + ax4.plot( [t], [value], yunits='deg', color='red' ) + ax4.fill( [t, t, t+day, t+day], + [0*units.deg, 0*units.deg, 90*units.deg, 0*units.deg], + facecolor="blue" ) + + fig.autofmt_xdate() + fig.savefig( fname ) + self.checkImage( fname ) + + #-------------------------------------------------------------------- + Added: trunk/matplotlib/test/test_plots/baseline/TestFill/fill_units.png =================================================================== (Binary files differ) Property changes on: trunk/matplotlib/test/test_plots/baseline/TestFill/fill_units.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |