|
From: <md...@us...> - 2009-12-31 16:46:06
|
Revision: 8059
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8059&view=rev
Author: mdboom
Date: 2009-12-31 16:45:59 +0000 (Thu, 31 Dec 2009)
Log Message:
-----------
Add support for mathtext markers (thanks to tcb for original work)
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/examples/pylab_examples/line_styles.py
trunk/matplotlib/lib/matplotlib/cbook.py
trunk/matplotlib/lib/matplotlib/lines.py
trunk/matplotlib/lib/matplotlib/text.py
trunk/matplotlib/src/_path.cpp
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2009-12-31 15:48:55 UTC (rev 8058)
+++ trunk/matplotlib/CHANGELOG 2009-12-31 16:45:59 UTC (rev 8059)
@@ -1,3 +1,6 @@
+2009-12-31 Add support for using math text as marker symbols (Thanks to tcb)
+ - MGD
+
2009-12-31 Commit a workaround for a regression in PyQt4-4.6.{0,1} - DSD
2009-12-22 Fix cmap data for gist_earth_r, etc. -JJL
@@ -20,7 +23,7 @@
Added new examples. - JJL
2009-12-01 Applied Laurent Dufrechou's patch to improve blitting with
- the qt4 backend - DSD
+ the qt4 backend - DSD
2009-11-13 The pdf backend now allows changing the contents of
a pdf file's information dictionary via PdfPages.infodict. - JKS
@@ -153,35 +156,35 @@
2009-08-06 Tagging the 0.99.0 release at svn r7397 - JDH
- * fixed an alpha colormapping bug posted on sf 2832575
+ * fixed an alpha colormapping bug posted on sf 2832575
- * fix typo in axes_divider.py. use nanmin, nanmax in angle_helper.py
+ * fix typo in axes_divider.py. use nanmin, nanmax in angle_helper.py
(patch by Christoph Gohlke)
- * remove dup gui event in enter/leave events in gtk
+ * remove dup gui event in enter/leave events in gtk
- * lots of fixes for os x binaries (Thanks Russell Owen)
+ * lots of fixes for os x binaries (Thanks Russell Owen)
- * attach gtk events to mpl events -- fixes sf bug 2816580
+ * attach gtk events to mpl events -- fixes sf bug 2816580
- * applied sf patch 2815064 (middle button events for wx) and
+ * applied sf patch 2815064 (middle button events for wx) and
patch 2818092 (resize events for wx)
- * fixed boilerplate.py so it doesn't break the ReST docs.
+ * fixed boilerplate.py so it doesn't break the ReST docs.
- * removed a couple of cases of mlab.load
+ * removed a couple of cases of mlab.load
- * fixed rec2csv win32 file handle bug from sf patch 2831018
+ * fixed rec2csv win32 file handle bug from sf patch 2831018
- * added two examples from Josh Hemann: examples/pylab_examples/barchart_demo2.py
+ * added two examples from Josh Hemann: examples/pylab_examples/barchart_demo2.py
and examples/pylab_examples/boxplot_demo2.py
- * handled sf bugs 2831556 and 2830525; better bar error messages and
+ * handled sf bugs 2831556 and 2830525; better bar error messages and
backend driver configs
- * added miktex win32 patch from sf patch 2820194
+ * added miktex win32 patch from sf patch 2820194
- * apply sf patches 2830233 and 2823885 for osx setup and 64 bit; thanks Michiel
+ * apply sf patches 2830233 and 2823885 for osx setup and 64 bit; thanks Michiel
2009-08-04 Made cbook.get_sample_data make use of the ETag and Last-Modified
headers of mod_dav_svn. - JKS
Modified: trunk/matplotlib/examples/pylab_examples/line_styles.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/line_styles.py 2009-12-31 15:48:55 UTC (rev 8058)
+++ trunk/matplotlib/examples/pylab_examples/line_styles.py 2009-12-31 16:45:59 UTC (rev 8059)
@@ -17,19 +17,28 @@
except TypeError:
pass
-styles = linestyles + markers
+styles = markers + [
+ r'$\lambda$',
+ r'$\bowtie$',
+ r'$\circlearrowleft$',
+ r'$\clubsuit$',
+ r'$\checkmark$']
colors = ('b', 'g', 'r', 'c', 'm', 'y', 'k')
+plt.figure(figsize=(8,8))
axisNum = 0
-for row in range(5):
+for row in range(6):
for col in range(5):
axisNum += 1
- ax = plt.subplot(5, 5, axisNum)
- style = styles[axisNum % len(styles) ]
- color = colors[axisNum % len(colors) ]
- plt.plot(t,s, style + color, markersize=10)
+ ax = plt.subplot(6, 5, axisNum)
+ color = colors[axisNum % len(colors)]
+ if axisNum < len(linestyles):
+ plt.plot(t, s, linestyles[axisNum], color=color, markersize=10)
+ else:
+ style = styles[(axisNum - len(linestyles)) % len(styles)]
+ plt.plot(t, s, linestyle='None', marker=style, color=color, markersize=10)
ax.set_yticklabels([])
ax.set_xticklabels([])
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py 2009-12-31 15:48:55 UTC (rev 8058)
+++ trunk/matplotlib/lib/matplotlib/cbook.py 2009-12-31 16:45:59 UTC (rev 8059)
@@ -1676,8 +1676,17 @@
else:
break
+def is_math_text(s):
+ # Did we find an even number of non-escaped dollar signs?
+ # If so, treat is as math text.
+ s = unicode(s)
+ dollar_count = s.count(r'$') - s.count(r'\$')
+ even_dollars = (dollar_count > 0 and dollar_count % 2 == 0)
+ return even_dollars
+
+
if __name__=='__main__':
assert( allequal([1,1,1]) )
assert(not allequal([1,1,0]) )
Modified: trunk/matplotlib/lib/matplotlib/lines.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/lines.py 2009-12-31 15:48:55 UTC (rev 8058)
+++ trunk/matplotlib/lib/matplotlib/lines.py 2009-12-31 16:45:59 UTC (rev 8059)
@@ -12,7 +12,7 @@
import artist
from artist import Artist
from cbook import iterable, is_string_like, is_numlike, ls_mapper, dedent,\
-flatten
+flatten, is_math_text
from colors import colorConverter
from path import Path
from transforms import Affine2D, Bbox, TransformedPath, IdentityTransform
@@ -20,6 +20,7 @@
from matplotlib import rcParams
from artist import allow_rasterization
from matplotlib import docstring
+from matplotlib.font_manager import FontProperties
# special-purpose marker identifiers:
(TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN,
@@ -139,7 +140,7 @@
}
filled_markers = ('o', '^', 'v', '<', '>',
- 's', 'd', 'D', 'h', 'H', 'p', '*')
+ 's', 'd', 'D', 'h', 'H', 'p', '*')
zorder = 2
validCap = ('butt', 'round', 'projecting')
@@ -535,7 +536,7 @@
gc.set_foreground(self.get_markeredgecolor())
gc.set_linewidth(self._markeredgewidth)
gc.set_alpha(self._alpha)
- funcname = self._markers.get(self._marker, '_draw_nothing')
+ funcname = self._markerFunc
if funcname != '_draw_nothing':
tpath, affine = self._transformed_path.get_transformed_points_and_affine()
if len(tpath.vertices):
@@ -573,7 +574,8 @@
def get_markeredgecolor(self):
if (is_string_like(self._markeredgecolor) and
self._markeredgecolor == 'auto'):
- if self._marker in self.filled_markers:
+ if (self._marker in self.filled_markers or
+ is_math_text(self._marker)):
return 'k'
else:
return self._color
@@ -774,6 +776,7 @@
'None' nothing
' ' nothing
'' nothing
+ '$...$' render the string using mathtext
========== ==========================
@@ -782,16 +785,18 @@
| '<' | '>' | 'D' | 'H' | '^' | '_' | 'd'
| 'h' | 'o' | 'p' | 's' | 'v' | 'x' | '|'
| TICKUP | TICKDOWN | TICKLEFT | TICKRIGHT
- | 'None' | ' ' | '' ]
+ | 'None' | ' ' | '' | '$...$']
"""
- if marker not in self._markers:
+ if marker in self._markers:
+ self._marker = marker
+ self._markerFunc = self._markers[marker]
+ elif is_math_text(marker):
+ self._marker = marker
+ self._markerFunc = '_draw_mathtext_path'
+ else: #already handle ' ', '' in marker list
verbose.report('Unrecognized marker style %s, %s' %
(marker, type(marker)))
- if marker in [' ','']:
- marker = 'None'
- self._marker = marker
- self._markerFunc = self._markers[marker]
def set_markeredgecolor(self, ec):
"""
@@ -867,6 +872,38 @@
def _draw_lines(self, renderer, gc, path, trans):
self._lineFunc(renderer, gc, path, trans)
+ def _draw_mathtext_path(self, renderer, gc, path, trans):
+ """
+ Draws mathtext markers '$...$' using TextPath object.
+
+ Submitted by tcb
+ """
+ from matplotlib.patches import PathPatch
+ from matplotlib.text import TextPath
+
+ gc.set_snap(False)
+
+ # again, the properties could be initialised just once outside
+ # this function
+ # Font size is irrelevant here, it will be rescaled based on
+ # the drawn size later
+ props = FontProperties(size=1.0)
+ text = TextPath(xy=(0,0), s=self.get_marker(), fontproperties=props,
+ usetex=rcParams['text.usetex'])
+ if len(text.vertices) == 0:
+ return
+ xmin, ymin = text.vertices.min(axis=0)
+ xmax, ymax = text.vertices.max(axis=0)
+ width = xmax - xmin
+ height = ymax - ymin
+ max_dim = max(width, height)
+ path_trans = Affine2D() \
+ .translate(0.5 * -width, 0.5 * -height) \
+ .scale((renderer.points_to_pixels(self.get_markersize()) / max_dim))
+
+ rgbFace = self._get_rgb_face()
+ renderer.draw_markers(gc, text, path_trans, path, trans, rgbFace)
+
def _draw_steps_pre(self, renderer, gc, path, trans):
vertices = self._xy
steps = ma.zeros((2*len(vertices)-1, 2), np.float_)
@@ -1288,6 +1325,7 @@
self._linestyle = other._linestyle
self._marker = other._marker
+ self._markerFunc = other._markerFunc
self._drawstyle = other._drawstyle
Modified: trunk/matplotlib/lib/matplotlib/text.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/text.py 2009-12-31 15:48:55 UTC (rev 8058)
+++ trunk/matplotlib/lib/matplotlib/text.py 2009-12-31 16:45:59 UTC (rev 8059)
@@ -997,13 +997,10 @@
"""
# Did we find an even number of non-escaped dollar signs?
# If so, treat is as math text.
- dollar_count = s.count(r'$') - s.count(r'\$')
- even_dollars = (dollar_count > 0 and dollar_count % 2 == 0)
-
if rcParams['text.usetex']:
return s, 'TeX'
- if even_dollars:
+ if cbook.is_math_text(s):
return s, True
else:
return s.replace(r'\$', '$'), False
Modified: trunk/matplotlib/src/_path.cpp
===================================================================
--- trunk/matplotlib/src/_path.cpp 2009-12-31 15:48:55 UTC (rev 8058)
+++ trunk/matplotlib/src/_path.cpp 2009-12-31 16:45:59 UTC (rev 8059)
@@ -922,9 +922,13 @@
vertices = (PyArrayObject*)PyArray_FromObject
(vertices_obj.ptr(), PyArray_DOUBLE, 1, 2);
if (!vertices ||
- (PyArray_NDIM(vertices) == 2 && PyArray_DIM(vertices, 1) != 2) ||
- (PyArray_NDIM(vertices) == 1 && PyArray_DIM(vertices, 0) != 2))
+ (PyArray_NDIM(vertices) == 2 && PyArray_DIM(vertices, 0) != 0 &&
+ PyArray_DIM(vertices, 1) != 2) ||
+ (PyArray_NDIM(vertices) == 1 &&
+ PyArray_DIM(vertices, 0) != 2 && PyArray_DIM(vertices, 0) != 0))
+ {
throw Py::ValueError("Invalid vertices array.");
+ }
transform = (PyArrayObject*) PyArray_FromObject
(transform_obj.ptr(), PyArray_DOUBLE, 2, 2);
@@ -979,7 +983,7 @@
vertex_in += stride0;
}
}
- else
+ else if (PyArray_DIM(vertices, 0) != 0)
{
char* vertex_in = PyArray_BYTES(vertices);
double* vertex_out = (double*)PyArray_DATA(result);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|