Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b125cc

Browse files
author
James Evans
committed
Updated 'fill' to handle unitized data. Added a unit-test for it.
svn path=/trunk/matplotlib/; revision=7020
1 parent 67d3ece commit 0b125cc

4 files changed

Lines changed: 92 additions & 7 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,10 @@ def _xy_from_xy(self, x, y):
216216
if self.axes.xaxis is not None and self.axes.yaxis is not None:
217217
bx = self.axes.xaxis.update_units(x)
218218
by = self.axes.yaxis.update_units(y)
219-
# right now multicol is not supported if either x or y are
220-
# unit enabled but this can be fixed..
221-
if bx or by: return x, y, False
219+
if bx:
220+
x = self.axes.convert_xunits(x)
221+
if by:
222+
y = self.axes.convert_yunits(y)
222223

223224
x = ma.asarray(x)
224225
y = ma.asarray(y)
@@ -310,8 +311,6 @@ def makeline(x, y):
310311
ret.append(seg)
311312

312313
def makefill(x, y):
313-
x = self.axes.convert_xunits(x)
314-
y = self.axes.convert_yunits(y)
315314
facecolor = self._get_next_cycle_color()
316315
seg = mpatches.Polygon(np.hstack(
317316
(x[:,np.newaxis],y[:,np.newaxis])),
@@ -358,8 +357,6 @@ def makeline(x, y):
358357

359358
def makefill(x, y):
360359
facecolor = color
361-
x = self.axes.convert_xunits(x)
362-
y = self.axes.convert_yunits(y)
363360
seg = mpatches.Polygon(np.hstack(
364361
(x[:,np.newaxis],y[:,np.newaxis])),
365362
facecolor = facecolor,

test/mplTest/units/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def register():
7171

7272
# Angles
7373
deg = UnitDbl( 1.0, "deg" )
74+
rad = UnitDbl( 1.0, "rad" )
7475

7576
# Time
7677
sec = UnitDbl( 1.0, "sec" )

test/test_plots/TestFill.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#=======================================================================
2+
"""The Fill unit-test class implementation."""
3+
#=======================================================================
4+
5+
from mplTest import *
6+
7+
#=======================================================================
8+
# Add import modules below.
9+
import matplotlib
10+
matplotlib.use( "Agg", warn = False )
11+
12+
import pylab
13+
import numpy as npy
14+
from datetime import datetime
15+
#
16+
#=======================================================================
17+
18+
#=======================================================================
19+
class TestFill( MplTestCase ):
20+
"""Test the various axes fill methods."""
21+
22+
# Uncomment any appropriate tags
23+
tags = [
24+
# 'gui', # requires the creation of a gui window
25+
'agg', # uses agg in the backend
26+
'agg-only', # uses only agg in the backend
27+
# 'wx', # uses wx in the backend
28+
# 'qt', # uses qt in the backend
29+
# 'ps', # uses the postscript backend
30+
# 'units', # uses units in the test
31+
'PIL', # uses PIL for image comparison
32+
]
33+
34+
#--------------------------------------------------------------------
35+
def setUp( self ):
36+
"""Setup any data needed for the unit test."""
37+
units.register()
38+
39+
#--------------------------------------------------------------------
40+
def tearDown( self ):
41+
"""Clean-up any generated files here."""
42+
pass
43+
44+
#--------------------------------------------------------------------
45+
def test_fill_units( self ):
46+
"""Test the fill method with unitized-data."""
47+
48+
fname = self.outFile( "fill_units.png" )
49+
50+
# generate some data
51+
t = units.Epoch( "ET", dt=datetime(2009, 4, 27) )
52+
value = 10.0 * units.deg
53+
day = units.Duration( "ET", 24.0 * 60.0 * 60.0 )
54+
55+
fig = pylab.figure()
56+
57+
# Top-Left
58+
ax1 = fig.add_subplot( 221 )
59+
ax1.plot( [t], [value], yunits='deg', color='red' )
60+
ax1.fill( [733525.0, 733525.0, 733526.0, 733526.0],
61+
[0.0, 0.0, 90.0, 0.0], 'b' )
62+
63+
# Top-Right
64+
ax2 = fig.add_subplot( 222 )
65+
ax2.plot( [t], [value], yunits='deg', color='red' )
66+
ax2.fill( [t, t, t+day, t+day],
67+
[0.0, 0.0, 90.0, 0.0], 'b' )
68+
69+
# Bottom-Left
70+
ax3 = fig.add_subplot( 223 )
71+
ax3.plot( [t], [value], yunits='deg', color='red' )
72+
ax1.fill( [733525.0, 733525.0, 733526.0, 733526.0],
73+
[0*units.deg, 0*units.deg, 90*units.deg, 0*units.deg], 'b' )
74+
75+
# Bottom-Right
76+
ax4 = fig.add_subplot( 224 )
77+
ax4.plot( [t], [value], yunits='deg', color='red' )
78+
ax4.fill( [t, t, t+day, t+day],
79+
[0*units.deg, 0*units.deg, 90*units.deg, 0*units.deg],
80+
facecolor="blue" )
81+
82+
fig.autofmt_xdate()
83+
fig.savefig( fname )
84+
self.checkImage( fname )
85+
86+
#--------------------------------------------------------------------
87+
59 KB
Loading

0 commit comments

Comments
 (0)