SF.net SVN: matplotlib:[7044] trunk/matplotlib
Revision: 7044
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7044&view=rev
Author: leejjoon
Date: 2009-04-16 17:28:41 + (Thu, 16 Apr 2009)
Log Message:
---
Fixed a bug in mixed mode renderer that images produced by
an rasterizing backend are placed with incorrect size.
Modified Paths:
--
trunk/matplotlib/lib/matplotlib/backend_bases.py
trunk/matplotlib/lib/matplotlib/backends/backend_mixed.py
trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
Added Paths:
---
trunk/matplotlib/examples/misc/tight_bbox_test.py
trunk/matplotlib/lib/matplotlib/tight_bbox.py
Added: trunk/matplotlib/examples/misc/tight_bbox_test.py
===
--- trunk/matplotlib/examples/misc/tight_bbox_test.py
(rev 0)
+++ trunk/matplotlib/examples/misc/tight_bbox_test.py 2009-04-16 17:28:41 UTC
(rev 7044)
@@ -0,0 +1,14 @@
+import matplotlib.pyplot as plt
+import numpy as np
+
+ax = plt.axes([0.1, 0.3, 0.5, 0.5])
+
+ax.pcolormesh(np.array([[1,2],[3,4]]))
+plt.yticks([0.5, 1.5], ["long long tick label",
+"tick label"])
+plt.ylabel("My y-label")
+plt.title("Check saved figures for their bboxes")
+for ext in ["png", "pdf", "svg", "svgz", "eps"]:
+print "saving tight_bbox_test.%s" % (ext,)
+plt.savefig("tight_bbox_test.%s" % (ext,), bbox_inches="tight")
+plt.show()
Modified: trunk/matplotlib/lib/matplotlib/backend_bases.py
===
--- trunk/matplotlib/lib/matplotlib/backend_bases.py2009-04-15 17:52:23 UTC
(rev 7043)
+++ trunk/matplotlib/lib/matplotlib/backend_bases.py2009-04-16 17:28:41 UTC
(rev 7044)
@@ -36,6 +36,8 @@
from matplotlib.transforms import Bbox, TransformedBbox, Affine2D
import cStringIO
+import matplotlib.tight_bbox as tight_bbox
+
class RendererBase:
"""An abstract base class to handle drawing/rendering operations.
@@ -271,7 +273,6 @@
gc.set_alpha(rgbFace[-1])
rgbFace = rgbFace[:3]
gc.set_antialiased(antialiaseds[i % Naa])
-
if Nurls:
gc.set_url(urls[i % Nurls])
@@ -1426,7 +1427,16 @@
if bbox_inches:
# call adjust_bbox to save only the given area
if bbox_inches == "tight":
-# save the figure to estimate the bounding box
+# when bbox_inches == "tight", it saves the figure
+# twice. The first save command is just to estimate
+# the bounding box of the figure. A stringIO object is
+# used as a temporary file object, but it causes a
+# problem for some backends (ps backend with
+# usetex=True) if they expect a filename, not a
+# file-like object. As I think it is best to change
+# the backend to support file-like object, i'm going
+# to leave it as it is. However, a better solution
+# than stringIO seems to be needed. -JJL
result = getattr(self, method_name)(
cStringIO.StringIO(),
dpi=dpi,
@@ -1439,10 +1449,13 @@
pad = kwargs.pop("pad_inches", 0.1)
bbox_inches = bbox_inches.padded(pad)
-restore_bbox = self._adjust_bbox(self.figure, format,
- bbox_inches)
+restore_bbox = tight_bbox.adjust_bbox(self.figure, format,
+ bbox_inches)
+
+_bbox_inches_restore = (bbox_inches, restore_bbox)
+else:
+_bbox_inches_restore = None
-
try:
result = getattr(self, method_name)(
filename,
@@ -1450,6 +1463,7 @@
facecolor=facecolor,
edgecolor=edgecolor,
orientation=orientation,
+bbox_inches_restore=_bbox_inches_restore,
**kwargs)
finally:
if bbox_inches and restore_bbox:
@@ -1463,108 +1477,8 @@
return result
-def _adjust_bbox(self, fig, format, bbox_inches):
-"""
-Temporarily adjust the figure so that only the specified area
-(bbox_inches) is saved.
-It modifies fig.bbox, fig.bbox_inches,
-fig.transFigure._boxout, and fig.patch. While the figure size
-changes, the scale of the original figure is conserved. A
-function whitch restores the original values are returned.
-"""
-origBbox = fig.bbox
-origBboxInches = fig.bbox_inches
-_boxout = fig.transFigure._boxout
-
-asp_list = []
-locator_list = []
-for ax in fig.axes:
-pos = ax.get_position(original=False).frozen()
-locator_list.append
SF.net SVN: matplotlib:[7045] trunk/matplotlib/CHANGELOG
Revision: 7045 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7045&view=rev Author: leejjoon Date: 2009-04-16 17:30:29 + (Thu, 16 Apr 2009) Log Message: --- updated changelog for r7044 Modified Paths: -- trunk/matplotlib/CHANGELOG Modified: trunk/matplotlib/CHANGELOG === --- trunk/matplotlib/CHANGELOG 2009-04-16 17:28:41 UTC (rev 7044) +++ trunk/matplotlib/CHANGELOG 2009-04-16 17:30:29 UTC (rev 7045) @@ -1,5 +1,9 @@ == +2009-04-16 Fixed a bug in mixed mode renderer that images produced by + an rasterizing backend are placed with incorrect size. + - JJL + 2008-04-14 Added Jonathan Taylor's Reinier Heeres' port of John Porters' mplot3d to svn trunk. Package in mpl_toolkits.mplot3d and demo is examples/mplot3d/demo.py. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. -- Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p ___ Matplotlib-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[7046] trunk/matplotlib
Revision: 7046 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7046&view=rev Author: leejjoon Date: 2009-04-17 02:31:16 + (Fri, 17 Apr 2009) Log Message: --- Fixed a offsetbox bug that multiline texts are not correctly aligned. Modified Paths: -- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/offsetbox.py Modified: trunk/matplotlib/CHANGELOG === --- trunk/matplotlib/CHANGELOG 2009-04-16 17:30:29 UTC (rev 7045) +++ trunk/matplotlib/CHANGELOG 2009-04-17 02:31:16 UTC (rev 7046) @@ -1,5 +1,8 @@ == +2009-04-16 Fixed a offsetbox bug that multiline texts are not + correctly aligned. - JJL + 2009-04-16 Fixed a bug in mixed mode renderer that images produced by an rasterizing backend are placed with incorrect size. - JJL @@ -17,7 +20,7 @@ create an output file. Thanks to Joao Luis Silva for reporting this. - JKS -2009-04-05 _png.read_png() reads 12 bit PNGs (patch from +2009-04-05 _png.read_png() reads 12 bit PNGs (patch from Tobias Wood) - ADS 2009-04-04 Allow log axis scale to clip non-positive values to Modified: trunk/matplotlib/lib/matplotlib/offsetbox.py === --- trunk/matplotlib/lib/matplotlib/offsetbox.py2009-04-16 17:30:29 UTC (rev 7045) +++ trunk/matplotlib/lib/matplotlib/offsetbox.py2009-04-17 02:31:16 UTC (rev 7046) @@ -620,27 +620,26 @@ line = info[0][0] # first line _, hh, dd = renderer.get_text_width_height_descent( -clean_line, self._text._fontproperties, ismath=ismath) +line, self._text._fontproperties, ismath=ismath) self._baseline_transform.clear() -if len(info) > 1 and self._multilinebaseline: # multi line -d = h-(hh-dd) # the baseline of the first line +d = h-(hh-dd) # the baseline of the first line +if len(info) > 1 and self._multilinebaseline: d_new = 0.5 * h - 0.5 * (h_ - d_) - self._baseline_transform.translate(0, d - d_new) d = d_new else: # single line -h_d = max(h_ - d_, h-dd) +h_d = max(h_ - d_, h-d) if self.get_minimumdescent(): ## to have a minimum descent, #i.e., "l" and "p" have same ## descents. -d = max(dd, d_) -else: -d = dd +d = max(d, d_) +#else: +#d = d h = h_d + d This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. -- Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p ___ Matplotlib-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
