Why are all my plots displayed as closed loops?

Using Matplotlib 1.5.1, PyGTK 2.24.2, Python 2.7.11

Everything I plot has a straight line connecting the end of the graph back
to the beginning. I've posted some sample code, along with screen caps of
the results, at Stackoverflow: http://preview.tinyurl.com/hb62una

I'm new at Matplotlib, so I must be doing something wrong.

···

--

Ciao, Paul D. DeRocco
Paul mailto:pderocco at ix.netcom.com

In the future, it is best to include a minimal example in your email to the
user list. tinyurls (and SO posts) are almost certainly going to rot.

`Line2D` draws lines connecting the points in the order you pass them in.
If mpl sorted your data based on the x values then you could never plot
anything was not a single valued function f(x).

Tom

···

On Sat, Jun 4, 2016 at 6:39 PM Paul D. DeRocco <pderocco at ix.netcom.com> wrote:

Using Matplotlib 1.5.1, PyGTK 2.24.2, Python 2.7.11

Everything I plot has a straight line connecting the end of the graph back
to the beginning. I've posted some sample code, along with screen caps of
the results, at Stackoverflow: http://preview.tinyurl.com/hb62una

I'm new at Matplotlib, so I must be doing something wrong.

--

Ciao, Paul D. DeRocco
Paul mailto:pderocco at ix.netcom.com

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160605/6f20a26d/attachment.html&gt;

From: Thomas Caswell [mailto:tcaswell at gmail.com]

`Line2D` draws lines connecting the points in the order you
pass them in. If mpl sorted your data based on the x values
then you could never plot anything was not a single valued
function f(x).

That's fine, but in this case that's exactly what I'm trying to plot, so
I'm giving it ascending x values. But it's connecting the last point back
to the first point, for no obvious reason. I won't try to post the screen
caps in the mailing list, which I expect doesn't work, but they are at
still at http://preview.tinyurl.com/hb62una for now. But here's the code:

···

---
import numpy
import gtk
import matplotlib
from matplotlib.figure import Figure
from matplotlib.backends.backend_gtk import FigureCanvasGTK as
FigureCanvas

class junk:

    def __init__(self):

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect('destroy', self.destroy)
        self.window.set_title('junk')
        self.window.resize(400, 400)

        self.figure = Figure()
        self.axes = self.figure.add_axes((0, 0, 1, 1))
        self.canvas = FigureCanvas(self.figure)
        self.canvas.show()

        self.window.add(self.canvas)

        self.axes.set_xlim(-10, 12)
        self.axes.set_ylim(-1, 122)
        x = numpy.arange(-9, 12)
        self.axes.plot(x, x * x)

        self.canvas.draw()

        self.window.show_all()

    def destroy(self, widget, data = None):

        gtk.main_quit()

    def main(self):

        gtk.main()

if __name__ == '__main__':

    app = junk()
    app.main()
---

Do you get the same results? How do I make it not do that?

--

Ciao, Paul D. DeRocco
Paul mailto:pderocco at ix.netcom.com

Looks like a bug in the GTK backend at least on Windows. Here's a
shorter example

import numpy
import matplotlib
matplotlib.use('GTK')
from matplotlib import pyplot
x = numpy.arange(-9, 12)
pyplot.plot(x, x*x)
pyplot.show()

Try to skip the last point in the polygon at
matplotlib/backends/backend_gdk.py#L101:
self.gdkDrawable.draw_lines(gc.gdkGC, polygon[:-1])

<https://github.com/matplotlib/matplotlib/blob/v1.5.x/lib/matplotlib/backends/backend_gdk.py#L101&gt;

Christoph

···

On 6/4/2016 11:56 PM, Paul D. DeRocco wrote:

From: Thomas Caswell [mailto:tcaswell at gmail.com]

`Line2D` draws lines connecting the points in the order you
pass them in. If mpl sorted your data based on the x values
then you could never plot anything was not a single valued
function f(x).

That's fine, but in this case that's exactly what I'm trying to plot, so
I'm giving it ascending x values. But it's connecting the last point back
to the first point, for no obvious reason. I won't try to post the screen
caps in the mailing list, which I expect doesn't work, but they are at
still at http://preview.tinyurl.com/hb62una for now. But here's the code:

---
import numpy
import gtk
import matplotlib
from matplotlib.figure import Figure
from matplotlib.backends.backend_gtk import FigureCanvasGTK as
FigureCanvas

class junk:

    def __init__(self):

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect('destroy', self.destroy)
        self.window.set_title('junk')
        self.window.resize(400, 400)

        self.figure = Figure()
        self.axes = self.figure.add_axes((0, 0, 1, 1))
        self.canvas = FigureCanvas(self.figure)
        self.canvas.show()

        self.window.add(self.canvas)

        self.axes.set_xlim(-10, 12)
        self.axes.set_ylim(-1, 122)
        x = numpy.arange(-9, 12)
        self.axes.plot(x, x * x)

        self.canvas.draw()

        self.window.show_all()

    def destroy(self, widget, data = None):

        gtk.main_quit()

    def main(self):

        gtk.main()

if __name__ == '__main__':

    app = junk()
    app.main()
---

Do you get the same results? How do I make it not do that?

From: Christoph Gohlke

Looks like a bug in the GTK backend at least on Windows. Here's a
shorter example

import numpy
import matplotlib
matplotlib.use('GTK')
from matplotlib import pyplot
x = numpy.arange(-9, 12)
pyplot.plot(x, x*x)
pyplot.show()

Try to skip the last point in the polygon at
matplotlib/backends/backend_gdk.py#L101:
self.gdkDrawable.draw_lines(gc.gdkGC, polygon[:-1])

<https://github.com/matplotlib/matplotlib/blob/v1.5.x/lib/matp
lotlib/backends/backend_gdk.py#L101>

Thanks to you and to Tom Caswell for checking into this. That probably is
where the bug lies. BrenBarn over on Stackoverflow had the simplest
solution, though: use the GTKAgg backend instead of the GTK backend.

···

--

Ciao, Paul D. DeRocco
Paul mailto:pderocco at ix.netcom.com

In fact, I think that deprecating the GTK backend is overdue.

Eric

···

On 2016/06/05 7:49 PM, Paul D. DeRocco wrote:

Thanks to you and to Tom Caswell for checking into this. That probably is
where the bug lies. BrenBarn over on Stackoverflow had the simplest
solution, though: use the GTKAgg backend instead of the GTK backend.

I spent a bit more time poking at this last night (but was having issues
getting the gtk dependencies setup) however it looks like
`path.to_ploygons` is not returning a closed polygon. I wonder if the gtk
drawing api moved under us?

Tom

···

On Mon, Jun 6, 2016 at 2:29 AM Eric Firing <efiring at hawaii.edu> wrote:

On 2016/06/05 7:49 PM, Paul D. DeRocco wrote:

> Thanks to you and to Tom Caswell for checking into this. That probably is
> where the bug lies. BrenBarn over on Stackoverflow had the simplest
> solution, though: use the GTKAgg backend instead of the GTK backend.
>

In fact, I think that deprecating the GTK backend is overdue.

Eric

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160606/acfd0b5d/attachment-0001.html&gt;