Path.to_polygons problem

Hi all,
Using the last 1.0.1 matplotlib version,sometimes exporting paths to
polygons gives wrong results like here (paths come from a
tricontourset) :
In [94]: path
Out[94]:
Path([[ 172.0079229 -43.79390934]
[ 171.97660793 -43.785 ]
[ 171.96206864 -43.78273625]
[ 171.959 -43.78114859]
...
[ 171.593 -44.00678244]
[ 171.64906502 -44.01 ]
[ 171.654 -44.01077106]
[ 171.7068607 -44.0160044 ]], [1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2])
In [95]: path.vertices.shape
Out[95]: (210, 2)

but to_polygons gives another result :
In [98]: path.to_polygons()
Out[98]:
[array([[ 172.0079229 , -43.79390934],
       [ 171.86039224, -43.65 ],
       [ 172.081 , -43.54450289],
       [ 172.386 , -43.57010293],
       [ 172.60631978, -43.67753099],
       [ 172.59231502, -43.71219961],
       [ 172.325 , -43.78095532],
       [ 172.02 , -43.79497729]]),
array([[ 171.715 , -44.0160044 ],
       [ 173.02676111, -43.92 ],
       [ 172.935 , -43.53340591],
       [ 171.40281884, -43.70029758],
       [ 171.37760645, -43.94389688],
       [ 171.54044973, -44.0037666 ],
       [ 171.7068607 , -44.0160044 ],
       [ 171.7068607 , -44.0160044 ]])]

Cheers

···

--
Lionel Roubeyrie
lionel.roubeyrie@...149...
http://youarealegend.blogspot.com

It's not obvious to me that this is wrong. The path has a MOVETO command (1) in the middle, and thus should require the creation of two polygons. Can you provide some code or pictures that demonstrate the problem?

Mike

···

On 01/13/2011 05:54 PM, Lionel Roubeyrie wrote:

Hi all,
Using the last 1.0.1 matplotlib version,sometimes exporting paths to
polygons gives wrong results like here (paths come from a
tricontourset) :
In [94]: path
Out[94]:
Path([[ 172.0079229 -43.79390934]
  [ 171.97660793 -43.785 ]
  [ 171.96206864 -43.78273625]
  [ 171.959 -43.78114859]
  ...
  [ 171.593 -44.00678244]
  [ 171.64906502 -44.01 ]
  [ 171.654 -44.01077106]
  [ 171.7068607 -44.0160044 ]], [1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
  2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2
  2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
  2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2])
In [95]: path.vertices.shape
Out[95]: (210, 2)

but to_polygons gives another result :
In [98]: path.to_polygons()
Out[98]:
[array([[ 172.0079229 , -43.79390934],
        [ 171.86039224, -43.65 ],
        [ 172.081 , -43.54450289],
        [ 172.386 , -43.57010293],
        [ 172.60631978, -43.67753099],
        [ 172.59231502, -43.71219961],
        [ 172.325 , -43.78095532],
        [ 172.02 , -43.79497729]]),
  array([[ 171.715 , -44.0160044 ],
        [ 173.02676111, -43.92 ],
        [ 172.935 , -43.53340591],
        [ 171.40281884, -43.70029758],
        [ 171.37760645, -43.94389688],
        [ 171.54044973, -44.0037666 ],
        [ 171.7068607 , -44.0160044 ],
        [ 171.7068607 , -44.0160044 ]])]

Cheers

--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

The problem appends on some paths/polygons, not all. Have a look at
the joined pictures. The to_polygons method normally take care about
polygons holes, but here some vertices are not converted, resulting in
wrong geometries.

polygonisation.png

rpatch3.grid (37.7 KB)

paths.png

···

#############
import numpy as np
import pylab as plb
a=np.recfromtxt('rpatch3.grid', delimiter='\t',names=True)
lev=np.linspace(a.ux.min(), a.ux.max(), 10)
cs=plb.tricontourf(a.lon, a.lat, a.ux, lev)
path=cs.collections[5].get_paths()[0] #210 vertices
path.to_polygons() #16 vertices :frowning:
#############
Cheers

2011/1/14 Michael Droettboom <mdroe@...31...>:

It's not obvious to me that this is wrong. The path has a MOVETO
command (1) in the middle, and thus should require the creation of two
polygons. Can you provide some code or pictures that demonstrate the
problem?

Mike

On 01/13/2011 05:54 PM, Lionel Roubeyrie wrote:

Hi all,
Using the last 1.0.1 matplotlib version,sometimes exporting paths to
polygons gives wrong results like here (paths come from a
tricontourset) :
In [94]: path
Out[94]:
Path([[ 172.0079229 -43.79390934]
[ 171.97660793 -43.785 ]
[ 171.96206864 -43.78273625]
[ 171.959 -43.78114859]
...
[ 171.593 -44.00678244]
[ 171.64906502 -44.01 ]
[ 171.654 -44.01077106]
[ 171.7068607 -44.0160044 ]], [1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2])
In [95]: path.vertices.shape
Out[95]: (210, 2)

but to_polygons gives another result :
In [98]: path.to_polygons()
Out[98]:
[array([[ 172.0079229 , -43.79390934],
[ 171.86039224, -43.65 ],
[ 172.081 , -43.54450289],
[ 172.386 , -43.57010293],
[ 172.60631978, -43.67753099],
[ 172.59231502, -43.71219961],
[ 172.325 , -43.78095532],
[ 172.02 , -43.79497729]]),
array([[ 171.715 , -44.0160044 ],
[ 173.02676111, -43.92 ],
[ 172.935 , -43.53340591],
[ 171.40281884, -43.70029758],
[ 171.37760645, -43.94389688],
[ 171.54044973, -44.0037666 ],
[ 171.7068607 , -44.0160044 ],
[ 171.7068607 , -44.0160044 ]])]

Cheers

--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

--
Lionel Roubeyrie
lionel.roubeyrie@...149...
http://youarealegend.blogspot.com

Hi,
is there a existing patch for this problem or do we have to use/modify
iter_segments for the moment?
thanks

2011/1/15 Lionel Roubeyrie <lionel.roubeyrie@...149...>:

···

The problem appends on some paths/polygons, not all. Have a look at
the joined pictures. The to_polygons method normally take care about
polygons holes, but here some vertices are not converted, resulting in
wrong geometries.
#############
import numpy as np
import pylab as plb
a=np.recfromtxt('rpatch3.grid', delimiter='\t',names=True)
lev=np.linspace(a.ux.min(), a.ux.max(), 10)
cs=plb.tricontourf(a.lon, a.lat, a.ux, lev)
path=cs.collections[5].get_paths()[0] #210 vertices
path.to_polygons() #16 vertices :frowning:
#############
Cheers

2011/1/14 Michael Droettboom <mdroe@...31...>:

It's not obvious to me that this is wrong. The path has a MOVETO
command (1) in the middle, and thus should require the creation of two
polygons. Can you provide some code or pictures that demonstrate the
problem?

Mike

On 01/13/2011 05:54 PM, Lionel Roubeyrie wrote:

Hi all,
Using the last 1.0.1 matplotlib version,sometimes exporting paths to
polygons gives wrong results like here (paths come from a
tricontourset) :
In [94]: path
Out[94]:
Path([[ 172.0079229 -43.79390934]
[ 171.97660793 -43.785 ]
[ 171.96206864 -43.78273625]
[ 171.959 -43.78114859]
...
[ 171.593 -44.00678244]
[ 171.64906502 -44.01 ]
[ 171.654 -44.01077106]
[ 171.7068607 -44.0160044 ]], [1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2])
In [95]: path.vertices.shape
Out[95]: (210, 2)

but to_polygons gives another result :
In [98]: path.to_polygons()
Out[98]:
[array([[ 172.0079229 , -43.79390934],
[ 171.86039224, -43.65 ],
[ 172.081 , -43.54450289],
[ 172.386 , -43.57010293],
[ 172.60631978, -43.67753099],
[ 172.59231502, -43.71219961],
[ 172.325 , -43.78095532],
[ 172.02 , -43.79497729]]),
array([[ 171.715 , -44.0160044 ],
[ 173.02676111, -43.92 ],
[ 172.935 , -43.53340591],
[ 171.40281884, -43.70029758],
[ 171.37760645, -43.94389688],
[ 171.54044973, -44.0037666 ],
[ 171.7068607 , -44.0160044 ],
[ 171.7068607 , -44.0160044 ]])]

Cheers

--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

--
Lionel Roubeyrie
lionel.roubeyrie@...149...
http://youarealegend.blogspot.com

--
Lionel Roubeyrie
lionel.roubeyrie@...149...
http://youarealegend.blogspot.com

Can you see if setting the "should_simplify" to False work? i.e.,

path=cs.collections[5].get_paths()[0] #210 vertices
path.should_simplify = False
path.to_polygons()

At least, it seems to conserve the number of vertices.

Regards,

-JJ

···

On Tue, Jan 18, 2011 at 5:07 PM, Lionel Roubeyrie <lionel.roubeyrie@...149...> wrote:

Hi,
is there a existing patch for this problem or do we have to use/modify
iter_segments for the moment?
thanks

2011/1/15 Lionel Roubeyrie <lionel.roubeyrie@...149...>:

The problem appends on some paths/polygons, not all. Have a look at
the joined pictures. The to_polygons method normally take care about
polygons holes, but here some vertices are not converted, resulting in
wrong geometries.
#############
import numpy as np
import pylab as plb
a=np.recfromtxt('rpatch3.grid', delimiter='\t',names=True)
lev=np.linspace(a.ux.min(), a.ux.max(), 10)
cs=plb.tricontourf(a.lon, a.lat, a.ux, lev)
path=cs.collections[5].get_paths()[0] #210 vertices
path.to_polygons() #16 vertices :frowning:
#############
Cheers

2011/1/14 Michael Droettboom <mdroe@...31...>:

It's not obvious to me that this is wrong. The path has a MOVETO
command (1) in the middle, and thus should require the creation of two
polygons. Can you provide some code or pictures that demonstrate the
problem?

Mike

On 01/13/2011 05:54 PM, Lionel Roubeyrie wrote:

Hi all,
Using the last 1.0.1 matplotlib version,sometimes exporting paths to
polygons gives wrong results like here (paths come from a
tricontourset) :
In [94]: path
Out[94]:
Path([[ 172.0079229 -43.79390934]
[ 171.97660793 -43.785 ]
[ 171.96206864 -43.78273625]
[ 171.959 -43.78114859]
...
[ 171.593 -44.00678244]
[ 171.64906502 -44.01 ]
[ 171.654 -44.01077106]
[ 171.7068607 -44.0160044 ]], [1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2])
In [95]: path.vertices.shape
Out[95]: (210, 2)

but to_polygons gives another result :
In [98]: path.to_polygons()
Out[98]:
[array([[ 172.0079229 , -43.79390934],
[ 171.86039224, -43.65 ],
[ 172.081 , -43.54450289],
[ 172.386 , -43.57010293],
[ 172.60631978, -43.67753099],
[ 172.59231502, -43.71219961],
[ 172.325 , -43.78095532],
[ 172.02 , -43.79497729]]),
array([[ 171.715 , -44.0160044 ],
[ 173.02676111, -43.92 ],
[ 172.935 , -43.53340591],
[ 171.40281884, -43.70029758],
[ 171.37760645, -43.94389688],
[ 171.54044973, -44.0037666 ],
[ 171.7068607 , -44.0160044 ],
[ 171.7068607 , -44.0160044 ]])]

Cheers

--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

--
Lionel Roubeyrie
lionel.roubeyrie@...149...
http://youarealegend.blogspot.com

--
Lionel Roubeyrie
lionel.roubeyrie@...149...
http://youarealegend.blogspot.com

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Seems to resolve the problem!
Thanks

2011/1/18 Jae-Joon Lee <lee.j.joon@...149...>:

···

Can you see if setting the "should_simplify" to False work? i.e.,

path=cs.collections[5].get_paths()[0] #210 vertices
path.should_simplify = False
path.to_polygons()

At least, it seems to conserve the number of vertices.

Regards,

-JJ

On Tue, Jan 18, 2011 at 5:07 PM, Lionel Roubeyrie > <lionel.roubeyrie@...149...> wrote:

Hi,
is there a existing patch for this problem or do we have to use/modify
iter_segments for the moment?
thanks

2011/1/15 Lionel Roubeyrie <lionel.roubeyrie@...149...>:

The problem appends on some paths/polygons, not all. Have a look at
the joined pictures. The to_polygons method normally take care about
polygons holes, but here some vertices are not converted, resulting in
wrong geometries.
#############
import numpy as np
import pylab as plb
a=np.recfromtxt('rpatch3.grid', delimiter='\t',names=True)
lev=np.linspace(a.ux.min(), a.ux.max(), 10)
cs=plb.tricontourf(a.lon, a.lat, a.ux, lev)
path=cs.collections[5].get_paths()[0] #210 vertices
path.to_polygons() #16 vertices :frowning:
#############
Cheers

2011/1/14 Michael Droettboom <mdroe@...31...>:

It's not obvious to me that this is wrong. The path has a MOVETO
command (1) in the middle, and thus should require the creation of two
polygons. Can you provide some code or pictures that demonstrate the
problem?

Mike

On 01/13/2011 05:54 PM, Lionel Roubeyrie wrote:

Hi all,
Using the last 1.0.1 matplotlib version,sometimes exporting paths to
polygons gives wrong results like here (paths come from a
tricontourset) :
In [94]: path
Out[94]:
Path([[ 172.0079229 -43.79390934]
[ 171.97660793 -43.785 ]
[ 171.96206864 -43.78273625]
[ 171.959 -43.78114859]
...
[ 171.593 -44.00678244]
[ 171.64906502 -44.01 ]
[ 171.654 -44.01077106]
[ 171.7068607 -44.0160044 ]], [1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2])
In [95]: path.vertices.shape
Out[95]: (210, 2)

but to_polygons gives another result :
In [98]: path.to_polygons()
Out[98]:
[array([[ 172.0079229 , -43.79390934],
[ 171.86039224, -43.65 ],
[ 172.081 , -43.54450289],
[ 172.386 , -43.57010293],
[ 172.60631978, -43.67753099],
[ 172.59231502, -43.71219961],
[ 172.325 , -43.78095532],
[ 172.02 , -43.79497729]]),
array([[ 171.715 , -44.0160044 ],
[ 173.02676111, -43.92 ],
[ 172.935 , -43.53340591],
[ 171.40281884, -43.70029758],
[ 171.37760645, -43.94389688],
[ 171.54044973, -44.0037666 ],
[ 171.7068607 , -44.0160044 ],
[ 171.7068607 , -44.0160044 ]])]

Cheers

--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

--
Lionel Roubeyrie
lionel.roubeyrie@...149...
http://youarealegend.blogspot.com

--
Lionel Roubeyrie
lionel.roubeyrie@...149...
http://youarealegend.blogspot.com

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

--
Lionel Roubeyrie
lionel.roubeyrie@...149...
http://youarealegend.blogspot.com