Skip to content

Commit c1b7db3

Browse files
committed
minor cleanup of units example, added some to backend driver, more to be fixed
svn path=/trunk/matplotlib/; revision=5850
1 parent 7e2a8fb commit c1b7db3

10 files changed

+47
-28
lines changed

examples/tests/backend_driver.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,23 @@
121121
'color_cycle.py',
122122
]
123123

124+
units_dir = os.path.join('..', 'units')
125+
units_files = [
126+
'annotate_with_units.py',
127+
#'artist_tests.py', # broken, fixme
128+
'bar_demo2.py',
129+
#'bar_unit_demo.py', # broken, fixme
130+
#'ellipse_with_units.py', # broken, fixme
131+
'radian_demo.py',
132+
'units_sample.py',
133+
#'units_scatter.py', # broken, fixme
134+
135+
]
124136

125137
files = [os.path.join(pylab_dir, fname) for fname in pylab_files] +\
126-
[os.path.join(api_dir, fname) for fname in api_files]
138+
[os.path.join(api_dir, fname) for fname in api_files] +\
139+
[os.path.join(units_dir, fname) for fname in units_files]
140+
127141
# tests known to fail on a given backend
128142

129143

examples/units/artist_tests.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import matplotlib.units as units
1515

1616
from basic_units import cm, inch
17-
18-
from pylab import figure, show, nx
17+
import numpy as np
18+
from pylab import figure, show
1919

2020
fig = figure()
2121
ax = fig.add_subplot(111)
@@ -26,7 +26,7 @@
2626
verts = []
2727
for i in range(10):
2828
# a random line segment in inches
29-
verts.append(zip(*inch*10*nx.mlab.rand(2, random.randint(2,15))))
29+
verts.append(zip(*inch*10*np.random.rand(2, random.randint(2,15))))
3030
lc = collections.LineCollection(verts, axes=ax)
3131
ax.add_collection(lc)
3232

examples/units/bar_demo2.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
units)
88
99
"""
10+
import numpy as np
1011
from basic_units import cm, inch
11-
from pylab import figure, show, nx
12+
from pylab import figure, show
1213

13-
cms = cm *nx.arange(0, 10, 2)
14+
cms = cm *np.arange(0, 10, 2)
1415
bottom=0*cm
1516
width=0.8*cm
1617

examples/units/bar_unit_demo.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
2+
import numpy as np
23
from basic_units import cm, inch
3-
from pylab import figure, show,nx
4+
from pylab import figure, show
45

56
N = 5
67
menMeans = (150*cm, 160*cm, 146*cm, 172*cm, 155*cm)
@@ -9,7 +10,7 @@
910
fig = figure()
1011
ax = fig.add_subplot(111)
1112

12-
ind = nx.arange(N) # the x locations for the groups
13+
ind = np.arange(N) # the x locations for the groups
1314
width = 0.35 # the width of the bars
1415
p1 = ax.bar(ind, menMeans, width, color='r', bottom=0*cm, yerr=menStd)
1516

examples/units/basic_units.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import math
2-
2+
import numpy as np
33

44
import matplotlib.units as units
55
import matplotlib.ticker as ticker
6-
import matplotlib.numerix as nx
76
from matplotlib.axes import Axes
87
from matplotlib.cbook import iterable
98

@@ -122,7 +121,7 @@ def __init__(self, value, unit):
122121
self.proxy_target = self.value
123122

124123
def get_compressed_copy(self, mask):
125-
compressed_value = nx.ma.masked_array(self.value, mask=mask).compressed()
124+
compressed_value = np.ma.masked_array(self.value, mask=mask).compressed()
126125
return TaggedValue(compressed_value, self.unit)
127126

128127
def __getattribute__(self, name):
@@ -135,9 +134,9 @@ def __getattribute__(self, name):
135134

136135
def __array__(self, t = None, context = None):
137136
if t is not None:
138-
return nx.asarray(self.value).astype(t)
137+
return np.asarray(self.value).astype(t)
139138
else:
140-
return nx.asarray(self.value, 'O')
139+
return np.asarray(self.value, 'O')
141140

142141
def __array_wrap__(self, array, context):
143142
return TaggedValue(array, self.unit)
@@ -159,7 +158,7 @@ def next(self):
159158
return IteratorProxy(iter(self.value), self.unit)
160159

161160
def get_compressed_copy(self, mask):
162-
new_value = nx.ma.masked_array(self.value, mask=mask).compressed()
161+
new_value = np.ma.masked_array(self.value, mask=mask).compressed()
163162
return TaggedValue(new_value, self.unit)
164163

165164
def convert_to(self, unit):
@@ -211,7 +210,7 @@ def __array_wrap__(self, array, context):
211210
return TaggedValue(array, self)
212211

213212
def __array__(self, t=None, context=None):
214-
ret = nx.array([1])
213+
ret = np.array([1])
215214
if t is not None:
216215
return ret.astype(t)
217216
else:
@@ -275,8 +274,8 @@ def __call__(self, operation, units):
275274

276275
radians = BasicUnit('rad', 'radians')
277276
degrees = BasicUnit('deg', 'degrees')
278-
radians.add_conversion_factor(degrees, 180.0/nx.pi)
279-
degrees.add_conversion_factor(radians, nx.pi/180.0)
277+
radians.add_conversion_factor(degrees, 180.0/np.pi)
278+
degrees.add_conversion_factor(radians, np.pi/180.0)
280279

281280
secs = BasicUnit('s', 'seconds')
282281
hertz = BasicUnit('Hz', 'Hertz')
@@ -287,7 +286,7 @@ def __call__(self, operation, units):
287286

288287
# radians formatting
289288
def rad_fn(x,pos=None):
290-
n = int((x / nx.pi) * 2.0 + 0.25)
289+
n = int((x / np.pi) * 2.0 + 0.25)
291290
if n == 0:
292291
return '0'
293292
elif n == 1:
@@ -307,7 +306,7 @@ def axisinfo(unit):
307306

308307
if unit==radians:
309308
return units.AxisInfo(
310-
majloc=ticker.MultipleLocator(base=nx.pi/2),
309+
majloc=ticker.MultipleLocator(base=np.pi/2),
311310
majfmt=ticker.FuncFormatter(rad_fn),
312311
label=unit.fullname,
313312
)

examples/units/evans_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from matplotlib.cbook import iterable
1212
import matplotlib.units as units
1313
import matplotlib.ticker as ticker
14-
from pylab import figure, show, nx
14+
from pylab import figure, show
1515

1616
class Foo:
1717
def __init__( self, val, unit=1.0 ):

examples/units/evans_test2.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
This example shows how the unit class can determine the tick locating,
44
formatting and axis labeling.
55
"""
6+
import numpy as np
67
from basic_units import radians, degrees, cos
7-
from pylab import figure, show, nx
8+
from pylab import figure, show
89
from matplotlib.cbook import iterable
910
import math
1011

1112

12-
x = nx.arange(0, 15, 0.01) * radians
13+
x = np.arange(0, 15, 0.01) * radians
1314

1415

1516
fig = figure()

examples/units/radian_demo.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import numpy as np
12
from basic_units import radians, degrees, cos
2-
from pylab import figure, show, nx
3+
from pylab import figure, show
34

4-
x = nx.arange(0, 15, 0.01) * radians
5+
x = np.arange(0, 15, 0.01) * radians
56

67
fig = figure()
78
fig.subplots_adjust(hspace=0.3)

examples/units/units_scatter.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
The example below shows support for unit conversions over masked
99
arrays.
1010
"""
11+
import numpy as np
1112
from basic_units import secs, hertz, minutes
12-
from matplotlib.pylab import figure, show, nx
13+
from matplotlib.pylab import figure, show
1314

1415
# create masked array
1516

16-
xsecs = secs*nx.ma.MaskedArray((1,2,3,4,5,6,7,8), nx.Float, mask=(1,0,1,0,0,0,1,0))
17-
#xsecs = secs*nx.arange(1,10.)
17+
18+
xsecs = secs*np.ma.MaskedArray((1,2,3,4,5,6,7,8), (1,0,1,0,0,0,1,0), np.float)
19+
#xsecs = secs*np.arange(1,10.)
1820

1921
fig = figure()
2022
ax1 = fig.add_subplot(3,1,1)

unit/memleak_hawaii3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os, sys, time, gc
44
import matplotlib
5-
matplotlib.use('PDF')
5+
matplotlib.use('Agg')
66

77
from matplotlib.cbook import report_memory
88
import numpy as np

0 commit comments

Comments
 (0)