SF.net SVN: matplotlib:[7100] trunk/matplotlib
Revision: 7100
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7100&view=rev
Author: efiring
Date: 2009-05-13 19:59:16 + (Wed, 13 May 2009)
Log Message:
---
Experimental clipping of Line _transformed_path to speed zoom and pan.
This can be modified to work with x monotonically decreasing, but
for a first try it works only with x monotonically increasing.
The intention is to greatly speed up zooming and panning into
a small segment of a very long time series (e.g., 10^6 points)
without incurring any significant speed penalty in other situations.
Modified Paths:
--
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/axes.py
trunk/matplotlib/lib/matplotlib/lines.py
trunk/matplotlib/lib/matplotlib/path.py
Modified: trunk/matplotlib/CHANGELOG
===
--- trunk/matplotlib/CHANGELOG 2009-05-12 19:35:25 UTC (rev 7099)
+++ trunk/matplotlib/CHANGELOG 2009-05-13 19:59:16 UTC (rev 7100)
@@ -1,4 +1,11 @@
==
+2009-05-13 When the x-coordinate of a line is monotonically
+ increasing, it is now automatically clipped at
+ the stage of generating the transformed path in
+ the draw method; this greatly speeds up zooming and
+ panning when one is looking at a short segment of
+ a long time series, for example. - EF
+
2009-05-11 aspect=1 in log-log plot gives square decades.
2009-05-08 clabel takes new kwarg, rightside_up; if False, labels
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===
--- trunk/matplotlib/lib/matplotlib/axes.py 2009-05-12 19:35:25 UTC (rev
7099)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2009-05-13 19:59:16 UTC (rev
7100)
@@ -765,7 +765,10 @@
self.xaxis.get_transform(), self.yaxis.get_transform()))
if hasattr(self, "lines"):
for line in self.lines:
-line._transformed_path.invalidate()
+try:
+line._transformed_path.invalidate()
+except AttributeError:
+pass
def get_position(self, original=False):
'Return the a copy of the axes rectangle as a Bbox'
Modified: trunk/matplotlib/lib/matplotlib/lines.py
===
--- trunk/matplotlib/lib/matplotlib/lines.py2009-05-12 19:35:25 UTC (rev
7099)
+++ trunk/matplotlib/lib/matplotlib/lines.py2009-05-13 19:59:16 UTC (rev
7100)
@@ -440,12 +440,22 @@
self._x = self._xy[:, 0] # just a view
self._y = self._xy[:, 1] # just a view
-# Masked arrays are now handled by the Path class itself
+self._subslice = False
+if len(x) > 100 and self._is_sorted(x):
+self._subslice = True
self._path = Path(self._xy)
-self._transformed_path = TransformedPath(self._path,
self.get_transform())
-
+self._transformed_path = None
self._invalid = False
+def _transform_path(self, subslice=None):
+# Masked arrays are now handled by the Path class itself
+if subslice is not None:
+_path = Path(self._xy[subslice,:])
+else:
+_path = self._path
+self._transformed_path = TransformedPath(_path, self.get_transform())
+
+
def set_transform(self, t):
"""
set the Transformation instance used by this artist
@@ -454,7 +464,6 @@
"""
Artist.set_transform(self, t)
self._invalid = True
-# self._transformed_path = TransformedPath(self._path,
self.get_transform())
def _is_sorted(self, x):
"return true if x is sorted"
@@ -465,7 +474,15 @@
def draw(self, renderer):
if self._invalid:
self.recache()
-
+if self._subslice:
+# Need to handle monotonically decreasing case also...
+x0, x1 = self.axes.get_xbound()
+i0, = self._x.searchsorted([x0], 'left')
+i1, = self._x.searchsorted([x1], 'right')
+subslice = slice(max(i0-1, 0), i1+1)
+self._transform_path(subslice)
+if self._transformed_path is None:
+self._transform_path()
renderer.open_group('line2d', self.get_gid())
if not self._visible: return
Modified: trunk/matplotlib/lib/matplotlib/path.py
===
--- trunk/matplotlib/lib/matplotlib/path.py 2009-05-12 19:35:25 UTC (rev
7099)
+++ trunk/matplotlib/lib/matplotlib/path.py 2009-05-13 19:59:16 UTC (rev
7100)
@@ -118,7 +118,10 @@
(len(vertices) >= 128 and
(codes is None or np.all(codes <=
Path.LINETO
self.simplify_threshold = rcParams['path.simplify_threshold']
-sel
SF.net SVN: matplotlib:[7101] trunk/matplotlib
Revision: 7101
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7101&view=rev
Author: leejjoon
Date: 2009-05-14 04:00:38 + (Thu, 14 May 2009)
Log Message:
---
psfrag in backend_ps now uses baseline-alignment when preview.sty is used
Modified Paths:
--
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
trunk/matplotlib/lib/matplotlib/offsetbox.py
Modified: trunk/matplotlib/CHANGELOG
===
--- trunk/matplotlib/CHANGELOG 2009-05-13 19:59:16 UTC (rev 7100)
+++ trunk/matplotlib/CHANGELOG 2009-05-14 04:00:38 UTC (rev 7101)
@@ -1,4 +1,9 @@
==
+2009-05-13 psfrag in backend_ps now uses baseline-alignment
+ when preview.sty is used ((default is
+ bottom-alignment). Also, a small api imporvement
+ in OffsetBox-JJL
+
2009-05-13 When the x-coordinate of a line is monotonically
increasing, it is now automatically clipped at
the stage of generating the transformed path in
@@ -6,7 +11,7 @@
panning when one is looking at a short segment of
a long time series, for example. - EF
-2009-05-11 aspect=1 in log-log plot gives square decades.
+2009-05-11 aspect=1 in log-log plot gives square decades. -JJL
2009-05-08 clabel takes new kwarg, rightside_up; if False, labels
will not be flipped to keep them rightside-up. This
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-05-13
19:59:16 UTC (rev 7100)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-05-14
04:00:38 UTC (rev 7101)
@@ -537,8 +537,6 @@
"""
w, h, bl = self.get_text_width_height_descent(s, prop, ismath)
fontsize = prop.get_size_in_points()
-corr = 0#w/2*(fontsize-10)/10
-pos = _nums_to_str(x-corr, y)
thetext = 'psmarker%d' % self.textcnt
color = '%1.3f,%1.3f,%1.3f'% gc.get_rgb()[:3]
fontcmd = {'sans-serif' : r'{\sffamily %s}',
@@ -546,7 +544,17 @@
rcParams['font.family'], r'{\rmfamily %s}')
s = fontcmd % s
tex = r'\color[rgb]{%s} %s' % (color, s)
-
self.psfrag.append(r'\psfrag{%s}[bl][bl][1][%f]{\fontsize{%f}{%f}%s}'%(thetext,
angle, fontsize, fontsize*1.25, tex))
+
+corr = 0#w/2*(fontsize-10)/10
+if rcParams['text.latex.preview']:
+# use baseline alignment!
+pos = _nums_to_str(x-corr, y+bl)
+
self.psfrag.append(r'\psfrag{%s}[Bl][Bl][1][%f]{\fontsize{%f}{%f}%s}'%(thetext,
angle, fontsize, fontsize*1.25, tex))
+else:
+# stick to the bottom alignment, but this may give incorrect
baseline some times.
+pos = _nums_to_str(x-corr, y)
+
self.psfrag.append(r'\psfrag{%s}[bl][bl][1][%f]{\fontsize{%f}{%f}%s}'%(thetext,
angle, fontsize, fontsize*1.25, tex))
+
ps = """\
gsave
%(pos)s moveto
Modified: trunk/matplotlib/lib/matplotlib/offsetbox.py
===
--- trunk/matplotlib/lib/matplotlib/offsetbox.py2009-05-13 19:59:16 UTC
(rev 7100)
+++ trunk/matplotlib/lib/matplotlib/offsetbox.py2009-05-14 04:00:38 UTC
(rev 7101)
@@ -782,11 +782,14 @@
explicitly specify the bbox_to_anchor.
"""
+zorder = 5 # zorder of the legend
+
def __init__(self, loc,
pad=0.4, borderpad=0.5,
child=None, prop=None, frameon=True,
bbox_to_anchor=None,
- bbox_transform=None):
+ bbox_transform=None,
+ **kwargs):
"""
loc is a string or an integer specifying the legend location.
The valid location codes are::
@@ -819,7 +822,7 @@
"""
-super(AnchoredOffsetbox, self).__init__()
+super(AnchoredOffsetbox, self).__init__(**kwargs)
self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform)
self.set_child(child)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
--
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[7102] trunk/matplotlib
Revision: 7102
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7102&view=rev
Author: leejjoon
Date: 2009-05-14 06:27:58 + (Thu, 14 May 2009)
Log Message:
---
An optional offset and bbox support in restore_bbox
Modified Paths:
--
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/backends/backend_agg.py
trunk/matplotlib/src/_backend_agg.cpp
trunk/matplotlib/src/_backend_agg.h
Added Paths:
---
trunk/matplotlib/examples/animation/animation_blit_gtk2.py
Modified: trunk/matplotlib/CHANGELOG
===
--- trunk/matplotlib/CHANGELOG 2009-05-14 04:00:38 UTC (rev 7101)
+++ trunk/matplotlib/CHANGELOG 2009-05-14 06:27:58 UTC (rev 7102)
@@ -1,4 +1,7 @@
==
+2009-05-13 An optional offset and bbox support in restore_bbox.
+ Add animation_blit_gtk2.py. -JJL
+
2009-05-13 psfrag in backend_ps now uses baseline-alignment
when preview.sty is used ((default is
bottom-alignment). Also, a small api imporvement
Added: trunk/matplotlib/examples/animation/animation_blit_gtk2.py
===
--- trunk/matplotlib/examples/animation/animation_blit_gtk2.py
(rev 0)
+++ trunk/matplotlib/examples/animation/animation_blit_gtk2.py 2009-05-14
06:27:58 UTC (rev 7102)
@@ -0,0 +1,167 @@
+#!/usr/bin/env python
+
+"""
+This example utlizes restore_region with optional bbox and xy
+arguments. The plot is continuously shifted to the left. Instead of
+drawing everything again, the plot is saved (copy_from_bbox) and
+restored with offset by the amount of the shift. And only newly
+exposed area is drawn. This technique may reduce drawing time for some cases.
+"""
+
+import time
+
+import gtk, gobject
+
+import matplotlib
+matplotlib.use('GTKAgg')
+
+import numpy as np
+import matplotlib.pyplot as plt
+
+class UpdateLine(object):
+def get_bg_bbox(self):
+
+return self.ax.bbox.padded(-3)
+
+def __init__(self, canvas, ax):
+self.cnt = 0
+self.canvas = canvas
+self.ax = ax
+
+self.prev_time = time.time()
+self.start_time = self.prev_time
+self.prev_pixel_offset = 0.
+
+
+self.x0 = 0
+self.phases = np.random.random_sample((20,)) * np.pi * 2
+self.line, = ax.plot([], [], "-", animated=True, lw=2)
+
+self.point, = ax.plot([], [], "ro", animated=True, lw=2)
+
+self.ax.set_ylim(-1.1, 1.1)
+
+self.background1 = None
+
+cmap = plt.cm.jet
+from itertools import cycle
+self.color_cycle = cycle(cmap(np.arange(cmap.N)))
+
+
+def save_bg(self):
+self.background1 =
self.canvas.copy_from_bbox(self.ax.get_figure().bbox)
+
+self.background2 = self.canvas.copy_from_bbox(self.get_bg_bbox())
+
+
+def get_dx_data(self, dx_pixel):
+tp = self.ax.transData.inverted().transform_point
+x0, y0 = tp((0, 0))
+x1, y1 = tp((dx_pixel, 0))
+return (x1-x0)
+
+
+def restore_background_shifted(self, dx_pixel):
+"""
+restore bacground shifted by dx in data coordinate. This only
+works if the data coordinate system is linear.
+"""
+
+# restore the clean slate background
+self.canvas.restore_region(self.background1)
+
+# restore subregion (x1+dx, y1, x2, y2) of the second bg
+# in a offset position (x1-dx, y1)
+x1, y1, x2, y2 = self.background2.get_extents()
+self.canvas.restore_region(self.background2,
+ bbox=(x1+dx_pixel, y1, x2, y2),
+ xy=(x1-dx_pixel, y1))
+
+return dx_pixel
+
+def on_draw(self, *args):
+self.save_bg()
+return False
+
+def update_line(self, *args):
+
+if self.background1 is None:
+return True
+
+cur_time = time.time()
+pixel_offset = int((cur_time - self.start_time)*100.)
+dx_pixel = pixel_offset - self.prev_pixel_offset
+self.prev_pixel_offset = pixel_offset
+dx_data = self.get_dx_data(dx_pixel) #cur_time - self.prev_time)
+
+x0 = self.x0
+self.x0 += dx_data
+self.prev_time = cur_time
+
+self.ax.set_xlim(self.x0-2, self.x0+0.1)
+
+
+# restore background which will plot lines from previous plots
+self.restore_background_shifted(dx_pixel) #x0, self.x0)
+# This restores lines between [x0-2, x0]
+
+
+
+self.line.set_color(self.color_cycle.next())
+
+# now plot line segment within [x0, x0+dx_data],
+# Note that we're only plotting a line between [x0, x0+dx_data].
+xx = np.array([x0, self.x0])
+self.line.set_xdata(xx)
+
+# the for loop below could be improved by using colle
