Skip to content

Commit 0df13d7

Browse files
committed
Increased coverage of backend_driver.py to include almost everything
in axes.py. Lots of little bug fixes. svn path=/branches/transforms/; revision=4004
1 parent e573c25 commit 0df13d7

22 files changed

+239
-338
lines changed

PASSED_DEMOS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ dynamic_demo.py O
6060
dynamic_demo_wx.py [REQUIRES NON-AGG WX RENDERER, WHICH IS NOT YET IMPLEMENTED]
6161
dynamic_image_gtkagg.py O
6262
dynamic_image_wxagg2.py O
63-
dynamic_image_wxagg.py
63+
dynamic_image_wxagg.py [REQUIRES NON-AGG WX RENDERER, WHICH IS NOT YET IMPLEMENTED]
6464
ellipse_demo.py O
6565
ellipse_rotated.py O
6666
embedding_in_gtk2.py [REQUIRES NON-AGG GDK RENDERER, WHICH IS NOT YET IMPLEMENTED]

examples/arrow_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):
280280

281281
if __name__ == '__main__':
282282
from sys import argv
283+
d = None
283284
if len(argv) > 1:
284285
if argv[1] == 'full':
285286
d = all_on_max
@@ -293,7 +294,7 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):
293294
elif argv[1] == 'sample':
294295
d = sample_data
295296
scaled = True
296-
else:
297+
if d is None:
297298
d = all_on_max
298299
scaled=False
299300
if len(argv) > 2:

examples/backend_driver.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,33 @@
2222
files = (
2323
'alignment_test.py',
2424
'arctest.py',
25+
'arrow_demo.py',
2526
'axes_demo.py',
27+
'axhspan_demo.py',
2628
'bar_stacked.py',
2729
'barchart_demo.py',
30+
'boxplot_demo.py',
31+
'broken_barh.py',
32+
'barh_demo.py',
2833
'color_demo.py',
34+
'colorbar_only.py',
2935
'contour_demo.py',
3036
'contourf_demo.py',
3137
'csd_demo.py',
3238
'custom_ticker1.py',
3339
'customize_rc.py',
3440
'date_demo1.py',
3541
'date_demo2.py',
42+
'equal_aspect_ratio.py',
43+
'errorbar_limits.py',
3644
'figimage_demo.py',
3745
'figlegend_demo.py',
3846
'figtext.py',
3947
'fill_demo.py',
4048
'finance_demo.py',
4149
'fonts_demo_kw.py',
4250
'histogram_demo.py',
51+
'hline_demo.py',
4352
'image_demo.py',
4453
'image_demo2.py',
4554
'image_masked.py',
@@ -66,11 +75,18 @@
6675
'polar_demo.py',
6776
'polar_scatter.py',
6877
'psd_demo.py',
78+
'quadmesh_demo.py',
6979
'quiver_demo.py',
7080
'scatter_demo.py',
7181
'scatter_demo2.py',
82+
'scatter_star_poly.py',
83+
'shared_axis_demo.py',
84+
'shared_axis_across_figures.py',
7285
'simple_plot.py',
7386
'specgram_demo.py',
87+
'spy_demos.py',
88+
'stem_plot.py',
89+
'step_demo.py',
7490
'stock_demo.py',
7591
'subplot_demo.py',
7692
# 'set_and_get.py',
@@ -104,7 +120,7 @@ def run(arglist):
104120
def run(arglist):
105121
os.system(' '.join(arglist))
106122

107-
def drive(backend, python='python', switches = []):
123+
def drive(backend, python=['python'], switches = []):
108124

109125
exclude = failbackend.get(backend, [])
110126
switchstring = ' '.join(switches)
@@ -151,17 +167,20 @@ def drive(backend, python='python', switches = []):
151167
tmpfile.write('savefig("%s", dpi=150)' % outfile)
152168

153169
tmpfile.close()
154-
run([python, tmpfile_name, switchstring])
170+
run(python + [tmpfile_name, switchstring])
155171
#os.system('%s %s %s' % (python, tmpfile_name, switchstring))
156172
os.remove(tmpfile_name)
157173

158174
if __name__ == '__main__':
159175
times = {}
160176
default_backends = ['Agg', 'PS', 'SVG', 'PDF', 'Template']
161-
if sys.platform == 'win32':
162-
python = r'c:\Python24\python.exe'
177+
if '--coverage' in sys.argv:
178+
python = ['coverage.py', '-x']
179+
sys.argv.remove('--coverage')
180+
elif sys.platform == 'win32':
181+
python = [r'c:\Python24\python.exe']
163182
else:
164-
python = 'python'
183+
python = ['python']
165184
all_backends = [b.lower() for b in mplbe.all_backends]
166185
all_backends.extend(['cairo.png', 'cairo.ps', 'cairo.pdf', 'cairo.svg'])
167186
backends = []

examples/equal_aspect_ratio.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
"""
3+
Example: simple line plot.
4+
Show how to make a plot that has equal aspect ratio
5+
"""
6+
from pylab import *
7+
8+
t = arange(0.0, 1.0+0.01, 0.01)
9+
s = cos(2*2*pi*t)
10+
plot(t, s, '-', lw=2)
11+
12+
xlabel('time (s)')
13+
ylabel('voltage (mV)')
14+
title('About as simple as it gets, folks')
15+
grid(True)
16+
17+
axes().set_aspect('equal', 'datalim')
18+
19+
20+
#savefig('simple_plot.png')
21+
savefig('equal_aspect')
22+
23+
show()

examples/hline_demo.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
from matplotlib.pyplot import *
3+
from numpy import sin, exp, absolute, pi, arange
4+
from numpy.random import normal
5+
6+
def f(t):
7+
s1 = sin(2*pi*t)
8+
e1 = exp(-t)
9+
return absolute((s1*e1))+.05
10+
11+
12+
t = arange(0.0, 5.0, 0.1)
13+
s = f(t)
14+
nse = normal(0.0, 0.3, t.shape) * s
15+
16+
plot(s+nse, t, 'b^')
17+
hlines(t, [0], s)
18+
xlabel('time (s)')
19+
title('Comparison of model with data')
20+
show()
21+

lib/matplotlib/artist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import division
2-
import sys, re
2+
import sys, re, warnings
33
from cbook import iterable, flatten
44
from transforms import Affine2D, Bbox, IdentityTransform, TransformedBbox, \
55
TransformedPath
@@ -174,7 +174,7 @@ def contains(self,mouseevent):
174174
"""
175175
if callable(self._contains): return self._contains(self,mouseevent)
176176
#raise NotImplementedError,str(self.__class__)+" needs 'contains' method"
177-
print str(self.__class__)+" needs 'contains' method"
177+
warnings.warn("'%s' needs 'contains' method" % self.__class__.__name__)
178178
return False,{}
179179

180180
def set_contains(self,picker):

lib/matplotlib/axes.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -821,16 +821,15 @@ def apply_aspect(self):
821821
Use self._aspect and self._adjustable to modify the
822822
axes box or the view limits.
823823
'''
824-
#MGDTODO: Numpify
825-
826-
if self._aspect == 'auto':
824+
aspect = self.get_aspect()
825+
if aspect == 'auto':
827826
self.set_position( self._originalPosition , 'active')
828827
return
829828

830-
if self._aspect == 'equal':
829+
if aspect == 'equal':
831830
A = 1
832831
else:
833-
A = self._aspect
832+
A = aspect
834833

835834
#Ensure at drawing time that any Axes involved in axis-sharing
836835
# does not have its position changed.
@@ -843,7 +842,7 @@ def apply_aspect(self):
843842
box_aspect = A * self.get_data_ratio()
844843
pb = self._originalPosition.frozen()
845844
pb1 = pb.shrunk_to_aspect(box_aspect, pb, fig_aspect)
846-
self.set_position(pb1.anchored(self._anchor, pb), 'active')
845+
self.set_position(pb1.anchored(self.get_anchor(), pb), 'active')
847846
return
848847

849848
xmin,xmax = self.get_xbound()
@@ -1040,7 +1039,7 @@ def add_artist(self, a):
10401039
a.set_clip_path(self.axesPatch)
10411040
a._remove_method = lambda h: self.artists.remove(h)
10421041

1043-
def add_collection(self, collection, autolim=False):
1042+
def add_collection(self, collection, autolim=True):
10441043
'add a Collection instance to Axes'
10451044
label = collection.get_label()
10461045
if not label:
@@ -1127,8 +1126,8 @@ def update_datalim_numerix(self, x, y):
11271126
self.ignore_existing_data_limits = False
11281127

11291128
def update_datalim_bounds(self, bounds):
1130-
# MGDTODO: Document me
1131-
self.dataLim.bounds = Bbox.union([self.dataLim, bounds]).bounds
1129+
'Update the datalim to include the given Bbox'
1130+
self.dataLim.set(Bbox.union([self.dataLim, bounds]))
11321131

11331132
def _get_verts_in_data_coords(self, trans, xys):
11341133
if trans == self.transData:
@@ -2017,8 +2016,9 @@ def __pick(self, x, y, trans=None, among=None):
20172016
Note this algorithm calculates distance to the vertices of the
20182017
polygon, so if you want to pick a patch, click on the edge!
20192018
"""
2019+
# MGDTODO: Needs updating
20202020
if trans is not None:
2021-
xywin = trans.xy_tup((x,y))
2021+
xywin = trans.transform_point((x,y))
20222022
else:
20232023
xywin = x,y
20242024

@@ -2036,12 +2036,12 @@ def dist_x_y(p1, x, y):
20362036
def dist(a):
20372037
if isinstance(a, Text):
20382038
bbox = a.get_window_extent()
2039-
l,b,w,h = bbox.get_bounds()
2039+
l,b,w,h = bbox.bounds
20402040
verts = (l,b), (l,b+h), (l+w,b+h), (l+w, b)
20412041
xt, yt = zip(*verts)
20422042
elif isinstance(a, Patch):
2043-
verts = a.get_verts()
2044-
tverts = a.get_transform().seq_xy_tups(verts)
2043+
path = a.get_path()
2044+
tverts = a.get_transform().transform_path(path)
20452045
xt, yt = zip(*tverts)
20462046
elif isinstance(a, mlines.Line2D):
20472047
xdata = a.get_xdata(orig=False)
@@ -3278,19 +3278,19 @@ def make_iterable(x):
32783278
self.hold(holdstate) # restore previous hold state
32793279

32803280
if adjust_xlim:
3281-
xmin, xmax = self.dataLim.intervalx().get_bounds()
3281+
xmin, xmax = self.dataLim.intervalx
32823282
xmin = npy.amin(width)
32833283
if xerr is not None:
32843284
xmin = xmin - npy.amax(xerr)
32853285
xmin = max(xmin*0.9, 1e-100)
3286-
self.dataLim.intervalx().set_bounds(xmin, xmax)
3286+
self.dataLim.intervalx = (xmin, xmax)
32873287
if adjust_ylim:
3288-
ymin, ymax = self.dataLim.intervaly().get_bounds()
3288+
ymin, ymax = self.dataLim.intervaly
32893289
ymin = npy.amin(height)
32903290
if yerr is not None:
32913291
ymin = ymin - npy.amax(yerr)
32923292
ymin = max(ymin*0.9, 1e-100)
3293-
self.dataLim.intervaly().set_bounds(ymin, ymax)
3293+
self.dataLim.intervaly = (ymin, ymax)
32943294
self.autoscale_view()
32953295
return patches
32963296
bar.__doc__ = cbook.dedent(bar.__doc__) % martist.kwdocd
@@ -4197,7 +4197,7 @@ def quiverkey(self, *args, **kw):
41974197

41984198
def quiver(self, *args, **kw):
41994199
q = mquiver.Quiver(self, *args, **kw)
4200-
self.add_collection(q)
4200+
self.add_collection(q, False)
42014201
self.update_datalim_numerix(q.X, q.Y)
42024202
self.autoscale_view()
42034203
return q
@@ -5170,6 +5170,7 @@ def get_geometry(self):
51705170
'get the subplot geometry, eg 2,2,3'
51715171
return self._rows, self._cols, self._num+1
51725172

5173+
# COVERAGE NOTE: Never used internally or from examples
51735174
def change_geometry(self, numrows, numcols, num):
51745175
'change subplot geometry, eg from 1,1,1 to 2,2,3'
51755176
self._rows = numrows
@@ -5238,6 +5239,7 @@ def is_last_row(self):
52385239
def is_last_col(self):
52395240
return self.colNum==self.numCols-1
52405241

5242+
# COVERAGE NOTE: Never used internally or from examples
52415243
def label_outer(self):
52425244
"""
52435245
set the visible property on ticklabels so xticklabels are

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
223223
baseline (descent), in display coords of the string s with
224224
FontPropertry prop
225225
"""
226-
return 1,1,1
226+
raise NotImplementedError
227227

228228
def new_gc(self):
229229
"""

lib/matplotlib/backends/backend_pdf.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,11 +1180,12 @@ def merge_used_characters(self, other):
11801180
def get_image_magnification(self):
11811181
return self.image_magnification
11821182

1183-
def draw_image(self, x, y, im, bbox):
1183+
def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
11841184
#print >>sys.stderr, "draw_image called"
11851185

1186+
# MGDTODO: Support clippath here
11861187
gc = self.new_gc()
1187-
gc.set_clip_rectangle(bbox.get_bounds())
1188+
gc.set_clip_rectangle(bbox.bounds)
11881189
self.check_gc(gc)
11891190

11901191
h, w = im.get_size_out()
@@ -1714,13 +1715,19 @@ def delta(self, other):
17141715
"""
17151716
cmds = []
17161717
for params, cmd in self.commands:
1717-
ours = [ getattr(self, p) for p in params ]
1718-
theirs = [ getattr(other, p) for p in params ]
1719-
try:
1720-
different = ours != theirs
1721-
except ValueError:
1722-
different = ours.shape != theirs.shape or npy.any(ours != theirs)
1723-
if ours is not theirs:
1718+
different = False
1719+
for p in params:
1720+
ours = getattr(self, p)
1721+
theirs = getattr(other, p)
1722+
try:
1723+
different = bool(ours != theirs)
1724+
except ValueError:
1725+
different = ours.shape != theirs.shape or npy.any(ours != theirs)
1726+
if different:
1727+
break
1728+
1729+
if different:
1730+
theirs = [getattr(other, p) for p in params]
17241731
cmds.extend(cmd(self, *theirs))
17251732
for p in params:
17261733
setattr(self, p, getattr(other, p))

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,12 +994,12 @@ def _print_figure_tex(self, outfile, format, dpi, facecolor, edgecolor,
994994
tmpfile = os.path.join(gettempdir(), md5.md5(outfile).hexdigest())
995995
fh = file(tmpfile, 'w')
996996

997-
self.figure.dpi.set(72) # ignore the dpi kwarg
997+
self.figure.dpi = 72 # ignore the dpi kwarg
998998
width, height = self.figure.get_size_inches()
999999
xo = 0
10001000
yo = 0
10011001

1002-
l, b, w, h = self.figure.bbox.get_bounds()
1002+
l, b, w, h = self.figure.bbox.bounds
10031003
llx = xo
10041004
lly = yo
10051005
urx = llx + w

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy