SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Alastair M. <amc...@go...> - 2009年11月27日 19:50:48
Hi everyone,
I am a new matplotlib user building a simple visualization tool.
I was having some issues with the graph not redrawing and I think I have
reduced it to a minimal case that doesn't work as expected for me.
In the example below one of the data elements is changed on every iteration
of the update function, but the graph does not update as expected.
Am I making a mistake in my usage?
Alastair
#!/usr/bin/env python
import gtk
import gobject
from matplotlib.figure import Figure
import numpy as np
from matplotlib.backends.backend_
gtkagg import FigureCanvasGTKAgg as FigureCanvas
def update(line):
 global data
 data[20]=data[20]+0.5
 line.set_ydata(data)
 line.axes.figure.canvas.draw()
 return True
win = gtk.Window()
win.connect("destroy", lambda x: x.destroy())
win.set_default_size(400,300)
fig = Figure(figsize=(5,4), dpi=100)
ax = fig.add_subplot(111)
canvas = FigureCanvas(fig)
win.add(canvas)
data = np.random.randn(100)
line, = ax.plot(data)
win.show_all()
gobject.timeout_add(1000,update,line)
gtk.main()
From: Alastair M. <amc...@go...> - 2009年11月27日 19:46:45
Hi everyone,
I am a new matplotlib user building a simple visualization tool.
I was having some issues with the graph not redrawing and I think I have
reduced it to a minimal case that doesn't work as expected for me.
In the example below one of the data elements is changed on every iteration
of the update function, but the graph does not update as expected.
Am I making a mistake in my usage?
Alastair
#!/usr/bin/env python
import gtk
import gobject
from matplotlib.figure import Figure
import numpy as np
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as
FigureCanvas
def update(line):
 global data
 data[20]=data[20]+0.5
 line.set_ydata(data)
 line.axes.figure.canvas.draw()
 return True
win = gtk.Window()
win.connect("destroy", lambda x: x.destroy())
win.set_default_size(400,300)
fig = Figure(figsize=(5,4), dpi=100)
ax = fig.add_subplot(111)
canvas = FigureCanvas(fig)
win.add(canvas)
data = np.random.randn(100)
line, = ax.plot(data)
win.show_all()
gobject.timeout_add(1000,update,line)
gtk.main()
From: Stephen G. <ste...@op...> - 2009年11月27日 23:22:19
Hi Alastair,
I don't have clue why yours doesn't work.
however I changed the following line in the update function
data[20]=data[20]+0.5
to
data = np.random.randn(100)
And it started updating the display, with new data each update.
maybe changing a single point is not seen as a big enough change?
Steve
Alastair McKinley wrote:
> Hi everyone,
>
> I am a new matplotlib user building a simple visualization tool.
>
> I was having some issues with the graph not redrawing and I think I 
> have reduced it to a minimal case that doesn't work as expected for me.
>
> In the example below one of the data elements is changed on every 
> iteration of the update function, but the graph does not update as 
> expected.
>
> Am I making a mistake in my usage?
>
> Alastair
>
>
>
> #!/usr/bin/env python
>
> import gtk
> import gobject
> from matplotlib.figure import Figure
> import numpy as np
>
> from matplotlib.backends.backend_
> gtkagg import FigureCanvasGTKAgg as FigureCanvas
>
> def update(line):
> global data
> data[20]=data[20]+0.5
> line.set_ydata(data)
> line.axes.figure.canvas.draw()
> return True
>
> win = gtk.Window()
> win.connect("destroy", lambda x: x.destroy())
> win.set_default_size(400,300)
> fig = Figure(figsize=(5,4), dpi=100)
> ax = fig.add_subplot(111)
> canvas = FigureCanvas(fig)
> win.add(canvas)
>
> data = np.random.randn(100)
> line, = ax.plot(data)
>
> win.show_all()
>
> gobject.timeout_add(1000,update,line)
>
> gtk.main()
> ------------------------------------------------------------------------
From: Jae-Joon L. <lee...@gm...> - 2009年11月28日 00:56:11
Maybe this thread is helpful.
http://old.nabble.com/Problem-with-simple-use-of-draw%28%29-in-animations-of-arrays-tt26174627.html#a26175190
I guess your code will work simply by calling "recache()" instead of set_ydata.
Regards,
-JJ
On Sat, Nov 28, 2009 at 4:50 AM, Alastair McKinley
<amc...@go...> wrote:
> Hi everyone,
>
> I am a new matplotlib user building a simple visualization tool.
>
> I was having some issues with the graph not redrawing and I think I have
> reduced it to a minimal case that doesn't work as expected for me.
>
> In the example below one of the data elements is changed on every iteration
> of the update function, but the graph does not update as expected.
>
> Am I making a mistake in my usage?
>
> Alastair
>
>
>
> #!/usr/bin/env python
>
> import gtk
> import gobject
> from matplotlib.figure import Figure
> import numpy as np
>
> from matplotlib.backends.backend_
> gtkagg import FigureCanvasGTKAgg as FigureCanvas
>
> def update(line):
>   global data
>   data[20]=data[20]+0.5
>   line.set_ydata(data)
>   line.axes.figure.canvas.draw()
>   return True
>
> win = gtk.Window()
> win.connect("destroy", lambda x: x.destroy())
> win.set_default_size(400,300)
> fig = Figure(figsize=(5,4), dpi=100)
> ax = fig.add_subplot(111)
> canvas = FigureCanvas(fig)
> win.add(canvas)
>
> data = np.random.randn(100)
> line, = ax.plot(data)
>
> win.show_all()
>
> gobject.timeout_add(1000,update,line)
>
> gtk.main()
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
From: Alastair M. <amc...@go...> - 2009年11月30日 00:35:28
Hi JJ,
Thanks very much that was exactly the right solution!
Best regards,
Alastair
On Sat, Nov 28, 2009 at 12:55 AM, Jae-Joon Lee <lee...@gm...> wrote:
> Maybe this thread is helpful.
>
>
> http://old.nabble.com/Problem-with-simple-use-of-draw%28%29-in-animations-of-arrays-tt26174627.html#a26175190
>
> I guess your code will work simply by calling "recache()" instead of
> set_ydata.
>
> Regards,
>
> -JJ
>
>
> On Sat, Nov 28, 2009 at 4:50 AM, Alastair McKinley
> <amc...@go... <amckinley03%2B...@go...>>
> wrote:
> > Hi everyone,
> >
> > I am a new matplotlib user building a simple visualization tool.
> >
> > I was having some issues with the graph not redrawing and I think I have
> > reduced it to a minimal case that doesn't work as expected for me.
> >
> > In the example below one of the data elements is changed on every
> iteration
> > of the update function, but the graph does not update as expected.
> >
> > Am I making a mistake in my usage?
> >
> > Alastair
> >
> >
> >
> > #!/usr/bin/env python
> >
> > import gtk
> > import gobject
> > from matplotlib.figure import Figure
> > import numpy as np
> >
> > from matplotlib.backends.backend_
> > gtkagg import FigureCanvasGTKAgg as FigureCanvas
> >
> > def update(line):
> > global data
> > data[20]=data[20]+0.5
> > line.set_ydata(data)
> > line.axes.figure.canvas.draw()
> > return True
> >
> > win = gtk.Window()
> > win.connect("destroy", lambda x: x.destroy())
> > win.set_default_size(400,300)
> > fig = Figure(figsize=(5,4), dpi=100)
> > ax = fig.add_subplot(111)
> > canvas = FigureCanvas(fig)
> > win.add(canvas)
> >
> > data = np.random.randn(100)
> > line, = ax.plot(data)
> >
> > win.show_all()
> >
> > gobject.timeout_add(1000,update,line)
> >
> > gtk.main()
> >
> >
> ------------------------------------------------------------------------------
> > Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> > trial. Simplify your report design, integration and deployment - and
> focus
> > on
> > what you do best, core application coding. Discover what's new with
> > Crystal Reports now. http://p.sf.net/sfu/bobj-july
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
> >
>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /