8000 Lots of minor fixes · matplotlib/matplotlib@548ddfa · GitHub
[go: up one dir, main page]

Skip to content

Commit 548ddfa

Browse files
committed
Lots of minor fixes
svn path=/branches/transforms/; revision=3859
1 parent 8dc255b commit 548ddfa

File tree

6 files changed

+158
-85
lines changed

6 files changed

+158
-85
lines changed

lib/matplotlib/lines.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,9 @@ def contains(self, mouseevent):
252252
if not is_numlike(self.pickradius):
253253
raise ValueError,"pick radius should be a distance"
254254

255-
if self._newstyle:
256-
# transform in backend
257-
x = self._x
258-
y = self._y
259-
else:
260-
x, y = self._get_plottable()
255+
# transform in backend
256+
x = self._x
257+
y = self._y
261258
if len(x)==0: return False,{}
262259

263260
xt, yt = self.get_transform().numerix_x_y(x, y)
@@ -337,7 +334,6 @@ def set_data(self, *args):
337334
338335
ACCEPTS: (npy.array xdata, npy.array ydata)
339336
"""
340-
341337
if len(args)==1:
342338
x, y = args[0]
343339
else:
@@ -347,8 +343,9 @@ def set_data(self, *args):
347343
self._yorig = y
348344
self.recache()
349345

346+
# MGDTODO: Masked data arrays are broken
350347
_masked_array_to_path_code_mapping = npy.array(
351-
[Path.LINETO, Path.IGNORE, Path.MOVETO], Path.code_type)
348+
[Path.LINETO, Path.MOVETO, Path.MOVETO], Path.code_type)
352349
def recache(self):
353350
#if self.axes is None: print 'recache no axes'
354351
#else: print 'recache units', self.axes.xaxis.units, self.axes.yaxis.units
@@ -387,18 +384,18 @@ def recache(self):
387384
# MGDTODO: If _draw_steps is removed, remove the following line also
388385
self._step_path = None
389386

390-
391387
def _is_sorted(self, x):
392388
"return true if x is sorted"
393389
if len(x)<2: return 1
394390
return npy.alltrue(x[1:]-x[0:-1]>=0)
395391

392+
# MGDTODO: Remove me (seems to be used for old-style interface only)
396393
def _get_plottable(self):
397394
# If log scale is set, only pos data will be returned
398395

399396
x, y = self._x, self._y
400397

401-
# MGDTODO: Deal with the log scale here
398+
# MGDTODO: (log-scaling)
402399

403400
# try: logx = self.get_transform().get_funcx().get_type()==LOG10
404401
# except RuntimeError: logx = False # non-separable

lib/matplotlib/patches.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,6 @@ def __str__(self):
319319
return str(self.__class__).split('.')[-1] \
320320
+ "(%g,%g;%gx%g)"%(self.xy[0],self.xy[1],self.width,self.height)
321321

322-
# MGDTODO: Perhaps pass in a Bbox here instead, then the updates will
323-
# happen automatically (without needing to call set_x etc.
324322
def __init__(self, xy, width, height, **kwargs):
325323
"""
326324
xy is an x,y tuple lower, left
@@ -459,17 +457,14 @@ def __str__(self):
459457

460458
def __init__(self, xy, **kwargs):
461459
"""
462-
xy is a sequence of (x,y) 2 tuples
460+
xy is a numpy array with shape Nx2
463461
464462
Valid kwargs are:
465463
%(Patch)s
466464
See Patch documentation for additional kwargs
467465
"""
468-
# MGDTODO: This should encourage the use of numpy arrays of shape Nx2
469466
Patch.__init__(self, **kwargs)
470-
if not isinstance(xy, list):
471-
xy = list(xy)
472-
self._path = Path(xy, closed=False)
467+
self._path = Path(xy, closed=True)
473468
__init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
474469

475470
def get_verts(self):

lib/matplotlib/path.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import numpy as npy
22

3-
DEBUG = True
4-
53
class Path(object):
64
# Path codes
7-
IGNORE = 0 # 1 vertex
5+
STOP = 0 # 1 vertex
86
MOVETO = 1 # 1 vertex
97
LINETO = 2 # 1 vertex
108
CURVE3 = 3 # 2 vertices
119
CURVE4 = 4 # 3 vertices
12-
CLOSEPOLY = 5
10+
CLOSEPOLY = 5 # 1 vertex
1311
###
1412
# MGDTODO: I'm not sure these are supported by PS/PDF/SVG,
1513
# so if they don't, we probably shouldn't
@@ -18,37 +16,35 @@ class Path(object):
1816
UBSPLINE = 8
1917
####
2018

21-
NUM_VERTICES = [1, 1, 1, 2, 3, 0]
19+
NUM_VERTICES = [1, 1, 1, 2, 3, 1]
2220

2321
code_type = npy.uint8
2422

2523
def __init__(self, vertices, codes=None, closed=True):
26-
self._vertices = npy.asarray(vertices, npy.float_)
27-
assert self._vertices.ndim == 2
28-
assert self._vertices.shape[1] == 2
29-
24+
vertices = npy.asarray(vertices, npy.float_)
25+
assert vertices.ndim == 2
26+
assert vertices.shape[1] == 2
27+
3028
if codes is None:
3129
if closed:
3230
codes = self.LINETO * npy.ones(
33-
self._vertices.shape[0] + 1, self.code_type)
31+
vertices.shape[0] + 1, self.code_type)
3432
codes[0] = self.MOVETO
35-
codes[-1] = self.CLOSEPOLY
33+
codes[-1] = self.CLOSEPOLY
34+
vertices = npy.concatenate((vertices, [[0.0, 0.0]]))
3635
else:
3736
codes = self.LINETO * npy.ones(
38-
self._vertices.shape[0], self.code_type)
37+
vertices.shape[0], self.code_type)
3938
codes[0] = self.MOVETO
4039
else:
4140
codes = npy.asarray(codes, self.code_type)
42-
self._codes = codes
43-
44-
assert self._codes.ndim == 1
41+
assert codes.ndim == 1
42+
assert len(codes) == len(vertices)
4543

46-
if DEBUG:
47-
i = 0
48-
NUM_VERTICES = self.NUM_VERTICES
49-
for code in codes:
50-
i += NUM_VERTICES[code]
51-
assert i == len(self.vertices)
44+
self._codes = codes
45+
self._vertices = vertices
46+
47+
assert self._codes.ndim == 1
5248

5349
def __repr__(self):
5450
return "Path(%s, %s)" % (self.vertices, self.codes)
@@ -66,11 +62,13 @@ def iter_endpoints(self):
6662
NUM_VERTICES = self.NUM_VERTICES
6763
vertices = self.vertices
6864
for code in self.codes:
69-
num_vertices = NUM_VERTICES[code]
70-
if num_vertices >= 1:
71-
i += num_vertices - 1
72-
yield vertices[i]
73-
i += 1
65+
if code == self.CLOSEPOLY:
66+
i += 1
67+
else:
68+
num_vertices = NUM_VERTICES[code]
69+
i += num_vertices - 1
70+
yield vertices[i]
71+
i += 1
7472

7573
_unit_rectangle = None
7674
#@classmethod
@@ -118,16 +116,18 @@ def unit_circle(cls):
118116

119117
[-offset, -1.0],
120118
[-1.0, -offset],
121-
[-1.0, 0.0]],
122-
npy.float_)
123-
codes = npy.array(
124-
[cls.MOVETO,
125-
cls.CURVE4,
126-
cls.CURVE4,
127-
cls.CURVE4,
128-
cls.CURVE4,
129-
cls.CLOSEPOLY],
130-
cls.code_type)
119+
[-1.0, 0.0],
120+
121+
[-1.0, 0.0]],
122+
npy.float_)
123+
124+
codes = cls.CURVE4 + npy.ones((len(vertices)))
125+
codes[0] = cls.MOVETO
126+
codes[-1] = cls.CLOSEPOLY
127+
131128
cls._unit_circle = Path(vertices, codes)
132129
return cls._unit_circle
133130
unit_circle = classmethod(unit_circle)
131+
132+
# MGDTODO: Add a transformed path that would automatically invalidate
133+
# itself when its transform changes

lib/matplotlib/pbox.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# MGDTODO: Just included verbatim for now
2-
31
class PBox(list):
42
'''
53
A left-bottom-width-height (lbwh) specification of a bounding box,

lib/matplotlib/text.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def _get_layout(self, renderer):
231231

232232
# now rotate the bbox
233233

234-
cornersRotated = M(cornersHoriz)
234+
cornersRotated = M.transform(cornersHoriz)
235235

236236
txs = cornersRotated[:, 0]
237237
tys = cornersRotated[:, 1]
@@ -269,15 +269,15 @@ def _get_layout(self, renderer):
269269

270270

271271
# now rotate the positions around the first x,y position
272-
xys = M(offsetLayout)
272+
xys = M.transform(offsetLayout)
273273
tx = xys[:, 0]
274274
ty = xys[:, 1]
275275
tx += offsetx
276276
ty += offsety
277277

278278
# now inverse transform back to data coords
279279
inverse_transform = self.get_transform().inverted()
280-
xys = inverse_transform(xys)
280+
xys = inverse_transform.transform(xys)
281281

282282
xs, ys = zip(*xys)
283283

@@ -407,7 +407,7 @@ def get_prop_tup(self):
407407
return (x, y, self._text, self._color,
408408
self._verticalalignment, self._horizontalalignment,
409409
hash(self._fontproperties), self._rotation,
410-
self.get_transform().to_values(),
410+
self.get_transform(),
411411
)
412412

413413
def get_text(self):

0 commit comments

Comments
 (0)
0