[Matplotlib-devel] [matplotlib-devel] matplotlib 1.5.1 closed path in draw_path when it is not necessary closed

Thomas Caswell tcaswell at gmail.com
Wed Sep 9 02:22:06 CEST 2015


Andres,

Have you made any progress on this?

Using the code in integral_demo.py

```python

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon


def func(x):
    return (x - 3) * (x - 5) * (x - 7) + 85


a, b = 2, 9  # integral limits

# Make the shaded region
ix = np.linspace(a, b)
iy = func(ix)
verts = [(a, 0)] + list(zip(ix, iy)) + [(b, 0)]
poly = Polygon(verts, facecolor='0.9', edgecolor='0.5')
pth = poly.get_path()
```

which if you look at the vertices and codes on both 1.4.3 and current(ish)
master you get

```
In [73]: pth.vertices
Out[74]:
array([[   2.        ,    0.        ],
       [   2.        ,   70.        ],
       [   2.14285714,   73.10495627],
       [   2.28571429,   75.86005831],
       [   2.42857143,   78.28279883],
       [   2.57142857,   80.39067055],
       [   2.71428571,   82.20116618],
       [   2.85714286,   83.73177843],
       [   3.        ,   85.        ],
       [   3.14285714,   86.02332362],
       [   3.28571429,   86.81924198],
       [   3.42857143,   87.40524781],
       [   3.57142857,   87.79883382],
       [   3.71428571,   88.01749271],
       [   3.85714286,   88.0787172 ],
       [   4.        ,   88.        ],
       [   4.14285714,   87.79883382],
       [   4.28571429,   87.49271137],
       [   4.42857143,   87.09912536],
       [   4.57142857,   86.63556851],
       [   4.71428571,   86.11953353],
       [   4.85714286,   85.56851312],
       [   5.        ,   85.        ],
       [   5.14285714,   84.43148688],
       [   5.28571429,   83.88046647],
       [   5.42857143,   83.36443149],
       [   5.57142857,   82.90087464],
       [   5.71428571,   82.50728863],
       [   5.85714286,   82.20116618],
       [   6.        ,   82.        ],
       [   6.14285714,   81.9212828 ],
       [   6.28571429,   81.98250729],
       [   6.42857143,   82.20116618],
       [   6.57142857,   82.59475219],
       [   6.71428571,   83.18075802],
       [   6.85714286,   83.97667638],
       [   7.        ,   85.        ],
       [   7.14285714,   86.26822157],
       [   7.28571429,   87.79883382],
       [   7.42857143,   89.60932945],
       [   7.57142857,   91.71720117],
       [   7.71428571,   94.13994169],
       [   7.85714286,   96.89504373],
       [   8.        ,  100.        ],
       [   8.14285714,  103.47230321],
       [   8.28571429,  107.32944606],
       [   8.42857143,  111.58892128],
       [   8.57142857,  116.26822157],
       [   8.71428571,  121.38483965],
       [   8.85714286,  126.95626822],
       [   9.        ,  133.        ],
       [   9.        ,    0.        ],
       [   2.        ,    0.        ]])

In [75]: pth.codes
Out[75]:
array([ 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, 79], dtype=uint8)

```

which is is both cases closed due to the `closed` kwarg on the `Polygon`
`__init__`, if you change this to `False` you get back open paths.

The backend API has not changed between 1.4.3 and current master, you
should be able to develop a backend which will work with both.  If you have
found API breaks we would really like to know about them!

Tom

On Fri, Aug 14, 2015 at 11:26 AM Jens Nielsen <jenshnielsen at gmail.com>
wrote:

> I can reproduce the problem with the GTK backend but not the GTKAgg or
> GTKCairo backends. Unless you have some specific reason for using the GTK
> backend I would strongly recommend against it. It is untested,
> unmaintained and officially discouraged:
> http://matplotlib.org/faq/usage_faq.html#what-is-a-backend I would
> recommend you to use GTKAgg instead.
>
> Furthermore the GDK toolkit, used in that backend, has been dropped from
> GTK3 which officially uses Cairo internally and thus Matplotlib only
> supports GTK3Agg and GTK3Cario
>
> I guess the issue is likely a result of the large C++ refactoring in
> master.
>
> best
> Jens
>
>
>
>
> fre. 14. aug. 2015 kl. 15.21 skrev Thomas Caswell <tcaswell at gmail.com>:
>
>> Please keep all discussion on the mailing list (
>> matplotlib-devel at python.org).
>>
>> Being pedantic about versions, current master is v1.5.0dev1 , not 1.5.1
>> (which will be the first bug fix release in the 1.5 series which may or may
>> not ever happen).
>>
>> I don't have gtk installed to easily test this and it looks fine with
>> qt4agg, can you provide a minimal script and the code paths from a simple
>> polygon?
>>
>> Tom
>>
>> On Fri, Aug 14, 2015 at 9:05 AM Andrés Vargas <andnovar at gmail.com> wrote:
>>
>>> Hello Tom,
>>>
>>> Thanks for your prompt reply. I am using the function path.to_polygons()
>>> and that gives me a non-closed path in matplotlib 1.4.3 (last stable
>>> release) and give me a closed path in 1.5.1 (master from github). You can
>>> see the problem if you run integral_demo.py with matplotlib 1.5.1 master
>>> with matplotlib.use('gtk').
>>>
>>> Thanks, Andres
>>>
>>
>>> On Fri, Aug 14, 2015 at 8:13 AM, Thomas Caswell <tcaswell at gmail.com>
>>> wrote:
>>>
>>>> Did you mean 1.4.1 instead of 1.5.1 ?
>>>>
>>>> Exactly which paths are you looking at and how are you generating then
>>>> on the mpl side? We have many ways to generate the paths and there maybe
>>>> inconsistence in how closed paths are handled.
>>>>
>>>> Tom
>>>>
>>>> On Wed, Aug 12, 2015, 1:57 PM Andrés Vargas <andnovar at gmail.com> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> My name is Andres I am developing a backend for kivy. I was initially
>>>>> developing for 1.5.1 and I found that the paths are coming with the initial
>>>>> vertex at the end of the list. Does anyone know whether this is change in
>>>>> the way paths are sent ? and how can be fixed coming from 1.4.3 since I am
>>>>> developing the backend for that version.
>>>>>
>>>>> Thanks, Andres
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>>> _______________________________________________
>>>>> Matplotlib-devel mailing list
>>>>> Matplotlib-devel at lists.sourceforge.net
>>>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>>>>>
>>>>
>>>
>>>
>>> _______________________________________________
>> Matplotlib-devel mailing list
>> Matplotlib-devel at python.org
>> https://mail.python.org/mailman/listinfo/matplotlib-devel
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20150909/77523292/attachment-0001.html>


More information about the Matplotlib-devel mailing list