SF.net SVN: matplotlib:[7265] trunk/matplotlib

2009-07-17 Thread heeres
Revision: 7265
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7265&view=rev
Author:   heeres
Date: 2009-07-17 07:24:06 + (Fri, 17 Jul 2009)

Log Message:
---
mplot3d: add bar3d, improve z-sort, hist3d example

Modified Paths:
--
trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py
trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py

Added Paths:
---
trunk/matplotlib/examples/mplot3d/hist3d_demo.py

Added: trunk/matplotlib/examples/mplot3d/hist3d_demo.py
===
--- trunk/matplotlib/examples/mplot3d/hist3d_demo.py
(rev 0)
+++ trunk/matplotlib/examples/mplot3d/hist3d_demo.py2009-07-17 07:24:06 UTC 
(rev 7265)
@@ -0,0 +1,27 @@
+from mpl_toolkits.mplot3d import Axes3D
+from matplotlib.collections import PolyCollection
+from matplotlib.colors import colorConverter
+import pylab
+import random
+import numpy as np
+
+fig = pylab.figure()
+ax = Axes3D(fig)
+x = np.random.rand(100) * 4
+y = np.random.rand(100) * 4
+hist, xedges, yedges = np.histogram2d(x, y, bins=4)
+
+elements = (len(xedges) - 1) * (len(yedges) - 1)
+xpos, ypos = np.meshgrid(
+[xedges[i] + 0.25 for i in range(len(xedges) - 1)],
+[yedges[i] + 0.25 for i in range(len(yedges) - 1)])
+xpos = xpos.flatten()
+ypos = ypos.flatten()
+zpos = [0] * elements
+dx = [0.5] * elements
+dy = [0.5] * elements
+dz = hist.flatten()
+ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b')
+
+pylab.show()
+

Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py
===
--- trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py  2009-07-16 20:53:24 UTC 
(rev 7264)
+++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py  2009-07-17 07:24:06 UTC 
(rev 7265)
@@ -271,6 +271,7 @@
 
 PolyCollection.__init__(self, verts, *args, **kwargs)
 self._zsort = 1
+self._sort_zpos = None
 
 def get_vector(self, segments3d):
 """Optimize points for projection"""
@@ -287,7 +288,6 @@
 ones = np.ones(len(xs))
 self._vec = np.array([xs, ys, zs, ones])
 self._segis = segis
-self._sort_zpos = min(zs)
 
 def set_verts(self, verts, closed=True):
 '''Set 3D vertices.'''
@@ -297,9 +297,13 @@
 
 def set_3d_properties(self):
 self._zsort = 1
+self._sort_zpos = None
 self._facecolors3d = PolyCollection.get_facecolors(self)
 self._edgecolors3d = PolyCollection.get_edgecolors(self)
 
+def set_sort_zpos(self, val):
+self._sort_zpos = val
+
 def do_3d_projection(self, renderer):
 '''
 Perform the 3D projection for this object.
@@ -315,17 +319,19 @@
 
 # This extra fuss is to re-order face / edge colors
 cface = self._facecolors3d
-if len(self._edgecolors3d) != len(cface):
-cedge = cface
-else:
-cedge = self._edgecolors3d
+cedge = self._edgecolors3d
+if len(cface) != len(xyzlist):
+cface = cface.repeat(len(xyzlist), axis=0)
+if len(cedge) != len(xyzlist):
+if len(cedge) == 0:
+cedge = cface
+cedge = cedge.repeat(len(xyzlist), axis=0)
 
 # if required sort by depth (furthest drawn first)
 if self._zsort:
-z_segments_2d = [(min(zs), zip(xs, ys), fc, ec) for
+z_segments_2d = [(np.average(zs), zip(xs, ys), fc, ec) for
 (xs, ys, zs), fc, ec in zip(xyzlist, cface, cedge)]
-z_segments_2d.sort()
-z_segments_2d.reverse()
+z_segments_2d.sort(reverse=True)
 else:
 raise ValueError, "whoops"
 
@@ -339,9 +345,12 @@
 self._edgecolors2d = self._edgecolors3d
 
 # Return zorder value
-zvec = np.array([[0], [0], [self._sort_zpos], [1]])
-ztrans = proj3d.proj_transform_vec(zvec, renderer.M)
-return ztrans[2][0]
+if self._sort_zpos is not None:
+   zvec = np.array([[0], [0], [self._sort_zpos], [1]])
+   ztrans = proj3d.proj_transform_vec(zvec, renderer.M)
+   return ztrans[2][0]
+else:
+return np.min(tzs)
 
 def set_facecolor(self, colors):
 PolyCollection.set_facecolor(self, colors)

Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py
===
--- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009-07-16 20:53:24 UTC 
(rev 7264)
+++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009-07-17 07:24:06 UTC 
(rev 7265)
@@ -625,6 +625,20 @@
 
 return polyc
 
+def _generate_normals(self, polygons):
+'''
+Generate normals for polygons by using the first three points.
+This normal of course might not make sense for polygons with
+more than three points not lying in a plane.
+'''
+
+

SF.net SVN: matplotlib:[7266] branches/mathtex/lib/matplotlib/backends/ backend_agg.py

2009-07-17 Thread evilguru
Revision: 7266
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7266&view=rev
Author:   evilguru
Date: 2009-07-17 15:24:27 + (Fri, 17 Jul 2009)

Log Message:
---
Port the AGG backend over to mathtex. More testing still needed.

Modified Paths:
--
branches/mathtex/lib/matplotlib/backends/backend_agg.py

Modified: branches/mathtex/lib/matplotlib/backends/backend_agg.py
===
--- branches/mathtex/lib/matplotlib/backends/backend_agg.py 2009-07-17 
07:24:06 UTC (rev 7265)
+++ branches/mathtex/lib/matplotlib/backends/backend_agg.py 2009-07-17 
15:24:27 UTC (rev 7266)
@@ -31,13 +31,15 @@
 from matplotlib.figure import Figure
 from matplotlib.font_manager import findfont
 from matplotlib.ft2font import FT2Font, LOAD_FORCE_AUTOHINT
-from matplotlib.mathtext import MathTextParser
 from matplotlib.path import Path
 from matplotlib.transforms import Bbox, BboxBase
 
 from _backend_agg import RendererAgg as _RendererAgg
 from matplotlib import _png
 
+from mathtex.mathtex_main import Mathtex
+from mathtex.backends.backend_image import MathtexBackendImage
+
 backend_version = 'v2.2'
 
 class RendererAgg(RendererBase):
@@ -66,7 +68,6 @@
 self.draw_image = self._renderer.draw_image
 self.copy_from_bbox = self._renderer.copy_from_bbox
 self.tostring_rgba_minimized = self._renderer.tostring_rgba_minimized
-self.mathtext_parser = MathTextParser('Agg')
 
 self.bbox = Bbox.from_bounds(0, 0, self.width, self.height)
 if __debug__: verbose.report('RendererAgg.__init__ done',
@@ -99,17 +100,17 @@
 
 def draw_mathtext(self, gc, x, y, s, prop, angle):
 """
-Draw the math text using matplotlib.mathtext
+Draw the math text using mathtex.mathtex_main
 """
 if __debug__: verbose.report('RendererAgg.draw_mathtext',
  'debug-annoying')
-ox, oy, width, height, descent, font_image, used_characters = \
-self.mathtext_parser.parse(s, self.dpi, prop)
+m = Mathtex(s, rcParams['mathtext.fontset'], 
prop.get_size_in_points(), self.dpi)
+b = MathtexBackendImage()
 
-x = int(x) + ox
-y = int(y) - oy
-self._renderer.draw_text_image(font_image, x, y + 1, angle, gc)
+m.render_to_backend(b)
 
+self._renderer.draw_text_image(b.image, int(x), int(y) + 1, angle, gc)
+
 def draw_text(self, gc, x, y, s, prop, angle, ismath):
 """
 Render the text
@@ -152,9 +153,8 @@
 return w, h, d
 
 if ismath:
-ox, oy, width, height, descent, fonts, used_characters = \
-self.mathtext_parser.parse(s, self.dpi, prop)
-return width, height, descent
+m = Mathtex(s, rcParams['mathtext.fontset'], 
prop.get_size_in_points(), self.dpi)
+return m.width, m.height, m.depth
 font = self._get_agg_font(prop)
 font.set_text(s, 0.0, flags=LOAD_FORCE_AUTOHINT)  # the width and 
height of unrotated string
 w, h = font.get_width_height()


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

--
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins


SF.net SVN: matplotlib:[7267] branches/mathtex/lib/matplotlib/backends/ backend_gdk.py

2009-07-17 Thread evilguru
Revision: 7267
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7267&view=rev
Author:   evilguru
Date: 2009-07-17 18:44:30 + (Fri, 17 Jul 2009)

Log Message:
---
Port the GDK backend over to mathtex.

Modified Paths:
--
branches/mathtex/lib/matplotlib/backends/backend_gdk.py

Modified: branches/mathtex/lib/matplotlib/backends/backend_gdk.py
===
--- branches/mathtex/lib/matplotlib/backends/backend_gdk.py 2009-07-17 
15:24:27 UTC (rev 7266)
+++ branches/mathtex/lib/matplotlib/backends/backend_gdk.py 2009-07-17 
18:44:30 UTC (rev 7267)
@@ -24,10 +24,11 @@
  FigureManagerBase, FigureCanvasBase
 from matplotlib.cbook import is_string_like
 from matplotlib.figure import Figure
-from matplotlib.mathtext import MathTextParser
 from matplotlib.transforms import Affine2D
 from matplotlib.backends._backend_gdk import pixbuf_get_pixels_array
 
+from mathtex.mathtex_main import Mathtex
+from mathtex.backends.backend_image import MathtexBackendImage
 
 backend_version = "%d.%d.%d" % gtk.pygtk_version
 _debug = False
@@ -71,7 +72,6 @@
 self.gtkDA = gtkDA
 self.dpi   = dpi
 self._cmap = gtkDA.get_colormap()
-self.mathtext_parser = MathTextParser("Agg")
 
 def set_pixmap (self, pixmap):
 self.gdkDrawable = pixmap
@@ -159,9 +159,14 @@
 
 
 def _draw_mathtext(self, gc, x, y, s, prop, angle):
-ox, oy, width, height, descent, font_image, used_characters = \
-self.mathtext_parser.parse(s, self.dpi, prop)
+m = Mathtex(s, matplotlib.rcParams['mathtext.fontset'],
+prop.get_size_in_points(), self.dpi)
+b = MathtexBackendImage()
+m.render_to_backend(b)
 
+width, height = m.width, m.height + m.depth
+font_image = b.image
+
 if angle==90:
 width, height = height, width
 x -= width
@@ -300,9 +305,9 @@
 
 def get_text_width_height_descent(self, s, prop, ismath):
 if ismath:
-ox, oy, width, height, descent, font_image, used_characters = \
-self.mathtext_parser.parse(s, self.dpi, prop)
-return width, height, descent
+m = Mathtex(s, matplotlib.rcParams['mathtext.fontset'],
+prop.get_size_in_points(), self.dpi)
+return m.width, m.height, m.depth
 
 layout, inkRect, logicalRect = self._get_pango_layout(s, prop)
 l, b, w, h = inkRect


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

--
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins


SF.net SVN: matplotlib:[7269] branches/mathtex/lib/matplotlib/backends/ backend_pdf.py

2009-07-17 Thread evilguru
Revision: 7269
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7269&view=rev
Author:   evilguru
Date: 2009-07-17 20:03:21 + (Fri, 17 Jul 2009)

Log Message:
---
Add the PDF backend to the mathtex family. Resistance is futile.

Modified Paths:
--
branches/mathtex/lib/matplotlib/backends/backend_pdf.py

Modified: branches/mathtex/lib/matplotlib/backends/backend_pdf.py
===
--- branches/mathtex/lib/matplotlib/backends/backend_pdf.py 2009-07-17 
19:03:07 UTC (rev 7268)
+++ branches/mathtex/lib/matplotlib/backends/backend_pdf.py 2009-07-17 
20:03:21 UTC (rev 7269)
@@ -38,11 +38,12 @@
 import matplotlib.dviread as dviread
 from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE, \
 LOAD_NO_HINTING, KERNING_UNFITTED
-from matplotlib.mathtext import MathTextParser
 from matplotlib.transforms import Affine2D, Bbox, BboxBase, TransformedPath
 from matplotlib.path import Path
 from matplotlib import ttconv
 
+from mathtex.mathtex_main import Mathtex
+
 # Overview
 #
 # The low-level knowledge about pdf syntax lies mainly in the pdfRepr
@@ -1242,7 +1243,6 @@
 RendererBase.__init__(self)
 self.file = file
 self.gc = self.new_gc()
-self.mathtext_parser = MathTextParser("Pdf")
 self.image_dpi = image_dpi
 self.tex_font_map = None
 
@@ -1344,10 +1344,23 @@
 
 def draw_mathtext(self, gc, x, y, s, prop, angle):
 # TODO: fix positioning and encoding
-width, height, descent, glyphs, rects, used_characters = \
-self.mathtext_parser.parse(s, 72, prop)
+m = Mathtex(s, rcParams['mathtext.fontset'], 
prop.get_size_in_points(), 72.0)
+
+# Generate the dict of used characters
+used_characters = {}
+for ox, oy, info in m.glyphs:
+realpath, stat_key = get_realpath_and_stat(info.font.fname)
+used_font = used_characters.setdefault(stat_key, (realpath, set()))
+used_font[1].add(info.num)
+
 self.merge_used_characters(used_characters)
 
+# Extract the glyphs and rects to render
+glyphs = [(ox, m.height - oy + info.offset, info.font.fname,
+   info.fontsize, info.num, info.symbol_name)
+  for ox, oy, info in m.glyphs]
+rects = [(x1, m.height - y2, x2 - x1, y2 - y1) for x1, y1, x2, y2 in 
m.rects]
+
 # When using Type 3 fonts, we can't use character codes higher
 # than 255, so we use the "Do" command to render those
 # instead.
@@ -1641,8 +1654,9 @@
 return w, h, d
 
 if ismath:
-w, h, d, glyphs, rects, used_characters = \
-self.mathtext_parser.parse(s, 72, prop)
+m = Mathtex(s, rcParams['mathtext.fontset'],
+prop.get_size_in_points(), 72.0)
+w, h, d = m.width, m.height, m.depth
 
 elif rcParams['pdf.use14corefonts']:
 font = self._get_font_afm(prop)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

--
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins