[Matplotlib-users] Animated plots in a Tkinter application

2010-05-05 Thread Kim Hansen
Hi,

Could anyone give a working example of an embedded, animated plot in a
Tkinter application, where animated=True is used together with canvas
background copying to make efficient animated plots in Tkinter
together with other widgets?

I cannot make it work myself, see below.

I am working on a prototype, where have some Tkinter widgets to
control what is plotted. What I want to plot is something which
progress in time depending on the state of the widgets, and it is
potentially a lot of graphs and details on the canvas, but only minor
changes between updates. So I would rather avoid redrawing the whole
canvas.

I would therefore like to use the trick with copying the backgorund,
static canvas from frame to frame to a buffer, and only draw the
animated artists on top of it as is discussed in

http://www.scipy.org/Cookbook/Matplotlib/Animations#head-3d51654b8306b1585664e7fe060a60fc76e5aa08

and also examplified in

http://matplotlib.sourceforge.net/examples/animation/animation_blit_tk.html

Now, the example does not embed the matplotlib canvas in a Tkinter
root class, which I need if I want to add other Tk widgets on the same
window

I have therefore tried to modify the animation by merging in the
embbedding in Tk example:

http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk.html

The closest I have gotten to something, which works is this:

import matplotlib
matplotlib.use('TkAgg')

import Tkinter

import sys
import pylab as p
import numpy as npy
import time

root = Tkinter.Tk()
fig = matplotlib.figure.Figure()

ax = fig.add_subplot(111)
canvas = matplotlib.backends.backend_tkagg.FigureCanvasTkAgg(fig, root)
canvas.get_tk_widget().grid()

# create the initial line
x = npy.arange(0,2*npy.pi,0.01)
ax.grid(True)
# canvas.show() #If I add this, it does not show anything?
line, = ax.plot(x, npy.sin(x), animated=True, lw=2)

def run(*args):
background = canvas.copy_from_bbox(ax.bbox)
# for profiling
tstart = time.time()

while 1:
# restore the clean slate background
canvas.restore_region(background)
# update the data
line.set_ydata(npy.sin(x+run.cnt/10.0))
# just draw the animated artist
ax.draw_artist(line)
# just redraw the axes rectangle
canvas.blit(ax.bbox)

if run.cnt==1000:
# print the timing info and quit
print 'FPS:' , 1000/(time.time()-tstart)
sys.exit()

run.cnt += 1
run.cnt = 0

manager = p.get_current_fig_manager()
manager.window.after(100, run)

p.show() # If I outcomment this, the graph does not animate

Now, this does show an efficient animated plot embedded in a Tk
application, but I cannot make it work witout instatiating the other
annoying backgroud window, whcih pops up when the p.show() is done.
However, if i uncomment it, I never get a visible window.

As I have understood the cookbook, one should draw the canvas before
copying it to the background and before drawing the animated Artists.
However, if I do that it does not work either.

I must admit, that I do not fully grasp waht is goin on in the lines,
where the current figure manager is associated woth the run method.

Another problem with the naimation is that it is not possible to close
it nicely.

Any help would be appreciated.

Kim

--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] re move / delete arrow / annotate, how to?

2010-05-05 Thread KrishnaPribadi



Ryan May-3 wrote:
 
 
 You can accomplish it by:
 
 ax.texts.remove(arrow)
 
 I'd still like to know why this exception gets raised:
 
 
 NotImplementedError   Traceback (most recent call
 last)
 
 /home/rmay/ipython console in module()
 
 /home/rmay/.local/lib/python2.6/site-packages/matplotlib/artist.pyc in
 remove(self)
 123 self._remove_method(self)
 124 else:
 -- 125 raise NotImplementedError('cannot remove artist')
 126 # TODO: the fix for the collections relim problem is to
 move the
 
 127 # limits calculation into the artist itself, including
 the property
 
 
 NotImplementedError: cannot remove artist
 
 JJ, thoughts?
 
 Ryan
 
 -- 
 Ryan May
 Graduate Research Assistant
 School of Meteorology
 University of Oklahoma
 
 --
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 
 
Ryan,
I implemented this code fine and NEVER got any raised exceptions... Maybe
you did something else wrong?

-
Krishna Adrianto Pribadi
Test Engineer
Harley-Davidson Motor Co.
Talladega Test Facility
Vehicle Test Stands
-- 
View this message in context: 
http://old.nabble.com/remove---delete-arrow---annotate%2C-how-to--tp28451836p28460643.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Animated plots in a Tkinter application

2010-05-05 Thread Alan G Isaac
On 5/5/2010 6:53 AM, Kim Hansen wrote:
  Could anyone give a working example of an embedded, animated plot in a
  Tkinter application, where animated=True is used together with canvas
  background copying to make efficient animated plots in Tkinter
  together with other widgets?

First see the embedding_in_tk.py example.
Then, for a simple example, you can see TSPlot here:
http://econpy.googlecode.com/svn/trunk/abm/gridworld/gridworld.py
You can stick it in any frame.
For a more complex example see diagram_cl
http://www.friedrichromstedt.org/index.php?m=186

hth,
Alan Isaac



--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib import problem

2010-05-05 Thread Jouni K . Seppänen
ailp...@gmail.com ailp...@gmail.com writes:

 I have strange problem while I am importing matplotlib.

   File /usr/lib/python2.6/xml/sax/saxutils.py, line 6, in module
 import os, urlparse, urllib, types
   File /usr/lib/python2.6/urllib.py, line 26, in module
 import socket
   File socket.py, line 7, in module
 except socket.error:
 AttributeError: 'module' object has no attribute 'error'

Note how Python prints the full path of saxutils.py and urllib.py but a
bare filename for socket.py. You probably have a file named socket.py in
your current working directory that is inadvertently getting imported by
urllib.py.

-- 
Jouni K. Seppänen
http://www.iki.fi/jks


--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] get_*gridlines alwys returns the same things?

2010-05-05 Thread Chloe Lewis
I got curious and looked for the grid command in matplotlib/axes.py.  
Looks like an inherited-from-Matlab thing. In the cla (clear axis)  
function of the Axes class:

 self._gridOn = rcParams['axes.grid']
 #...
 self.grid(self._gridOn)

and grid() passes its argument on to the xaxis.grid and yaxis.grid.

I haven't found the code that checks any of those settings to decide  
whether the gridline objects are to be drawn or not (??) but I think  
we can rule out Harry Potter. Not magic: adaptation. (Or, if you will,  
not mystification: legacy code.)

C


On May 4, 2010, at 3:27 PM, Nico Schlömer wrote:

 This is weird:

 When plotting something very simple, e.g.,

t = arange( 0.0, 2.0, 0.01 )
s = sin( 2*pi*t )
plot( t, s, : )

 I thought I can check weather the grid is on or off by

   gca().get_xgridlines()

 -- but this *always* returns

 a list of 5 Line2D xgridline objects

 with *always* the same lines

 Line2D((0,0),(0,1))
 Line2D((0,0),(0,1))
 Line2D((0,0),(0,1))
 Line2D((0,0),(0,1))
 Line2D((0,0),(0,1))

 That's really independent of whether the grid is on or off.

 Is there any explanation for it that does not have to do with Harry
 Potter or the Jedi? ;)

 --Nico

 --
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] get_*gridlines alwys returns the same things?

2010-05-05 Thread Jae-Joon Lee
On Tue, May 4, 2010 at 6:27 PM, Nico Schlömer nico.schloe...@gmail.com wrote:
 That's really independent of whether the grid is on or off.

 Is there any explanation for it that does not have to do with Harry
 Potter or the Jedi? ;)


positions of gridlines (and ticks, ticklabels, etc) are updated during
the drawing time (when the figure is drawn). Thus, the coordinates of
lines returned by gca().get_xgridlines() are sometimes meaningless and
you have to be careful about using this (it is best not to pay
attention). However, other artist-related attributes, e.g., line
colors etc, are respected.

Whether gridlines are on or off is actually controlled by each tick.
For example,

for t in gca().xaxis.majorTicks:
  print t.gridOn


A status of the gridlines is also kept in the axis-level.

print gca().xaxis._gridOnMajor

Regards,

-JJ

--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] get_*gridlines alwys returns the same things?

2010-05-05 Thread Eric Firing
On 05/05/2010 08:46 AM, Chloe Lewis wrote:
 I got curious and looked for the grid command in matplotlib/axes.py.
 Looks like an inherited-from-Matlab thing. In the cla (clear axis)
 function of the Axes class:

   self._gridOn = rcParams['axes.grid']
   #...
   self.grid(self._gridOn)

 and grid() passes its argument on to the xaxis.grid and yaxis.grid.

 I haven't found the code that checks any of those settings to decide
 whether the gridline objects are to be drawn or not (??) but I think
 we can rule out Harry Potter. Not magic: adaptation. (Or, if you will,
 not mystification: legacy code.)

Exactly.

The decision on whether to draw the gridlines is made in the draw() 
method of each Tick object; even if the gridlines exist, they may not be 
drawn.
There is no API for retrieving the grid state, and the grid() API, both 
at the Axes and the Axis level, is a bit complicated.  Although you 
can't retrieve the grid state (except by reading private attributes), 
you can set the grid to a known state, and you can toggle the state.

If there is a substantial need to read the grid state, we could expose 
it via a suitable API at the Axis level.  But is this important?

Eric


 C


 On May 4, 2010, at 3:27 PM, Nico Schlömer wrote:

 This is weird:

 When plotting something very simple, e.g.,

 t = arange( 0.0, 2.0, 0.01 )
 s = sin( 2*pi*t )
 plot( t, s, : )

 I thought I can check weather the grid is on or off by

gca().get_xgridlines()

 -- but this *always* returns

 a list of 5 Line2D xgridline objects

 with *always* the same lines

 Line2D((0,0),(0,1))
 Line2D((0,0),(0,1))
 Line2D((0,0),(0,1))
 Line2D((0,0),(0,1))
 Line2D((0,0),(0,1))

 That's really independent of whether the grid is on or off.

 Is there any explanation for it that does not have to do with Harry
 Potter or the Jedi? ;)

 --Nico

 --
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


 --
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users



--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] get_*gridlines alwys returns the same things?

2010-05-05 Thread Nico Schlömer
 If there is a substantial need to read the grid state, we could expose
 it via a suitable API at the Axis level.  But is this important?

Well, I'm using this for the matplotlib2tikz converter
http://github.com/nicki/matplotlib2tikz which takes a matplotlib
figure and spits out TikZ code. TikZ knows
{x,y}{major,minor}grid={on,off}, so I'd like to read this from the
plot.

For now, I can live with

gca().xaxis._gridOnMajor

as JJ proposed, but I guess I can't rely on this forever.

--Nico


On Wed, May 5, 2010 at 9:36 PM, Eric Firing efir...@hawaii.edu wrote:
 On 05/05/2010 08:46 AM, Chloe Lewis wrote:
 I got curious and looked for the grid command in matplotlib/axes.py.
 Looks like an inherited-from-Matlab thing. In the cla (clear axis)
 function of the Axes class:

           self._gridOn = rcParams['axes.grid']
           #...
           self.grid(self._gridOn)

 and grid() passes its argument on to the xaxis.grid and yaxis.grid.

 I haven't found the code that checks any of those settings to decide
 whether the gridline objects are to be drawn or not (??) but I think
 we can rule out Harry Potter. Not magic: adaptation. (Or, if you will,
 not mystification: legacy code.)

 Exactly.

 The decision on whether to draw the gridlines is made in the draw()
 method of each Tick object; even if the gridlines exist, they may not be
 drawn.
 There is no API for retrieving the grid state, and the grid() API, both
 at the Axes and the Axis level, is a bit complicated.  Although you
 can't retrieve the grid state (except by reading private attributes),
 you can set the grid to a known state, and you can toggle the state.

 If there is a substantial need to read the grid state, we could expose
 it via a suitable API at the Axis level.  But is this important?

 Eric


 C


 On May 4, 2010, at 3:27 PM, Nico Schlömer wrote:

 This is weird:

 When plotting something very simple, e.g.,

         t = arange( 0.0, 2.0, 0.01 )
         s = sin( 2*pi*t )
         plot( t, s, : )

 I thought I can check weather the grid is on or off by

    gca().get_xgridlines()

 -- but this *always* returns

 a list of 5 Line2D xgridline objects

 with *always* the same lines

 Line2D((0,0),(0,1))
 Line2D((0,0),(0,1))
 Line2D((0,0),(0,1))
 Line2D((0,0),(0,1))
 Line2D((0,0),(0,1))

 That's really independent of whether the grid is on or off.

 Is there any explanation for it that does not have to do with Harry
 Potter or the Jedi? ;)

 --Nico

 --
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


 --
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users



 --
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users