Revision: 7270
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7270&view=rev
Author: jouni
Date: 2009-07-18 08:35:56 +0000 (Sat, 18 Jul 2009)
Log Message:
-----------
Fix support for hatches without color fills to pdf and svg backends.
Add an example of that to hatch_demo.py.
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/examples/pylab_examples/hatch_demo.py
trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2009-07-17 20:03:21 UTC (rev 7269)
+++ trunk/matplotlib/CHANGELOG 2009-07-18 08:35:56 UTC (rev 7270)
@@ -1,3 +1,6 @@
+2009-07-18 Fix support for hatches without color fills to pdf and svg
+ backends. Add an example of that to hatch_demo.py. - JKS
+
2009-07-17 Removed fossils from swig version of agg backend. - EF
2009-07-14 initial submission of the annotation guide. -JJL
Modified: trunk/matplotlib/examples/pylab_examples/hatch_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/hatch_demo.py 2009-07-17
20:03:21 UTC (rev 7269)
+++ trunk/matplotlib/examples/pylab_examples/hatch_demo.py 2009-07-18
08:35:56 UTC (rev 7270)
@@ -3,18 +3,29 @@
PDF, SVG and Agg backends only.
"""
import matplotlib.pyplot as plt
+from matplotlib.patches import Ellipse, Polygon
fig = plt.figure()
-ax1 = fig.add_subplot(121)
+ax1 = fig.add_subplot(131)
ax1.bar(range(1,5), range(1,5), color='red', edgecolor='black', hatch="/")
ax1.bar(range(1,5), [6] * 4, bottom=range(1,5), color='blue',
edgecolor='black', hatch='//')
+ax1.set_xticks([1.5,2.5,3.5,4.5])
-ax2 = fig.add_subplot(122)
+ax2 = fig.add_subplot(132)
bars = ax2.bar(range(1,5), range(1,5), color='yellow', ecolor='black') + \
ax2.bar(range(1, 5), [6] * 4, bottom=range(1,5), color='green',
ecolor='black')
+ax2.set_xticks([1.5,2.5,3.5,4.5])
patterns = ('-', '+', 'x', '\\', '*', 'o', 'O', '.')
for bar, pattern in zip(bars, patterns):
bar.set_hatch(pattern)
+ax3 = fig.add_subplot(133)
+ax3.fill([1,3,3,1],[1,1,2,2], fill=False, hatch='\\')
+ax3.add_patch(Ellipse((4,1.5), 4, 0.5, fill=False, hatch='*'))
+ax3.add_patch(Polygon([[0,0],[4,1.1],[6,2.5],[2,1.4]], closed=True,
+ fill=False, hatch='/'))
+ax3.set_xlim((0,6))
+ax3.set_ylim((0,2.5))
+
plt.show()
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2009-07-17
20:03:21 UTC (rev 7269)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2009-07-18
08:35:56 UTC (rev 7270)
@@ -1715,14 +1715,27 @@
return `d`
def _strokep(self):
+ """
+ Predicate: does the path need to be stroked (its outline drawn)?
+ This tests for the various conditions that disable stroking
+ the path, in which case it would presumably be filled.
+ """
return (self._linewidth > 0 and self._alpha > 0 and
(len(self._rgb) <= 3 or self._rgb[3] != 0.0))
def _fillp(self):
- return ((self._fillcolor is not None or self._hatch) and
- (len(self._fillcolor) <= 3 or self._fillcolor[3] != 0.0))
+ """
+ Predicate: does the path need to be filled?
+ """
+ return self._hatch or \
+ (self._fillcolor is not None and
+ (len(self._fillcolor) <= 3 or self._fillcolor[3] != 0.0))
def close_and_paint(self):
+ """
+ Return the appropriate pdf operator to close the path and
+ cause it to be stroked, filled, or both.
+ """
if self._strokep():
if self._fillp():
return Op.close_fill_stroke
@@ -1735,6 +1748,10 @@
return Op.endpath
def paint(self):
+ """
+ Return the appropriate pdf operator to cause the path to be
+ stroked, filled, or both.
+ """
if self._strokep():
if self._fillp():
return Op.fill_stroke
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2009-07-17
20:03:21 UTC (rev 7269)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2009-07-18
08:35:56 UTC (rev 7270)
@@ -102,9 +102,13 @@
path_data = self._convert_path(
gc.get_hatch_path(),
Affine2D().scale(HATCH_SIZE).scale(1.0, -1.0).translate(0,
HATCH_SIZE))
+ if rgbFace is None:
+ fill = 'none'
+ else:
+ fill = rgb2hex(rgbFace)
self._svgwriter.write(
'<rect x="0" y="0" width="%d" height="%d" fill="%s"/>' %
- (HATCH_SIZE+1, HATCH_SIZE+1, rgb2hex(rgbFace)))
+ (HATCH_SIZE+1, HATCH_SIZE+1, fill))
path = '<path d="%s" fill="%s" stroke="%s" stroke-width="1.0"/>' %
(
path_data, rgb2hex(gc.get_rgb()[:3]),
rgb2hex(gc.get_rgb()[:3]))
self._svgwriter.write(path)
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