Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix fancy-style annotation causing an exception when the connecting path #566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2011

Conversation

leejjoon
Copy link
Contributor

@leejjoon leejjoon commented Nov 3, 2011

This issue is originally reported by [email protected] on the user mailing list.

http://www.mail-archive.com/[email protected]/msg22443.html

This happens when the connecting path is too short compared to the arrow head length.
The patch fixes this problem.

mdboom added a commit to mdboom/matplotlib that referenced this pull request Nov 8, 2011
mdboom added a commit to mdboom/matplotlib that referenced this pull request Nov 8, 2011
mdboom added a commit that referenced this pull request Nov 16, 2011
fix fancy-style annotation causing an exception when the connecting path
@mdboom mdboom merged commit f6ebac9 into matplotlib:v1.1.x Nov 16, 2011
@mdboom
Copy link
Member

mdboom commented Jul 29, 2012

@leejjoon: I received this private e-mail from Rolf Barinka, and I think you may be the most appropriate person to address it.

Hello Michael Droettboom

I found a bug in matplotlib 1.1.1.
And I offer a bugfix.

I am not part of the development team and don't want to be.
So I offer my bugfix to you, because i saw you involved with the bug.

I used matplotlib 1.1.0 and saw this exception:
a long traceback culminating in
/usr/lib64/python2.7/site-packages/matplotlib/bezier.py",
line 129, in find_bezier_t_intersecting_with_closedpath
     raise ValueError("the segment does not seemed to intersect with the path")

I googled and found the "Pull Request #566" for matplotlib, which seemed to solve
the problem:
"fix fancy-style annotation causing an exception when..."
<https://github.com/matplotlib/matplotlib/pull/566>

I installed matplotlib 1.1.1 incl. #566.
The bug stayed alive.

In #566 a new exception NonIntersectingPathException was created.
This exception was caught in patches.py: Fancy.transmute().

But in my case the exception occurred in patches.py: Simple.transmute().
So I catch it there and do something to work around.
I am not sure that my workaround is okay for all cases.
It works for my application.

Please consider my bugfix:

41# diff /home/bai/software/matplotlib-1.1.1/lib/matplotlib/patches.py /usr/lib64/python2.7/site-packages/matplotlib/patches.py
3404,3405c3404,3409
<             arrow_out, arrow_in = \
<                        split_bezier_intersecting_with_closedpath(arrow_path,
---

            from bezier import NonIntersectingPathException

          try:
               arrow_out, arrow_in = \
                          split_bezier_intersecting_with_closedpath(arrow_path,
3407a3412,3418
            except NonIntersectingPathException:
                arrow_out = arrow_path
                dx, dy = x2 - x1, y2 - y1
                ff = head_length/(dx*dx+dy*dy)**.5
                x0, y0 = x2 - ff*dx, y2 - ff*dy
                arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
                arrow_in = arrow_path

And please tell me what you think about it.

@leejjoon
Copy link
Contributor Author

Michael, can you contact Rolf Barinka and ask if he/she can send an example script that reproduces this error?

@barinka
Copy link

barinka commented Aug 13, 2012

@leejjoon: Hello, this is Rolf Barinka.

The code that brings the exception is part of a complex application, and it is hard to seperate.


I put some prints into patches.py and bezier.py:

    def transmute(self, path, mutation_size, linewidth):
        ...
    try:
           ...
        except NonIntersectingPathException:
    print 'NonIntersectingPathException'
            ....

def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t, inside_closedpath,
t0=0., t1=1., tolerence=0.01):
...
if not xor(start_inside, end_inside):
print 't0=', t0, ' t1=', t1, ' tol=', tolerence
print 'start=', start, ' end=', end
print 'start_inside=', start_inside, ' end_inside=', end_inside
raise NonIntersectingPathException("the segment does not seemed to intersect with the path")


Now some parts of my script, that raise the exception:

def pol2kar(w, r):
"polar [grad,mm] --> karthesisch [x,y]"
if type(w) is list:
phi = [ a / fakt for a in w ]
else:
phi = w / fakt
return (r * np.cos(phi), r * np.sin(phi))

def pfeil(ax, r,v, col, xM=0, yM=0):
"""Pfeil malen
PolKoo color"""
print 'r=', r, ' v=', v
(xp, yp) = pol2kar(r, v)
print 'xM,yM=', xM, yM
x = [ a + xM for a in xp ]; y = [ b + yM for b in yp ]
rad = 0.0680529
cs = 'arc3, rad=%g' % rad
d = dict(arrowstyle='simple', connectionstyle=cs, alpha=0.2, fc=col, ec='none')
print 'x=', x, ' y=', y
print 'd=', d
ax.annotate('', xy=(x[2], y[2]), xytext=(x[0], y[0]), arrowprops=d)

r = [220, 222, 226]
v = [-322.455, -322.455, -320.189]

we need an Axes object "ax" and a color "col"

this brings the exception:

pfeil(ax, r, v, col)


This was the output:
r= [220, 222, 226] v= [-322.455, -322.455, -320.189]
xM,yM= 0 0
x= [247.01486090593005, 239.63076469931315, 222.42196897889596] y= [207.270078681473, 215.76450967344562, 230.32469133063231]
d= {'connectionstyle': 'arc3, rad=0.0680529', 'alpha': 0.2, 'fc': '#DD0000', 'arrowstyle': 'simple', 'ec': 'none'}
t0= 0.0 t1= 1.0 tol= 0.01
start= (396.80739712418909, 350.43678238448041) end= (402.37062135854825, 346.84973645969643)
start_inside= True end_inside= True
NonIntersectingPathException

@ghost ghost assigned leejjoon Aug 21, 2012
leejjoon added a commit to leejjoon/matplotlib that referenced this pull request Aug 21, 2012
…oo close. This addresses matplotlib#566. Initial patch submitted by Rolf Barinka.
@leejjoon
Copy link
Contributor Author

Rolf, please test with my proposed change above. Let us know if things work okay in your side.

@barinka
Copy link

barinka commented Aug 23, 2012

Hello

Yes, things work okay for me.
Your arrow looks like mine.

Jae-Joon Lee schrieb Folgendes am 2012-08-21 20:58:

Rolf, please test with my proposed change above. Let us know if things work okay in your side.


Reply to this email directly or view it on GitHub #566 (comment).

Freundliche Grüße
Rolf Barinka
Abt: AHPS
Fon: 5713

leejjoon added a commit to leejjoon/matplotlib that referenced this pull request Oct 7, 2012
…oo close. This addresses matplotlib#566. Initial patch submitted by Rolf Barinka.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants