[Matplotlib-users] help visualizing plots

2009-02-16 Thread Simone Gabbriellini
dear list,

can someone tell me why I don't see anything when I run this script?
it is a modified version of the traits example...
I expected to see three plots with one line each...

from enthought.traits.api import HasTraits, Instance, Range, Array,
on_trait_change, Property,cached_property, Bool
from enthought.traits.ui.api import View, Item
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure
from matplotlib.axes import Axes
from matplotlib.lines import Line2D
from enthought.traits.ui.api import CustomEditor
import wx
import numpy

def MakePlot(parent, editor):
fig = editor.object.figure
panel = wx.Panel(parent, -1)
canvas = FigureCanvasWxAgg(panel, -1, fig)
toolbar = NavigationToolbar2Wx(canvas)
toolbar.Realize()
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(canvas,1,wx.EXPAND|wx.ALL,1)
sizer.Add(toolbar,0,wx.EXPAND|wx.ALL,1)
panel.SetSizer(sizer)
canvas.SetMinSize((300,600))
return panel

class PlotModel(HasTraits):

figure = Instance(Figure, ())
axes1 = Instance(Axes)
axes2 = Instance(Axes)
axes3 = Instance(Axes)
line1 = Instance(Line2D)
line2 = Instance(Line2D)
line3 = Instance(Line2D)
_draw_pending = Bool(False) #a flag to throttle the redraw rate
# a variable parameter
x = Array(value=numpy.arange(1, 31))
x2 = Array(value=numpy.arange(1, 31))
x3 = Array(value=numpy.arange(1, 31))
# a dependent variable
y = Array(value=numpy.arange(1, 31))
y2 = Array(value=numpy.arange(1, 31))
y3 = Array(value=numpy.arange(1, 31))

traits_view = View(
Item('figure',
 editor=CustomEditor(MakePlot),
 resizable=True,
 show_label=False),
resizable=False,
width=400,
height=750
)

def _axes1_default(self):
return self.figure.add_subplot(311)

def _axes2_default(self):
return self.figure.add_subplot(312)

def _axes3_default(self):
return self.figure.add_subplot(313)

def _line1_default(self):
return self.axes1.plot(self.x, self.y)[0]

def _line2_default(self):
return self.axes2.plot(self.x2, self.y2)[0]

def _line3_default(self):
return self.axes3.plot(self.x3, self.y3)[0]

def redraw(self):
if self._draw_pending:
return
canvas = self.figure.canvas
if canvas is None:
return
def _draw():
canvas.draw()
self._draw_pending = False
wx.CallLater(50, _draw).Start()
self._draw_pending = True

if __name__==__main__:
model = PlotModel()
model.configure_traits(model.redraw())


thank you,
simone

--
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plot a data stream with matplotlib

2009-01-23 Thread Simone Gabbriellini
that's nice!!! thank you...

anyway, I wanted to take advantage of the Traits implementation of my app...

simone

2009/1/23 eliben eli...@gmail.com:



 Simone Gabbriellini-3 wrote:

 Dear List,

 I have some variables I want to plot... the values of those variable
 change in time... I would like to plot the result with a traditional
 line plot

 those variables are traits of a class (don't know if this can make a
 difference...)

 is there any example of this with matplotlib?


 Hi Simone,

 I think you will find the following  examples useful:
 http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/

 Both feature dynamic plotting of variables that change (either by the user
 or in time)

 Eli


 --
 View this message in context: 
 http://www.nabble.com/plot-a-data-stream-with-matplotlib-tp21530559p21622559.html
 Sent from the matplotlib - users mailing list archive at Nabble.com.


 --
 This SF.net email is sponsored by:
 SourcForge Community
 SourceForge wants to tell your story.
 http://p.sf.net/sfu/sf-spreadtheword
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plot a data stream with matplotlib

2009-01-20 Thread Simone Gabbriellini
Ryan,

 You'd want to look at the animation examples in examples/animation.  The exact
 details will depend upon what backend you want to use, but 
 strip_chart_demo.py,
 simple_anim_gtk.py, and gtk_timeout.py are good places to start.

I tried the strip_chart_demo.py, which is my case, but at least on my
Mac OSX system, I don't see anything untill the plot is finished...

Simone

--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plot a data stream with matplotlib

2009-01-20 Thread Simone Gabbriellini
Sorry I made a mistake... what I mean is that I tryed the code in the
section GUI neutral animation in pylab from
http://www.scipy.org/Cookbook/Matplotlib/Animations, which is my
case... and, as I said, nothing is drawn in the window untill the
function ends the cycle, then the line is displayed

here is the code:

from pylab import *
import time

ion()

tstart = time.time()   # for profiling
x = arange(0,2*pi,0.01)# x-array
line, = plot(x,sin(x))
for i in arange(1,200):
line.set_ydata(sin(x+i/10.0))  # update the data
draw() # redraw the canvas

print 'FPS:' , 200/(time.time()-tstart)

best regards,
simone

2009/1/20 Simone Gabbriellini simone.gabbriell...@gmail.com:
 Ryan,

 You'd want to look at the animation examples in examples/animation.  The 
 exact
 details will depend upon what backend you want to use, but 
 strip_chart_demo.py,
 simple_anim_gtk.py, and gtk_timeout.py are good places to start.

 I tried the strip_chart_demo.py, which is my case, but at least on my
 Mac OSX system, I don't see anything untill the plot is finished...

 Simone


--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plot a data stream with matplotlib

2009-01-19 Thread Simone Gabbriellini
I see that you first build your array and then display it at the end...

is it possible in matplotlib to update the plot while the class is
evolving? like:

f.evolve(6)
f.display()
f.evolve(.27)
f.display()
f.evolve(10)
f.display()
f.evolve(2)
f.display()

best regards,
simone

2009/1/19 C Lewis chle...@nature.berkeley.edu:
 #Skeleton example of a taking snapshots of an evolving class
 import pylab as p
 from math import log
 class foo:
def __init__(self):
self.red = 0
self.green = 1
self.age = 0
self.history = ([self.age],[self.red],[self.green])

def snapshot(self):
self.history[0].append(self.age)
self.history[1].append(self.red)
self.history[2].append(self.green)

def evolve(self, time):
self.red = self.red + time/2
self.green = self.green * log(time)
self.age = self.age + time
self.snapshot()

def display(self):

  p.plot(self.history[0],self.history[1],self.history[0],self.history[2])
p.show()

 if __name__ == '__main__':
f = foo()
f.snapshot()
f.evolve(6); f.evolve(.27);f.evolve(10);f.evolve(2)
print f.history
f.display()

 On Jan 18, 2009, at 3:18 PM, Simone Gabbriellini wrote:

 thanks, it is exactly what I need... I have undestood the logic, I
 build a plot,  put my traits values into an array and then I call the
 add_current_state_to_plot function to update the plot with the new
 values...

 I am an absolute beginner of matplotlib, can you give me a little
 example of add_current_state_to_plot function? Because I don't know
 the right way to update: do I have to pass all the array, or just the
 new values?

 best regards,
 simone

 2009/1/18 C Lewis chle...@nature.berkeley.edu:

 Guessing about what you want:

 Does the class change with time? that is, perhaps you have a class foo,
 and
 foo evolves, and you would like to plot a history of some traits of foo,
 but
 at any given moment foo only contains its current state?

 If so, I think you need to have a function in foo, or even a separate
 class,
 that takes `snapshots' of foo's traits on one schedule, and stores them,
 and
 can also plot them on some schedule. Choosing how to do that is more a
 python problem than a matplotlib problem; personally, I have something
 set
 up so class 'profile' has functions to 'setup_plot' and
 'add_current_state_to_plot', and I just have to choose when to call the
 latter.

 Or you can just store the values and plot at the end; once you have one
 list
 of the times, and a separate list of each trait's history at those times,
 you're set up for matplotlib plotting, e.g.

 from pylab import *
 plot(times, traitA, times, traitB, times, traitC)
 show()

 although, while looking for a simple example, I found this:


 http://matplotlib.sourceforge.net/examples/pylab_examples/plotfile_demo.html

 which is not totally simple but looks great.


 C

 On Jan 18, 2009, at 9:36 AM, Simone Gabbriellini wrote:

 Dear List,

 I have some variables I want to plot... the values of those variable
 change in time... I would like to plot the result with a traditional
 line plot

 those variables are traits of a class (don't know if this can make a
 difference...)

 is there any example of this with matplotlib?

 best regards,
 simone gabbriellini



 --
 This SF.net email is sponsored by:
 SourcForge Community
 SourceForge wants to tell your story.
 http://p.sf.net/sfu/sf-spreadtheword
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users



 Chloe Lewis
 Graduate student, Amundson Lab
 Division of Ecosystem Sciences, ESPM
 University of California, Berkeley
 137 Mulford Hall - #3114
 Berkeley, CA  94720-3114
 chle...@nature.berkeley.edu



--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] plot a data stream with matplotlib

2009-01-18 Thread Simone Gabbriellini
Dear List,

I have some variables I want to plot... the values of those variable
change in time... I would like to plot the result with a traditional
line plot

those variables are traits of a class (don't know if this can make a
difference...)

is there any example of this with matplotlib?

best regards,
simone gabbriellini

--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plot a data stream with matplotlib

2009-01-18 Thread Simone Gabbriellini
thanks, it is exactly what I need... I have undestood the logic, I
build a plot,  put my traits values into an array and then I call the
add_current_state_to_plot function to update the plot with the new
values...

I am an absolute beginner of matplotlib, can you give me a little
example of add_current_state_to_plot function? Because I don't know
the right way to update: do I have to pass all the array, or just the
new values?

best regards,
simone

2009/1/18 C Lewis chle...@nature.berkeley.edu:
 Guessing about what you want:

 Does the class change with time? that is, perhaps you have a class foo, and
 foo evolves, and you would like to plot a history of some traits of foo, but
 at any given moment foo only contains its current state?

 If so, I think you need to have a function in foo, or even a separate class,
 that takes `snapshots' of foo's traits on one schedule, and stores them, and
 can also plot them on some schedule. Choosing how to do that is more a
 python problem than a matplotlib problem; personally, I have something set
 up so class 'profile' has functions to 'setup_plot' and
 'add_current_state_to_plot', and I just have to choose when to call the
 latter.

 Or you can just store the values and plot at the end; once you have one list
 of the times, and a separate list of each trait's history at those times,
 you're set up for matplotlib plotting, e.g.

 from pylab import *
 plot(times, traitA, times, traitB, times, traitC)
 show()

 although, while looking for a simple example, I found this:

 http://matplotlib.sourceforge.net/examples/pylab_examples/plotfile_demo.html

 which is not totally simple but looks great.


 C

 On Jan 18, 2009, at 9:36 AM, Simone Gabbriellini wrote:

 Dear List,

 I have some variables I want to plot... the values of those variable
 change in time... I would like to plot the result with a traditional
 line plot

 those variables are traits of a class (don't know if this can make a
 difference...)

 is there any example of this with matplotlib?

 best regards,
 simone gabbriellini


 --
 This SF.net email is sponsored by:
 SourcForge Community
 SourceForge wants to tell your story.
 http://p.sf.net/sfu/sf-spreadtheword
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users



--
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users