Skip to content

Commit c77e82c

Browse files
committed
more backend refactorng and optimizations
svn path=/trunk/matplotlib/; revision=945
1 parent 862225a commit c77e82c

File tree

11 files changed

+635
-415
lines changed

11 files changed

+635
-415
lines changed

CHANGELOG

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
New entries should be added at the top
22

3+
2005-02-10 backend renderer draw_lines now has transform in backend,
4+
as in draw_markers; use numerix in _backend_agg
5+
6+
2005-02-09 subplot now deletes axes that it overlaps
7+
8+
2005-02-08 Added transparent support for gzipped files in load/save - Fernando
9+
Perez (FP from now on).
10+
311
2005-02-08 Small optimizations in PS backend. They may have a big impact for
412
large plots, otherwise they don't hurt - FP
513

TODO

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,4 +642,4 @@ ZeroDivisionError: SeparableTransformation::eval_scalars yin interval is zero; c
642642

643643
-- fix contour mappable to work under changes in clim, cmap
644644

645-
-- make subplot delaxes on other subplots under it.
645+
-- DONE make subplot delaxes on other subplots under it.

lib/matplotlib/axes.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,14 @@ def update_datalim(self, xys):
686686
# and the data in xydata
687687
self.dataLim.update(xys, not self.has_data())
688688

689+
def update_datalim_numerix(self, x, y):
690+
'Update the data lim bbox with seq of xy tups'
691+
# if no data is set currently, the bbox will ignore it's
692+
# limits and set the bound to be the bounds of the xydata.
693+
# Otherwise, it will compute the bounds of it's current data
694+
# and the data in xydata
695+
self.dataLim.update_numerix(x, y, not self.has_data())
696+
689697
def add_line(self, l):
690698
'Add a line to the list of plot lines'
691699
self._set_artist_props(l)
@@ -697,8 +705,7 @@ def add_line(self, l):
697705
xys = self._get_verts_in_data_coords(
698706
l.get_transform(), zip(xdata, ydata))
699707
xdata, ydata = zip(*xys)
700-
701-
self.update_datalim( zip(xdata, ydata) )
708+
self.update_datalim_numerix( xdata, ydata )
702709

703710
self.lines.append(l)
704711

lib/matplotlib/backends/backend_agg.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@
8484
from matplotlib.ft2font import FT2Font
8585
from matplotlib.mathtext import math_parse_s_ft2font
8686

87-
from _backend_agg import RendererAgg as _RendererAgg
87+
88+
import matplotlib.numerix
89+
90+
if matplotlib.numerix.which[0] == "numarray":
91+
from _na_backend_agg import RendererAgg as _RendererAgg
92+
else:
93+
from _nc_backend_agg import RendererAgg as _RendererAgg
8894

8995
backend_version = 'v2.2'
9096
_fontd = {} # a map from fname to font instances

lib/matplotlib/lines.py

+33-28
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from matplotlib import verbose
1515
from artist import Artist
1616
from cbook import iterable, is_string_like
17-
from collections import RegularPolyCollection, PolyCollection
1817
from colors import colorConverter
1918
from patches import bbox_artist
2019
from path import MOVETO, LINETO, ENDPOLY
@@ -32,8 +31,6 @@
3231
TICKDOWN:1,
3332
'None':1
3433
}
35-
36-
3734

3835
class Line2D(Artist):
3936
_lineStyles = {
@@ -147,7 +144,12 @@ def __init__(self, xdata, ydata,
147144
self._logcache = None
148145

149146
def get_window_extent(self, renderer):
150-
x, y = self._get_numeric_clipped_data_in_range()
147+
self._newstyle = hasattr(renderer, 'draw_markers')
148+
if self._newstyle:
149+
x = self._x
150+
y = self._y
151+
else:
152+
x, y = self._get_numeric_clipped_data_in_range()
151153

152154

153155
x, y = self._transform.numerix_x_y(x, y)
@@ -268,8 +270,8 @@ def draw(self, renderer):
268270
gc.set_clip_rectangle(self.clipbox.get_bounds())
269271

270272

271-
if self._newstyle and self._linestyle == 'None':
272-
# we don't need xt
273+
if self._newstyle:
274+
# transform in backend
273275
xt = self._x
274276
yt = self._y
275277
else:
@@ -289,9 +291,6 @@ def draw(self, renderer):
289291
if self.get_clip_on():
290292
gc.set_clip_rectangle(self.clipbox.get_bounds())
291293
markerFunc = getattr(self, self._markerFunc)
292-
if self._newstyle:
293-
xt = self._x
294-
yt = self._y
295294
markerFunc(renderer, gc, xt, yt)
296295

297296
#if 1: bbox_artist(self, renderer)
@@ -512,14 +511,22 @@ def _draw_steps(self, renderer, gc, xt, yt):
512511
yt2[0:-1:2], yt2[1::2]=yt, yt
513512
gc.set_linestyle('solid')
514513
gc.set_capstyle('projecting')
515-
renderer.draw_lines(gc, xt2, yt2)
514+
515+
if self._newstyle:
516+
renderer.draw_lines(gc, xt2, yt2, self._transform)
517+
else:
518+
renderer.draw_lines(gc, xt2, yt2)
516519

517520
def _draw_solid(self, renderer, gc, xt, yt):
518521
if len(xt)<2: return
519522
gc.set_linestyle('solid')
520523
gc.set_capstyle('projecting')
521524

522-
renderer.draw_lines(gc, xt,yt)
525+
if self._newstyle:
526+
renderer.draw_lines(gc, xt, yt, self._transform)
527+
else:
528+
renderer.draw_lines(gc, xt, yt)
529+
523530

524531
def _draw_dashed(self, renderer, gc, xt, yt):
525532
if len(xt)<2: return
@@ -528,14 +535,23 @@ def _draw_dashed(self, renderer, gc, xt, yt):
528535
gc.set_dashes(0, self._dashSeq)
529536
gc.set_capstyle('butt')
530537
gc.set_joinstyle('miter')
531-
renderer.draw_lines(gc, xt, yt)
538+
539+
if self._newstyle:
540+
renderer.draw_lines(gc, xt, yt, self._transform)
541+
else:
542+
renderer.draw_lines(gc, xt, yt)
543+
532544

533545
def _draw_dash_dot(self, renderer, gc, xt, yt):
534546
if len(xt)<2: return
535547
gc.set_linestyle('dashdot')
536548
gc.set_capstyle('butt')
537549
gc.set_joinstyle('miter')
538-
renderer.draw_lines(gc, xt, yt)
550+
if self._newstyle:
551+
renderer.draw_lines(gc, xt, yt, self._transform)
552+
else:
553+
renderer.draw_lines(gc, xt, yt)
554+
539555

540556

541557
def _draw_dotted(self, renderer, gc, xt, yt):
@@ -544,8 +560,10 @@ def _draw_dotted(self, renderer, gc, xt, yt):
544560
gc.set_linestyle('dotted')
545561
gc.set_capstyle('butt')
546562
gc.set_joinstyle('miter')
547-
renderer.draw_lines(gc, xt, yt)
548-
563+
if self._newstyle:
564+
renderer.draw_lines(gc, xt, yt, self._transform)
565+
else:
566+
renderer.draw_lines(gc, xt, yt)
549567

550568
def _draw_point(self, renderer, gc, xt, yt):
551569
if self._newstyle:
@@ -603,17 +621,6 @@ def _draw_circle(self, renderer, gc, xt, yt):
603621
x, y, w, h, 0.0, 360.0)
604622

605623

606-
def _draw_circle_collection(self, renderer):
607-
colors = ( colorConverter.to_rgba(self._color, self.get_alpha()), )
608-
collection = RegularPolyCollection(
609-
self.figure.dpi,
610-
numsides=20, rotation=0, sizes=(self._markersize,),
611-
facecolors = colors,
612-
offsets = zip(self._x, self._y),
613-
transOffset = self._transform,
614-
)
615-
collection.draw(renderer)
616-
617624

618625
def _draw_triangle_up(self, renderer, gc, xt, yt):
619626

@@ -631,8 +638,6 @@ def _draw_triangle_up(self, renderer, gc, xt, yt):
631638
)
632639
renderer.draw_markers(gc, path, xt, yt, self._transform)
633640
else:
634-
635-
636641
for (x,y) in zip(xt, yt):
637642
verts = ( (x, y+offset),
638643
(x-offset, y-offset),

setup.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
BUILD_WINDOWING = 'auto'
4242

4343

44-
VERBOSE = False # insert lots of diagnostic prints in extension code
44+
VERBOSE = False # insert lots of diagnostic prints in extension code
4545

4646

4747

@@ -158,18 +158,18 @@ def add_dateutil():
158158
print 'pygtk present but import failed'
159159
if BUILD_GTKAGG:
160160
BUILD_AGG = 1
161-
build_gtkagg(ext_modules, packages)
161+
build_gtkagg(ext_modules, packages, NUMERIX)
162162

163163
if BUILD_TKAGG:
164164
try: import Tkinter
165165
except ImportError: print 'TKAgg requires TkInter'
166166
else:
167167
BUILD_AGG = 1
168-
build_tkagg(ext_modules, packages)
168+
build_tkagg(ext_modules, packages, NUMERIX)
169169

170170

171171
if BUILD_AGG:
172-
build_agg(ext_modules, packages)
172+
build_agg(ext_modules, packages, NUMERIX)
173173

174174
if BUILD_FT2FONT:
175175
build_ft2font(ext_modules, packages)

setupext.py

+39-15
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def build_ft2font(ext_modules, packages):
337337
ext_modules.append(module)
338338
BUILT_FT2FONT = True
339339

340-
def build_gtkagg(ext_modules, packages):
340+
def build_gtkagg(ext_modules, packages, numerix):
341341
global BUILT_GTKAGG
342342
if BUILT_GTKAGG: return # only build it if you you haven't already
343343
deps = ['src/_gtkagg.cpp', 'src/mplutils.cpp']
@@ -360,7 +360,7 @@ def build_gtkagg(ext_modules, packages):
360360
ext_modules.append(module)
361361
BUILT_GTKAGG = True
362362

363-
def build_tkagg(ext_modules, packages):
363+
def build_tkagg(ext_modules, packages, numerix):
364364
global BUILT_TKAGG
365365
if BUILT_TKAGG: return # only build it if you you haven't already
366366
module = Extension('matplotlib.backends._tkagg',
@@ -377,24 +377,48 @@ def build_tkagg(ext_modules, packages):
377377
BUILT_TKAGG = True
378378

379379

380-
def build_agg(ext_modules, packages):
380+
def build_agg(ext_modules, packages, numerix):
381381
global BUILT_AGG
382382
if BUILT_AGG: return # only build it if you you haven't already
383383

384-
deps = ['src/_backend_agg.cpp', 'src/ft2font.cpp', 'src/mplutils.cpp']
385-
deps.extend(glob.glob('agg22/src/*.cpp'))
386-
deps.extend(glob.glob('CXX/*.cxx'))
387-
deps.extend(glob.glob('CXX/*.c'))
388384

389-
module = Extension(
390-
'matplotlib.backends._backend_agg',
391-
deps
392-
,
393-
)
394385

395-
add_agg_flags(module)
396-
add_ft2font_flags(module)
397-
ext_modules.append(module)
386+
387+
if numerix in ["numarray","both"]: # Build for numarray
388+
deps = ['src/ft2font.cpp', 'src/mplutils.cpp']
389+
deps.extend(glob.glob('agg22/src/*.cpp'))
390+
deps.extend(glob.glob('CXX/*.cxx'))
391+
deps.extend(glob.glob('CXX/*.c'))
392+
temp_copy('src/_backend_agg.cpp', 'src/_na_backend_agg.cpp')
393+
deps.append('src/_na_backend_agg.cpp')
394+
module = Extension(
395+
'matplotlib.backends._na_backend_agg',
396+
deps
397+
,
398+
)
399+
module.extra_compile_args.append('-DNUMARRAY=1')
400+
add_agg_flags(module)
401+
add_ft2font_flags(module)
402+
ext_modules.append(module)
403+
if numerix in ["Numeric","both"]: # Build for Numeric
404+
deps = ['src/ft2font.cpp', 'src/mplutils.cpp']
405+
deps.extend(glob.glob('agg22/src/*.cpp'))
406+
deps.extend(glob.glob('CXX/*.cxx'))
407+
deps.extend(glob.glob('CXX/*.c'))
408+
409+
temp_copy('src/_backend_agg.cpp', 'src/_nc_backend_agg.cpp')
410+
deps.append('src/_nc_backend_agg.cpp')
411+
module = Extension(
412+
'matplotlib.backends._nc_backend_agg',
413+
deps
414+
,
415+
)
416+
module.extra_compile_args.append('-DNUMERIC=1')
417+
418+
add_agg_flags(module)
419+
add_ft2font_flags(module)
420+
ext_modules.append(module)
421+
398422
BUILT_AGG = True
399423

400424
def build_image(ext_modules, packages, numerix):

0 commit comments

Comments
 (0)