Example showing differences between Mac O$ and Windows use

Hello,
I’m a little disappointed by the following test program coming from this post.

What are the technical reasons that make fail the following code under Mac O$ ?

Best regards.

Christophe BAL

---- TEST —

from random import randint, choice
import time
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
back_color = "black"
colors = ['red', 'green', 'cyan', 'yellow']
width, height = 16, 16

fig, ax = plt.subplots()
ax.set(xlim=[0, width], ylim=[0, height]) # Or use "ax.axis([x0,x1,y0,y1])"

# Be sure to draw the canvas once before we start blitting. Otherwise
# a) the renderer doesn't exist yet, and b) there's noting to blit onto
fig.canvas.draw()

def update():
    x = randint(0, width - 1)
    y = randint(0, height - 1)

    rect = mpatches.Rectangle(
        (x, y), 1, 1,
        facecolor = choice(colors),
        edgecolor = back_color
)
    ax.add_artist(rect)

    start = time.time()
    ax.draw_artist(rect)
    fig.canvas.blit(ax.bbox)
    print("draw >>>", time.time() - start)

timer = fig.canvas.new_timer(interval=1)
timer.add_callback(update)
timer.start()

plt.show()

Hi Christophe,

This is (I think) a known limitation of the OS X backend. One way around this is to use another backend. Which backends are available depends on how your matplotlib was built. (And unfortunately I don’t know how to figure out which ones are available, apart from trying.) In my case (matplotlib from homebrew on OS X 10.9.2) the TkAgg backend works.

To use the TkAgg backend insert these two lines:
import matplotlib
matplotlib.use('Agg’)
before the line
import matplotlib.pyplot as plt

I hope that helps.

Best regards,
Jeroen

···

On 13 Mar 2014, at 15:33, Christophe Bal <projetmbc@...287...> wrote:

Hello,
I'm a little disappointed by the following test program coming from this post.

What are the technical reasons that make fail the following code under Mac O$ ?

Best regards.
Christophe BAL

---- TEST ---

from random import randint,
choice

import
time

import matplotlib.pyplot as
plt

import matplotlib.patches as
mpatches

back_color
= "black"

colors
= ['red', 'green', 'cyan', 'yellow']

width
, height = 16, 16

fig
, ax = plt.subplots()

ax
.set(xlim=[0, width], ylim=[0, height]) # Or use "ax.axis([x0,x1,y0,y1])"

# Be sure to draw the canvas once before we start blitting. Otherwise
# a) the renderer doesn't exist yet, and b) there's noting to blit onto

fig
.canvas.draw()

def update():

   x
= randint(0, width - 1)

   y
= randint(0, height - 1)

   rect
= mpatches.Rectangle(

(x, y), 1, 1,

       facecolor
= choice(colors),

       edgecolor

back_color

)

   ax
.add_artist(rect)

   start
= time.time()

   ax
.draw_artist(rect)

   fig
.canvas.blit(ax.bbox)

print("draw >>>", time.time() - start)

timer
= fig.canvas.new_timer(interval=1)

timer
.add_callback(update)

timer
.start()

plt
.show()
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

That should be matplotlib.use('TkAgg'), not “Agg”. Agg is a non-interactive backend, while TkAgg is an interactive Tkinter wrapper around the Agg backend.

···

On Thu, Mar 13, 2014 at 9:53 AM, Jeroen Hegeman <jeroen.hegeman@…287…> wrote:

Hi Christophe,

This is (I think) a known limitation of the OS X backend. One way around this is to use another backend. Which backends are available depends on how your matplotlib was built. (And unfortunately I don’t know how to figure out which ones are available, apart from trying.) In my case (matplotlib from homebrew on OS X 10.9.2) the TkAgg backend works.

To use the TkAgg backend insert these two lines:

import matplotlib

matplotlib.use('Agg’)

before the line

import matplotlib.pyplot as plt

I hope that helps.

Best regards,

Jeroen

On 13 Mar 2014, at 15:33, Christophe Bal <projetmbc@…287…> wrote:

Hello,

I’m a little disappointed by the following test program coming from this post.

What are the technical reasons that make fail the following code under Mac O$ ?

Best regards.

Christophe BAL

---- TEST —

from random import randint,

choice

import

time

import matplotlib.pyplot as

plt

import matplotlib.patches as

mpatches

back_color

= “black”

colors

= [‘red’, ‘green’, ‘cyan’, ‘yellow’]

width

, height = 16, 16

fig

, ax = plt.subplots()

ax

.set(xlim=[0, width], ylim=[0, height]) # Or use “ax.axis([x0,x1,y0,y1])”

Be sure to draw the canvas once before we start blitting. Otherwise

a) the renderer doesn’t exist yet, and b) there’s noting to blit onto

fig

.canvas.draw()

def update():

x

= randint(0, width - 1)

y

= randint(0, height - 1)

rect

= mpatches.Rectangle(

(x, y), 1, 1,

   facecolor

= choice(colors),

   edgecolor

=

back_color

)

ax

.add_artist(rect)

start

= time.time()

ax

.draw_artist(rect)

fig

.canvas.blit(ax.bbox)

print(“draw >>>”, time.time() - start)

timer

= fig.canvas.new_timer(interval=1)

timer

.add_callback(update)

timer

.start()

plt

.show()


Learn Graph Databases - Download FREE O’Reilly Book

“Graph Databases” is the definitive new guide to graph databases and their

applications. Written by three acclaimed leaders in the field,

this first edition is now available. Download your free book today!

http://p.sf.net/sfu/13534_NeoTech_______________________________________________

Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Learn Graph Databases - Download FREE O’Reilly Book

“Graph Databases” is the definitive new guide to graph databases and their

applications. Written by three acclaimed leaders in the field,

this first edition is now available. Download your free book today!

http://p.sf.net/sfu/13534_NeoTech


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Jeroen seems to be right. The example runs fine in on my Mac when using the Qt4Agg backend (which is the default in my matplotlibrc file), but crashes when switching to the MacOSX backend. Tested on OS X 10.8.5., Matplotlib from MacPorts.

Best,
Felix

···

Am 13.03.2014 um 15:53 schrieb Jeroen Hegeman <jeroen.hegeman@...287...>:

Hi Christophe,

This is (I think) a known limitation of the OS X backend. One way around this is to use another backend. Which backends are available depends on how your matplotlib was built. (And unfortunately I don’t know how to figure out which ones are available, apart from trying.) In my case (matplotlib from homebrew on OS X 10.9.2) the TkAgg backend works.

To use the TkAgg backend insert these two lines:
import matplotlib
matplotlib.use('Agg’)
before the line
import matplotlib.pyplot as plt

I hope that helps.

Best regards,
Jeroen

On 13 Mar 2014, at 15:33, Christophe Bal <projetmbc@...287...> wrote:

Hello,
I'm a little disappointed by the following test program coming from this post.

What are the technical reasons that make fail the following code under Mac O$ ?

Best regards.
Christophe BAL

---- TEST ---

from random import randint,
choice

import
time

import matplotlib.pyplot as
plt

import matplotlib.patches as
mpatches

back_color
= "black"

colors
= ['red', 'green', 'cyan', 'yellow']

width
, height = 16, 16

fig
, ax = plt.subplots()

ax
.set(xlim=[0, width], ylim=[0, height]) # Or use "ax.axis([x0,x1,y0,y1])"

# Be sure to draw the canvas once before we start blitting. Otherwise
# a) the renderer doesn't exist yet, and b) there's noting to blit onto

fig
.canvas.draw()

def update():

  x
= randint(0, width - 1)

  y
= randint(0, height - 1)

  rect
= mpatches.Rectangle(

(x, y), 1, 1,

      facecolor
= choice(colors),

      edgecolor

back_color

)

  ax
.add_artist(rect)

  start
= time.time()

  ax
.draw_artist(rect)

  fig
.canvas.blit(ax.bbox)

print("draw >>>", time.time() - start)

timer
= fig.canvas.new_timer(interval=1)

timer
.add_callback(update)

timer
.start()

plt
.show()
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Oops, you are correct. Copy-paste error. I did actually see the blinking boxes with the TkAgg backend.

Jeroen

···

On 13 Mar 2014, at 16:08, Joe Kington <joferkington@...287...> wrote:

That should be `matplotlib.use('TkAgg')`, not "Agg". Agg is a non-interactive backend, while TkAgg is an interactive Tkinter wrapper around the Agg backend.

On Thu, Mar 13, 2014 at 9:53 AM, Jeroen Hegeman <jeroen.hegeman@...287...> wrote:
Hi Christophe,

This is (I think) a known limitation of the OS X backend. One way around this is to use another backend. Which backends are available depends on how your matplotlib was built. (And unfortunately I don’t know how to figure out which ones are available, apart from trying.) In my case (matplotlib from homebrew on OS X 10.9.2) the TkAgg backend works.

To use the TkAgg backend insert these two lines:
import matplotlib
matplotlib.use('Agg’)
before the line
import matplotlib.pyplot as plt

I hope that helps.

Best regards,
Jeroen

On 13 Mar 2014, at 15:33, Christophe Bal <projetmbc@...287...> wrote:

> Hello,
> I'm a little disappointed by the following test program coming from this post.
>
> What are the technical reasons that make fail the following code under Mac O$ ?
>
> Best regards.
> Christophe BAL
>
> ---- TEST ---
>
> from random import randint,
> choice
>
> import
> time
>
> import matplotlib.pyplot as
> plt
>
> import matplotlib.patches as
> mpatches
>
> back_color
> = "black"
>
> colors
> = ['red', 'green', 'cyan', 'yellow']
>
> width
> , height = 16, 16
>
>
> fig
> , ax = plt.subplots()
>
> ax
> .set(xlim=[0, width], ylim=[0, height]) # Or use "ax.axis([x0,x1,y0,y1])"
>
>
>
> # Be sure to draw the canvas once before we start blitting. Otherwise
> # a) the renderer doesn't exist yet, and b) there's noting to blit onto
>
> fig
> .canvas.draw()
>
>
>
> def update():
>
> x
> = randint(0, width - 1)
>
> y
> = randint(0, height - 1)
>
>
> rect
> = mpatches.Rectangle(
>
>
> (x, y), 1, 1,
>
> facecolor
> = choice(colors),
>
> edgecolor
> =
> back_color
>
> )
>
> ax
> .add_artist(rect)
>
>
> start
> = time.time()
>
> ax
> .draw_artist(rect)
>
> fig
> .canvas.blit(ax.bbox)
>
>
> print("draw >>>", time.time() - start)
>
>
> timer
> = fig.canvas.new_timer(interval=1)
>
> timer
> .add_callback(update)
>
> timer
> .start()
>
>
> plt
> .show()
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/13534_NeoTech_______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--

Jeroen Hegeman
jeroen DOT hegeman AT gmail DOT com

WARNING: This message may contain classified information. Immediately burn this message after reading.