Revision: 7921
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7921&view=rev
Author: mdboom
Date: 2009-11-03 16:11:07 +0000 (Tue, 03 Nov 2009)
Log Message:
-----------
[2890979] Close paths correctly in PolyCollection
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/collections.py
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_axes/imshow_clip.pdf
trunk/matplotlib/lib/matplotlib/tests/test_axes.py
trunk/matplotlib/src/_backend_agg.cpp
trunk/matplotlib/src/_backend_agg.h
Added Paths:
-----------
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_axes/polycollection_joinstyle.pdf
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_axes/polycollection_joinstyle.png
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_axes/polycollection_joinstyle.svg
Modified: trunk/matplotlib/lib/matplotlib/collections.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/collections.py 2009-11-03 16:00:13 UTC
(rev 7920)
+++ trunk/matplotlib/lib/matplotlib/collections.py 2009-11-03 16:11:07 UTC
(rev 7921)
@@ -574,14 +574,19 @@
if closed:
self._paths = []
for xy in verts:
- if np.ma.isMaskedArray(xy):
- if len(xy) and (xy[0] != xy[-1]).any():
- xy = np.ma.concatenate([xy, [xy[0]]])
+ if len(xy):
+ if np.ma.isMaskedArray(xy):
+ xy = np.ma.concatenate([xy, np.zeros((1,2))])
+ else:
+ xy = np.asarray(xy)
+ xy = np.concatenate([xy, np.zeros((1,2))])
+ codes = np.empty(xy.shape[0], dtype=mpath.Path.code_type)
+ codes[:] = mpath.Path.LINETO
+ codes[0] = mpath.Path.MOVETO
+ codes[-1] = mpath.Path.CLOSEPOLY
+ self._paths.append(mpath.Path(xy, codes))
else:
- xy = np.asarray(xy)
- if len(xy) and (xy[0] != xy[-1]).any():
- xy = np.concatenate([xy, [xy[0]]])
- self._paths.append(mpath.Path(xy))
+ self._paths.append(mpath.Path(xy))
else:
self._paths = [mpath.Path(xy) for xy in verts]
Modified:
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_axes/imshow_clip.pdf
===================================================================
(Binary files differ)
Added:
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_axes/polycollection_joinstyle.pdf
===================================================================
(Binary files differ)
Property changes on:
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_axes/polycollection_joinstyle.pdf
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_axes/polycollection_joinstyle.png
===================================================================
(Binary files differ)
Property changes on:
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_axes/polycollection_joinstyle.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_axes/polycollection_joinstyle.svg
===================================================================
---
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_axes/polycollection_joinstyle.svg
(rev 0)
+++
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_axes/polycollection_joinstyle.svg
2009-11-03 16:11:07 UTC (rev 7921)
@@ -0,0 +1,50 @@
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Created with matplotlib (http://matplotlib.sourceforge.net/) -->
+<svg width="576pt" height="432pt" viewBox="0 0 576 432"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ version="1.1"
+ id="svg1">
+<filter id="colorAdd"><feComposite in="SourceGraphic" in2="BackgroundImage"
operator="arithmetic" k2="1" k3="1"/></filter>
+<g id="figure1">
+<g id="patch1">
+<path style="fill: #ffffff; stroke: #ffffff; stroke-width: 1.000000;
stroke-linejoin: round; stroke-linecap: square; opacity: 1.000000"
d="M0.000000 432.000000L576.000000 432.000000L576.000000 0.000000
+L0.000000 0.000000L0.000000 432.000000"/>
+</g>
+<g id="axes1">
+<g id="patch2">
+<path style="fill: #ffffff; opacity: 1.000000" d="M72.000000
388.800000L518.400000 388.800000L518.400000 43.200000
+L72.000000 43.200000L72.000000 388.800000"/>
+</g>
+<g id="PolyCollection1">
+<defs>
+<path id="coll0_0_19e93e5df12bdd5a95009dd1dd45c12d" d="M220.800000
-158.400000L220.800000 -273.600000L369.600000 -273.600000
+L369.600000 -158.400000z"/>
+</defs>
+<defs>
+ <clipPath id="p50431ccdcb28178602d99d9270004dde">
+<rect x="72.000000" y="43.200000" width="446.400000" height="345.600000"/>
+ </clipPath>
+</defs><g clip-path="url(#p50431ccdcb28178602d99d9270004dde)"><use
style="fill: #0000ff; stroke: #000000; stroke-width: 40.000000;
stroke-linejoin: round; stroke-linecap: butt; opacity: 1.000000"
xlink:href="#coll0_0_19e93e5df12bdd5a95009dd1dd45c12d" x="0.000000"
y="432.000000"/>
+</g></g>
+<g id="matplotlib.axis1">
+</g>
+<g id="matplotlib.axis2">
+</g>
+<g id="patch3">
+<path style="fill: none; stroke: #000000; stroke-width: 1.000000;
stroke-linejoin: round; stroke-linecap: square; opacity: 1.000000"
d="M72.000000 43.200000L518.400000 43.200000"/>
+</g>
+<g id="patch4">
+<path style="fill: none; stroke: #000000; stroke-width: 1.000000;
stroke-linejoin: round; stroke-linecap: square; opacity: 1.000000"
d="M518.400000 388.800000L518.400000 43.200000"/>
+</g>
+<g id="patch5">
+<path style="fill: none; stroke: #000000; stroke-width: 1.000000;
stroke-linejoin: round; stroke-linecap: square; opacity: 1.000000"
d="M72.000000 388.800000L518.400000 388.800000"/>
+</g>
+<g id="patch6">
+<path style="fill: none; stroke: #000000; stroke-width: 1.000000;
stroke-linejoin: round; stroke-linecap: square; opacity: 1.000000"
d="M72.000000 388.800000L72.000000 43.200000"/>
+</g>
+</g>
+</g>
+</svg>
Modified: trunk/matplotlib/lib/matplotlib/tests/test_axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/tests/test_axes.py 2009-11-03 16:00:13 UTC
(rev 7920)
+++ trunk/matplotlib/lib/matplotlib/tests/test_axes.py 2009-11-03 16:11:07 UTC
(rev 7921)
@@ -407,7 +407,24 @@
ax.imshow(r, clip_path=clip_path)
fig.savefig('imshow_clip')
+...@image_comparison(baseline_images=['polycollection_joinstyle'])
+def test_polycollection_joinstyle():
+ # Bug #2890979 reported by Matthew West
+ from matplotlib import collections as mcoll
+
+ fig = plt.figure()
+ ax = fig.add_subplot(111)
+ verts = np.array([[1,1], [1,2], [2,2], [2,1]])
+ c = mcoll.PolyCollection([verts], linewidths = 40)
+ ax.add_collection(c)
+ ax.set_xbound(0, 3)
+ ax.set_ybound(0, 3)
+ ax.set_xticks([])
+ ax.set_yticks([])
+
+ fig.savefig('polycollection_joinstyle')
+
if __name__=='__main__':
import nose
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
Modified: trunk/matplotlib/src/_backend_agg.cpp
===================================================================
--- trunk/matplotlib/src/_backend_agg.cpp 2009-11-03 16:00:13 UTC (rev
7920)
+++ trunk/matplotlib/src/_backend_agg.cpp 2009-11-03 16:11:07 UTC (rev
7921)
@@ -147,8 +147,7 @@
}
GCAgg::GCAgg(const Py::Object &gc, double dpi) :
- dpi(dpi), isaa(true), linewidth(1.0), alpha(1.0),
- dashOffset(0.0)
+ dpi(dpi), isaa(true), dashOffset(0.0)
{
_VERBOSE("GCAgg::GCAgg");
linewidth = points_to_pixels ( gc.getAttr("_linewidth") ) ;
@@ -164,13 +163,6 @@
_set_hatch_path(gc);
}
-GCAgg::GCAgg(double dpi) :
- dpi(dpi), isaa(true), linewidth(1.0), alpha(1.0),
- dashOffset(0.0)
-{
-
-}
-
void
GCAgg::_set_antialiased(const Py::Object& gc) {
_VERBOSE("GCAgg::antialiased");
@@ -219,11 +211,11 @@
std::string joinstyle = Py::String( gc.getAttr("_joinstyle") );
- if (joinstyle=="miter")
- join = agg::miter_join_revert;
- else if (joinstyle=="round")
+ if (joinstyle == "miter")
+ join = agg::miter_join_revert;
+ else if (joinstyle == "round")
join = agg::round_join;
- else if(joinstyle=="bevel")
+ else if (joinstyle == "bevel")
join = agg::bevel_join;
else
throw Py::ValueError(Printf("GC _joinstyle attribute must be one of butt,
round, projecting; found %s", joinstyle.c_str()).str());
@@ -532,7 +524,7 @@
if (args.size() == 6)
face_obj = args[5];
- GCAgg gc = GCAgg(gc_obj, dpi);
+ GCAgg gc(gc_obj, dpi);
// Deal with the difference in y-axis direction
marker_trans *= agg::trans_affine_scaling(1.0, -1.0);
@@ -775,7 +767,7 @@
double angle = Py::Float( args[3] );
- GCAgg gc = GCAgg(args[4], dpi);
+ GCAgg gc(args[4], dpi);
theRasterizer.reset_clipping();
rendererBase.reset_clipping(true);
@@ -1081,7 +1073,8 @@
template<class PathGenerator, int check_snap, int has_curves>
Py::Object
RendererAgg::_draw_path_collection_generic
- (agg::trans_affine master_transform,
+ (GCAgg& gc,
+ agg::trans_affine master_transform,
const Py::Object& cliprect,
const Py::Object& clippath,
const agg::trans_affine& clippath_trans,
@@ -1101,8 +1094,6 @@
typedef agg::conv_curve<quantized_t>
quantized_curve_t;
typedef agg::conv_curve<clipped_t> curve_t;
- GCAgg gc(dpi);
-
PyArrayObject* offsets = NULL;
PyArrayObject* facecolors = NULL;
PyArrayObject* edgecolors = NULL;
@@ -1312,7 +1303,8 @@
try {
_draw_path_collection_generic<PathListGenerator, 0, 1>
- (master_transform,
+ (gc,
+ master_transform,
gc.cliprect,
gc.clippath,
gc.clippath_trans,
@@ -1449,7 +1441,8 @@
try {
try {
_draw_path_collection_generic<QuadMeshGenerator, 0, 0>
- (master_transform,
+ (gc,
+ master_transform,
gc.cliprect,
gc.clippath,
gc.clippath_trans,
Modified: trunk/matplotlib/src/_backend_agg.h
===================================================================
--- trunk/matplotlib/src/_backend_agg.h 2009-11-03 16:00:13 UTC (rev 7920)
+++ trunk/matplotlib/src/_backend_agg.h 2009-11-03 16:11:07 UTC (rev 7921)
@@ -104,7 +104,6 @@
class GCAgg {
public:
GCAgg(const Py::Object& gc, double dpi);
- GCAgg(double dpi);
double dpi;
bool isaa;
@@ -224,15 +223,16 @@
bool render_clippath(const Py::Object& clippath, const agg::trans_affine&
clippath_trans);
template<class PathIteratorType>
void _draw_path(PathIteratorType& path, bool has_clippath,
- const facepair_t& face, const GCAgg& gc);
+ const facepair_t& face, const GCAgg& gc);
template<class PathGenerator, int check_snap, int has_curves>
Py::Object
_draw_path_collection_generic
- (agg::trans_affine master_transform,
- const Py::Object& cliprect,
- const Py::Object& clippath,
+ (GCAgg& gc,
+ agg::trans_affine master_transform,
+ const Py::Object& cliprect,
+ const Py::Object& clippath,
const agg::trans_affine& clippath_trans,
- const PathGenerator& path_generator,
+ const PathGenerator& path_generator,
const Py::SeqBase<Py::Object>& transforms_obj,
const Py::Object& offsets_obj,
const agg::trans_affine& offset_trans,
@@ -262,7 +262,7 @@
BufferRegion::init_type();
add_keyword_method("RendererAgg", &_backend_agg_module::new_renderer,
- "RendererAgg(width, height, dpi)");
+ "RendererAgg(width, height, dpi)");
initialize( "The agg rendering backend" );
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins