 # Comet

All,

I am still wondering why there is no comet command in matplotlib.

I was successful with the following:

import matplotlib.pyplot as plt
import numpy as np

len=200
t=np.linspace(0,2*np.pi,len)
x=np.cos(t)
y=np.sin(t)
xd=[x]
yd=[y]
l,=plt.plot(xd,yd)
plt.axis([-1,1,-1,1])

for i in np.arange(1,len):
xd.append(x[i])
yd.append(y[i])
l.set_xdata(xd)
l.set_ydata(yd)
plt.draw()

plt.show()

But it seems that a comet function added to the matplotlib library would greatly simplify things for students using the interactive pylab in ipython.

Any plans?

David

David Arnold wrote:

All,

I am still wondering why there is no comet command in matplotlib.

I was successful with the following:

import matplotlib.pyplot as plt
import numpy as np

len=200
t=np.linspace(0,2*np.pi,len)
x=np.cos(t)
y=np.sin(t)
xd=[x]
yd=[y]
l,=plt.plot(xd,yd)
plt.axis([-1,1,-1,1])

for i in np.arange(1,len):
xd.append(x[i])
yd.append(y[i])
l.set_xdata(xd)
l.set_ydata(yd)
plt.draw()

plt.show()

But it seems that a comet function added to the matplotlib library would greatly simplify things for students using the interactive pylab in ipython.

I don't understand--what's the point of the example? What is "comet", and how does it simplify anything?

Eric

Hi Eric,

Matlab has two commands, comet and comet3, that animate the path. They are used as in the following Matlab code:

t=linspace(0,2*pi,2000);
x=-sin(t);
y=cos(t);
comet(x,y)

What then happens is the path is drawn "live", as in my python code below.

This is especially useful when teaching parametric equations in calculus. A typical question in that section might be: "find a parametrization for the unit circle that starts at (0,1) and moves around the circle one time in the counterclockwise direction." In this situation, the following is not helpful:

t=linspace(0,2*pi,2000);
x=-sin(t);
y=cos(t);
plot(x,y)

Because the student just sees sees the "finished" path. The comet command, on the other hand, allows the student to "see" that path as it is traced out in real time.

David.

···

On Feb 6, 2010, at 9:09 AM, Eric Firing wrote:

David Arnold wrote:

All,
I am still wondering why there is no comet command in matplotlib. I was successful with the following:
import matplotlib.pyplot as plt
import numpy as np
len=200
t=np.linspace(0,2*np.pi,len)
x=np.cos(t)
y=np.sin(t)
xd=[x]
yd=[y]
l,=plt.plot(xd,yd)
plt.axis([-1,1,-1,1])
for i in np.arange(1,len):
xd.append(x[i])
yd.append(y[i])
l.set_xdata(xd)
l.set_ydata(yd)
plt.draw()

plt.show()
But it seems that a comet function added to the matplotlib library would greatly simplify things for students using the interactive pylab in ipython.

I don't understand--what's the point of the example? What is "comet", and how does it simplify anything?

Eric

Hi David,

Hi Eric,

Matlab has two commands, comet and comet3, that animate the path. They are used as in the following Matlab code:

t=linspace(0,2*pi,2000);
x=-sin(t);
y=cos(t);
comet(x,y)

You can just write the function:

import matplotlib.pyplot as plt

def comet(x, y, fmt='', step=1, **kwargs):
l, = plt.plot(x, y, fmt, **kwargs)
num_points = len(x)
for i in xrange(1, num_points + 1, step):
l.set_data(x[:i], y[:i])
plt.draw()
l.set_data(x, y)
plt.draw()

I think this could be better done using animation features of
matplotlib, but I never used them and I think they varies across
toolkits. Search the docs for animation examples anyway.

Goyo

···

El sáb, 06-02-2010 a las 10:21 -0800, David Arnold escribió:

What then happens is the path is drawn "live", as in my python code below.

This is especially useful when teaching parametric equations in calculus. A typical question in that section might be: "find a parametrization for the unit circle that starts at (0,1) and moves around the circle one time in the counterclockwise direction." In this situation, the following is not helpful:

t=linspace(0,2*pi,2000);
x=-sin(t);
y=cos(t);
plot(x,y)

Because the student just sees sees the "finished" path. The comet command, on the other hand, allows the student to "see" that path as it is traced out in real time.

David.

On Feb 6, 2010, at 9:09 AM, Eric Firing wrote:

> David Arnold wrote:
>> All,
>> I am still wondering why there is no comet command in matplotlib. I was successful with the following:
>> import matplotlib.pyplot as plt
>> import numpy as np
>> len=200
>> t=np.linspace(0,2*np.pi,len)
>> x=np.cos(t)
>> y=np.sin(t)
>> xd=[x]
>> yd=[y]
>> l,=plt.plot(xd,yd)
>> plt.axis([-1,1,-1,1])
>> for i in np.arange(1,len):
>> xd.append(x[i])
>> yd.append(y[i])
>> l.set_xdata(xd)
>> l.set_ydata(yd)
>> plt.draw()
>>
>> plt.show()
>> But it seems that a comet function added to the matplotlib library would greatly simplify things for students using the interactive pylab in ipython.
>
> I don't understand--what's the point of the example? What is "comet", and how does it simplify anything?
>
> Eric
>

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Goyo,

Sweet little function. Thanks.

I still feel that a comet routine should be added to matplotlib for the reasons I've delineated.

D.

···

On Feb 6, 2010, at 1:38 PM, Goyo wrote:

Hi David,

El sáb, 06-02-2010 a las 10:21 -0800, David Arnold escribió:

Hi Eric,

Matlab has two commands, comet and comet3, that animate the path. They are used as in the following Matlab code:

t=linspace(0,2*pi,2000);
x=-sin(t);
y=cos(t);
comet(x,y)

You can just write the function:

import matplotlib.pyplot as plt

def comet(x, y, fmt='', step=1, **kwargs):
l, = plt.plot(x, y, fmt, **kwargs)
num_points = len(x)
for i in xrange(1, num_points + 1, step):
l.set_data(x[:i], y[:i])
plt.draw()
l.set_data(x, y)
plt.draw()

I think this could be better done using animation features of
matplotlib, but I never used them and I think they varies across
toolkits. Search the docs for animation examples anyway.

Goyo

What then happens is the path is drawn "live", as in my python code below.

This is especially useful when teaching parametric equations in calculus. A typical question in that section might be: "find a parametrization for the unit circle that starts at (0,1) and moves around the circle one time in the counterclockwise direction." In this situation, the following is not helpful:

t=linspace(0,2*pi,2000);
x=-sin(t);
y=cos(t);
plot(x,y)

Because the student just sees sees the "finished" path. The comet command, on the other hand, allows the student to "see" that path as it is traced out in real time.

David.

On Feb 6, 2010, at 9:09 AM, Eric Firing wrote:

David Arnold wrote:

All,
I am still wondering why there is no comet command in matplotlib. I was successful with the following:
import matplotlib.pyplot as plt
import numpy as np
len=200
t=np.linspace(0,2*np.pi,len)
x=np.cos(t)
y=np.sin(t)
xd=[x]
yd=[y]
l,=plt.plot(xd,yd)
plt.axis([-1,1,-1,1])
for i in np.arange(1,len):
xd.append(x[i])
yd.append(y[i])
l.set_xdata(xd)
l.set_ydata(yd)
plt.draw()

plt.show()
But it seems that a comet function added to the matplotlib library would greatly simplify things for students using the interactive pylab in ipython.

I don't understand--what's the point of the example? What is "comet", and how does it simplify anything?

Eric

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users