Hi,

As per your request below, I have attached a stand-alone example (test3d.py)
of my problem. I am trying to plot in 3D using ion() from a loop.

The code should plot x,y,z coordinates from a loop in ion(). We should see
the plot line moving and the marker moving as well.

I have also attached a working 2d-plot (test2d.py) to show what it's
supposed to do. The 3d plot (test3d.py) should plot the same but with an
additional z coordinates and a z axis!

Thanks
Vick

-----Original Message-----
From: Oscar Benjamin [mailto:oscar.j.benja...@gmail.com] 
Sent: Thursday, 01 August, 2013 01:42
To: Vick
Subject: Re: [Tutor] hi

On 31 July 2013 22:20, Vick <vick1...@orange.mu> wrote:
> Hello,

Hi Vick,

I would prefer it if you would send questions like this to the tutor mailing
list rather than directly to me. This is because:
1) I'm often unable to respond and there are many other people there who
could help (I may be the only one there who understands ODEs but I'm
certainly not the only one who understands matplotlib).
2) It's helpful for others on the tutor mailing list to see the kind of
problems (and solutions) that people new to Python are working with.
3) Any problem/solution gets publicly archived for future reference.

> Can you help me please with plotting in 3D using ion()?
>
> My code is the following:
>
> from pylab import *
> #import pylab
> from mpl_toolkits.mplot3d.axes3d import Axes3D import 
> matplotlib.pyplot as plt from mpl_toolkits.mplot3d import axes3d
>
> plt.ion()
>
> fig = plt.figure(dpi=100)
> ax = axes3d.Axes3D(fig)#fig.add_subplot(111, projection = '3d')
>
>
> tn= mpf('300')#mpf('800')*dt
>
> for i in drange (t+dt, tn,dt):
>     mi = testran(i,mi,dt)
>     #print i+ dt,"       ", mi
>     a.append(mi[0])
>     b.append(mi[1])
>     z1.append(mi[2])
>     c.append(mi[6])
>     d.append(mi[7])
>     z2.append(mi[8])
>     #clf()
>     ax.plot(a,b,z1)#linestyle='None', marker='o', markersize = 5)
>     ax.plot(a,b,z1, marker='o', linestyle='None')
>     ax.plot(c,d,z2)
>     ax.plot(c,d,z2, marker='o', linestyle='None')
>     #draw()
>
> #grid()
> #show()
>
> I'm trying to plot in 3D, coordinates that are appended from a loop 
> using ion(), but it doesn't plot.

I get something different:

$ python plot3d.py
Traceback (most recent call last):
  File "plot3d.py", line 13, in <module>
    tn= mpf('300')#mpf('800')*dt
NameError: name 'mpf' is not defined

Where does the mpf function come from? There are many other symbols that are
not defined (t, dt, testran, ...) so presumably this code is incomplete
somehow.

Could you please make a complete example illustrating the problem you have
and then post it to the tutor list?


Oscar
from pylab import *

import matplotlib.pyplot as plt



def drange(start, stop, step):
    r = start
    while r < stop:
        yield r
        r += step


a=[]
b=[]
z1=[]
c=[]
d=[]
z2=[]




plt.ion()

fig = plt.figure(dpi=100)
ax = fig.add_subplot(111)

t = 0
dt = 1
tn= 50

for i in drange (t+dt, tn,dt):
    aa = sin(i)
    bb = cos(i)
    aa1 = 1.5 *sin(i)
    bb1 = 1.5*cos(i)
    a.append(aa)
    b.append(bb)
    c.append(aa1)
    d.append(bb1)
    clf()
    plot(a,b)#linestyle='None', marker='o', markersize = 5)
    plot(aa,bb, marker='o', linestyle='None')
    plot(c,d)
    plot(aa1,bb1, marker='o', linestyle='None')
    draw()

#grid()
#show()
from pylab import *
#import pylab
from mpl_toolkits.mplot3d.axes3d import Axes3D
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d


def drange(start, stop, step):
    r = start
    while r < stop:
        yield r
        r += step


a=[]
b=[]
z1=[]
c=[]
d=[]
z2=[]




plt.ion()

fig = plt.figure(dpi=100)
ax = axes3d.Axes3D(fig)#fig.add_subplot(111, projection = '3d')

t = 0
dt = 1
tn= 50

for i in drange (t+dt, tn,dt):
    aa = sin(i)
    bb = cos(i)
    cc = aa*bb
    aa1 = 1.5 *sin(i)
    bb1 = 1.5*cos(i)
    cc1 = aa1*bb1
    a.append(aa)
    b.append(bb)
    z1.append(cc)
    c.append(aa1)
    d.append(bb1)
    z2.append(cc1)
    #clf()
    ax.plot(a,b,z1)#linestyle='None', marker='o', markersize = 5)
    ax.plot(a,b,z1, marker='o', linestyle='None')
    ax.plot(c,d,z2)
    ax.plot(c,d,z2, marker='o', linestyle='None')
    plt.draw()

#grid()
#show()
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to