Revision: 7090
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7090&view=rev
Author: leejjoon
Date: 2009-05-07 03:50:55 +0000 (Thu, 07 May 2009)
Log Message:
-----------
print_ps with mixed-renderer
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/axes.py
trunk/matplotlib/lib/matplotlib/backend_bases.py
trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2009-05-07 03:40:40 UTC (rev 7089)
+++ trunk/matplotlib/CHANGELOG 2009-05-07 03:50:55 UTC (rev 7090)
@@ -1,4 +1,8 @@
======================================================================
+2009-05-06 print_ps now uses mixed-mode renderer. Axes.draw rasterize
+ artists whose zorder smaller than rasterization_zorder.
+ -JJL
+
2009-05-06 Per-artist Rasterization, originally by Eric Bruning. -JJ
2009-05-05 Add an example that shows how to make a plot that updates
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py 2009-05-07 03:40:40 UTC (rev
7089)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2009-05-07 03:50:55 UTC (rev
7090)
@@ -8,6 +8,7 @@
rcParams = matplotlib.rcParams
import matplotlib.artist as martist
+from matplotlib.artist import allow_rasterization
import matplotlib.axis as maxis
import matplotlib.cbook as cbook
import matplotlib.collections as mcoll
@@ -531,6 +532,8 @@
self._frameon = frameon
self._axisbelow = rcParams['axes.axisbelow']
+ self._rasterization_zorder = -30000
+
self._hold = rcParams['axes.hold']
self._connected = {} # a dict from events to (id, func)
self.cla()
@@ -1566,6 +1569,19 @@
"""
self._autoscaleYon = b
+ def set_rasterization_zorder(self, z):
+ """
+ Set zorder value below which artists will be rasterized
+ """
+ self._rasterization_zorder = z
+
+ def get_rasterization_zorder(self):
+ """
+ Get zorder value below which artists will be rasterized
+ """
+ return self._rasterization_zorder
+
+
def autoscale_view(self, tight=False, scalex=True, scaley=True):
"""
autoscale the view limits using the data limits. You can
@@ -1620,15 +1636,55 @@
else:
self.apply_aspect()
+
+ artists = []
+
+ artists.extend(self.collections)
+ artists.extend(self.patches)
+ artists.extend(self.lines)
+ artists.extend(self.texts)
+ artists.extend(self.artists)
+ if self.axison and not inframe:
+ if self._axisbelow:
+ self.xaxis.set_zorder(0.5)
+ self.yaxis.set_zorder(0.5)
+ else:
+ self.xaxis.set_zorder(2.5)
+ self.yaxis.set_zorder(2.5)
+ artists.extend([self.xaxis, self.yaxis])
+ if not inframe: artists.append(self.title)
+ artists.extend(self.tables)
+ if self.legend_ is not None:
+ artists.append(self.legend_)
+
+ # the frame draws the edges around the axes patch -- we
+ # decouple these so the patch can be in the background and the
+ # frame in the foreground.
+ if self.axison and self._frameon:
+ artists.append(self.frame)
+
+
+ dsu = [ (a.zorder, i, a) for i, a in enumerate(artists)
+ if not a.get_animated() ]
+ dsu.sort()
+
+
+ # rasterze artists with negative zorder
+ # if the minimum zorder is negative, start rasterization
+ rasterization_zorder = self._rasterization_zorder
+ if len(dsu) > 0 and dsu[0][0] < rasterization_zorder:
+ renderer.start_rasterizing()
+ dsu_rasterized = [l for l in dsu if l[0] < rasterization_zorder]
+ dsu = [l for l in dsu if l[0] >= rasterization_zorder]
+ else:
+ dsu_rasterized = []
+
+
# the patch draws the background rectangle -- the frame below
# will draw the edges
if self.axison and self._frameon:
self.patch.draw(renderer)
- artists = []
-
-
-
if len(self.images)<=1 or renderer.option_image_nocomposite():
for im in self.images:
im.draw(renderer)
@@ -1657,35 +1713,13 @@
self.patch.get_path(),
self.patch.get_transform())
- artists.extend(self.collections)
- artists.extend(self.patches)
- artists.extend(self.lines)
- artists.extend(self.texts)
- artists.extend(self.artists)
- if self.axison and not inframe:
- if self._axisbelow:
- self.xaxis.set_zorder(0.5)
- self.yaxis.set_zorder(0.5)
- else:
- self.xaxis.set_zorder(2.5)
- self.yaxis.set_zorder(2.5)
- artists.extend([self.xaxis, self.yaxis])
- if not inframe: artists.append(self.title)
- artists.extend(self.tables)
- if self.legend_ is not None:
- artists.append(self.legend_)
- # the frame draws the edges around the axes patch -- we
- # decouple these so the patch can be in the background and the
- # frame in the foreground.
- if self.axison and self._frameon:
- artists.append(self.frame)
+ if dsu_rasterized:
+ for zorder, i, a in dsu_rasterized:
+ a.draw(renderer)
+ renderer.stop_rasterizing()
- dsu = [ (a.zorder, i, a) for i, a in enumerate(artists)
- if not a.get_animated() ]
- dsu.sort()
-
for zorder, i, a in dsu:
a.draw(renderer)
Modified: trunk/matplotlib/lib/matplotlib/backend_bases.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backend_bases.py 2009-05-07 03:40:40 UTC
(rev 7089)
+++ trunk/matplotlib/lib/matplotlib/backend_bases.py 2009-05-07 03:50:55 UTC
(rev 7090)
@@ -1443,6 +1443,7 @@
facecolor=facecolor,
edgecolor=edgecolor,
orientation=orientation,
+ dryrun=True,
**kwargs)
renderer = self.figure._cachedRenderer
bbox_inches = self.figure.get_tightbbox(renderer)
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-05-07
03:40:40 UTC (rev 7089)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2009-05-07
03:50:55 UTC (rev 7090)
@@ -33,6 +33,9 @@
from matplotlib.path import Path
from matplotlib.transforms import Affine2D
+from matplotlib.backends.backend_mixed import MixedModeRenderer
+
+
import numpy as npy
import binascii
import re
@@ -843,8 +846,13 @@
def print_eps(self, outfile, *args, **kwargs):
return self._print_ps(outfile, 'eps', *args, **kwargs)
+
+
+
+
+
def _print_ps(self, outfile, format, *args, **kwargs):
- papertype = kwargs.get("papertype", rcParams['ps.papersize'])
+ papertype = kwargs.pop("papertype", rcParams['ps.papersize'])
papertype = papertype.lower()
if papertype == 'auto':
pass
@@ -852,25 +860,28 @@
raise RuntimeError( '%s is not a valid papertype. Use one \
of %s'% (papertype, ', '.join( papersize.keys() )) )
- orientation = kwargs.get("orientation", "portrait").lower()
+ orientation = kwargs.pop("orientation", "portrait").lower()
if orientation == 'landscape': isLandscape = True
elif orientation == 'portrait': isLandscape = False
else: raise RuntimeError('Orientation must be "portrait" or
"landscape"')
self.figure.set_dpi(72) # Override the dpi kwarg
- imagedpi = kwargs.get("dpi", 72)
- facecolor = kwargs.get("facecolor", "w")
- edgecolor = kwargs.get("edgecolor", "w")
+ imagedpi = kwargs.pop("dpi", 72)
+ facecolor = kwargs.pop("facecolor", "w")
+ edgecolor = kwargs.pop("edgecolor", "w")
if rcParams['text.usetex']:
self._print_figure_tex(outfile, format, imagedpi, facecolor,
edgecolor,
- orientation, isLandscape, papertype)
+ orientation, isLandscape, papertype,
+ **kwargs)
else:
self._print_figure(outfile, format, imagedpi, facecolor, edgecolor,
- orientation, isLandscape, papertype)
+ orientation, isLandscape, papertype,
+ **kwargs)
def _print_figure(self, outfile, format, dpi=72, facecolor='w',
edgecolor='w',
- orientation='portrait', isLandscape=False,
papertype=None):
+ orientation='portrait', isLandscape=False,
papertype=None,
+ **kwargs):
"""
Render the figure to hardcopy. Set the figure patch face and
edge colors. This is useful because some of the GUIs have a
@@ -939,10 +950,30 @@
self.figure.set_facecolor(facecolor)
self.figure.set_edgecolor(edgecolor)
- self._pswriter = StringIO()
- renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi)
+
+ dryrun = kwargs.get("dryrun", False)
+ if dryrun:
+ class NullWriter(object):
+ def write(self, *kl, **kwargs):
+ pass
+
+ self._pswriter = NullWriter()
+ else:
+ self._pswriter = StringIO()
+
+
+ # mixed mode rendering
+ _bbox_inches_restore = kwargs.pop("bbox_inches_restore", None)
+ ps_renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi)
+ renderer = MixedModeRenderer(self.figure,
+ width, height, dpi, ps_renderer,
+ bbox_inches_restore=_bbox_inches_restore)
+
self.figure.draw(renderer)
+ if dryrun: # return immediately if dryrun (tightbbox=True)
+ return
+
self.figure.set_facecolor(origfacecolor)
self.figure.set_edgecolor(origedgecolor)
@@ -962,7 +993,7 @@
Ndict = len(psDefs)
print >>fh, "%%BeginProlog"
if not rcParams['ps.useafm']:
- Ndict += len(renderer.used_characters)
+ Ndict += len(ps_renderer.used_characters)
print >>fh, "/mpldict %d dict def"%Ndict
print >>fh, "mpldict begin"
for d in psDefs:
@@ -970,7 +1001,7 @@
for l in d.split('\n'):
print >>fh, l.strip()
if not rcParams['ps.useafm']:
- for font_filename, chars in renderer.used_characters.values():
+ for font_filename, chars in ps_renderer.used_characters.values():
if len(chars):
font = FT2Font(font_filename)
cmap = font.get_charmap()
@@ -1019,7 +1050,8 @@
shutil.move(tmpfile, outfile)
def _print_figure_tex(self, outfile, format, dpi, facecolor, edgecolor,
- orientation, isLandscape, papertype):
+ orientation, isLandscape, papertype,
+ **kwargs):
"""
If text.usetex is True in rc, a temporary pair of tex/eps files
are created to allow tex to manage the text layout via the PSFrags
@@ -1051,10 +1083,29 @@
self.figure.set_facecolor(facecolor)
self.figure.set_edgecolor(edgecolor)
- self._pswriter = StringIO()
- renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi)
+ dryrun = kwargs.get("dryrun", False)
+ if dryrun:
+ class NullWriter(object):
+ def write(self, *kl, **kwargs):
+ pass
+
+ self._pswriter = NullWriter()
+ else:
+ self._pswriter = StringIO()
+
+
+ # mixed mode rendering
+ _bbox_inches_restore = kwargs.pop("bbox_inches_restore", None)
+ ps_renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi)
+ renderer = MixedModeRenderer(self.figure,
+ width, height, dpi, ps_renderer,
+ bbox_inches_restore=_bbox_inches_restore)
+
self.figure.draw(renderer)
+ if dryrun: # return immediately if dryrun (tightbbox=True)
+ return
+
self.figure.set_facecolor(origfacecolor)
self.figure.set_edgecolor(origedgecolor)
@@ -1117,11 +1168,11 @@
paper will be used to prevent clipping.'%(papertype, temp_papertype),
'helpful')
- texmanager = renderer.get_texmanager()
+ texmanager = ps_renderer.get_texmanager()
font_preamble = texmanager.get_font_preamble()
custom_preamble = texmanager.get_custom_preamble()
- convert_psfrags(tmpfile, renderer.psfrag, font_preamble,
+ convert_psfrags(tmpfile, ps_renderer.psfrag, font_preamble,
custom_preamble, paperWidth, paperHeight,
orientation)
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