|
From: Jakob J. L. <jak...@gm...> - 2006-04-17 13:46:30
|
Hello,
It may very well be that this is a trivial problem, due to my lack of
knowledge. I did, at least, go through all the mail lists and the
examples of pylab (VERY NICE, BTW: I am extremely happy to have found
it).
I am trying to plot a table or matrix of graphs. I want to do this
with a loop. So far, I have tried it with something like
## code starts here
rownrs =3D ... # defined nr of graphs in x direction
colnrs =3D ... # defined nr of graphs in y direction
x =3D .... # defined x-values here
plotnr =3D 0
=09fig =3D figure()
=09hold(False)
=09for counter in counter_list:
=09=09y =3D intensities_calc[counter]
=09=09plotnr =3D plotnr+1=09
=09=09ax =3D subplot(rownrs, colnrs, plotnr)
=09=09fig.add_subplot(ax)
=09=09plot(x,y)=09
=09=09if ax.is_last_row():
=09=09ax.set_xlabel('time')
=09show()
### code ends here
all i get is one graph, in the first position. no error messages.
please, what am i doing wrong ?
very grateful for an answer..
Jakob
--
Jakob J. Lopez (Jak...@gm...)
|
|
From: Ryan K. <rya...@gm...> - 2006-04-17 14:03:56
|
I think you need to replace plot(x,y) with ax.plot(x,y).
I think this script could be slightly simpler if you used the pylab
interface to matplotlib so that you could just call figure, subplot,
and plot without having to specify the axis.
But if this is your first attempt at using matplotlib, you have done a
fairly impressive job at searching the examples and archives first.
Ryan
On 4/17/06, Jakob J. Lopez <jak...@gm...> wrote:
> Hello,
>
> It may very well be that this is a trivial problem, due to my lack of
> knowledge. I did, at least, go through all the mail lists and the
> examples of pylab (VERY NICE, BTW: I am extremely happy to have found
> it).
>
> I am trying to plot a table or matrix of graphs. I want to do this
> with a loop. So far, I have tried it with something like
>
> ## code starts here
> rownrs =3D ... # defined nr of graphs in x direction
> colnrs =3D ... # defined nr of graphs in y direction
> x =3D .... # defined x-values here
> plotnr =3D 0
> fig =3D figure()
> hold(False)
> for counter in counter_list:
> y =3D intensities_calc[counter]
> plotnr =3D plotnr+1
> ax =3D subplot(rownrs, colnrs, plotnr)
> fig.add_subplot(ax)
> plot(x,y)
> if ax.is_last_row():
> ax.set_xlabel('time')
> show()
>
> ### code ends here
>
> all i get is one graph, in the first position. no error messages.
>
> please, what am i doing wrong ?
>
> very grateful for an answer..
>
> Jakob
>
> --
> Jakob J. Lopez (Jak...@gm...)
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting langua=
ge
> that extends applications into web and mobile media. Attend the live webc=
ast
> and join the prime developer group breaking into this new coding territor=
y!
> http://sel.as-us.falkag.net/sel?cmdlnk&kid=110944&bid$1720&dat=121642
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
|
|
From: Jakob J. L. <jak...@gm...> - 2006-04-17 14:08:08
|
Hi Ryan,
Thanks for that very quick email and the encouragement.
Sadly, using ax.plot doesnt solve my problem.. no change in output...
Jakob
On 4/17/06, Ryan Krauss <rya...@gm...> wrote:
> I think you need to replace plot(x,y) with ax.plot(x,y).
>
> I think this script could be slightly simpler if you used the pylab
> interface to matplotlib so that you could just call figure, subplot,
> and plot without having to specify the axis.
>
> But if this is your first attempt at using matplotlib, you have done a
> fairly impressive job at searching the examples and archives first.
>
> Ryan
>
> On 4/17/06, Jakob J. Lopez <jak...@gm...> wrote:
> > Hello,
> >
> > It may very well be that this is a trivial problem, due to my lack of
> > knowledge. I did, at least, go through all the mail lists and the
> > examples of pylab (VERY NICE, BTW: I am extremely happy to have found
> > it).
> >
> > I am trying to plot a table or matrix of graphs. I want to do this
> > with a loop. So far, I have tried it with something like
> >
> > ## code starts here
> > rownrs =3D ... # defined nr of graphs in x direction
> > colnrs =3D ... # defined nr of graphs in y direction
> > x =3D .... # defined x-values here
> > plotnr =3D 0
> > fig =3D figure()
> > hold(False)
> > for counter in counter_list:
> > y =3D intensities_calc[counter]
> > plotnr =3D plotnr+1
> > ax =3D subplot(rownrs, colnrs, plotnr)
> > fig.add_subplot(ax)
> > plot(x,y)
> > if ax.is_last_row():
> > ax.set_xlabel('time')
> > show()
> >
> > ### code ends here
> >
> > all i get is one graph, in the first position. no error messages.
> >
> > please, what am i doing wrong ?
> >
> > very grateful for an answer..
> >
> > Jakob
> >
> > --
> > Jakob J. Lopez (Jak...@gm...)
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by xPML, a groundbreaking scripting lang=
uage
> > that extends applications into web and mobile media. Attend the live we=
bcast
> > and join the prime developer group breaking into this new coding territ=
ory!
> > http://sel.as-us.falkag.net/sel?cmdlnk&kid=110944&bid$1720&dat=121642
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
>
--
Jakob J. Lopez (Jak...@gm...)
|
|
From: John H. <jdh...@ac...> - 2006-04-17 14:27:53
|
You seem to be mixing idioms, between pylab which manages current
figure and current axes, and explicitly managing the Figure and Axes
instances yourself. Eg
fig = figure()
hold(False) #<-- manipulates current axes
for counter in counter_list:
y = intensities_calc[counter]
plotnr = plotnr+1
ax = subplot(rownrs, colnrs, plotnr) #<-- uses current fig
fig.add_subplot(ax)
plot(x,y) #<-- uses current axes
if ax.is_last_row():
ax.set_xlabel('time')
If you want to manage the figure and axes attributes yourself, which
is good practice, I suggest imposing some discipline on yourself and
only importing 4 things from pylab (this is what I usually do)
from pylab import figure, show, nx, close
Your code would then look something like:
fig = figure()
for counter in counter_list:
y = intensities_calc[counter]
plotnr = plotnr+1
ax = fig.add_subplot(rownrs, colnrs, plotnr)
ax.hold(False)
ax.plot(x,y)
if ax.is_last_row():
ax.set_xlabel('time')
That should work, as long as plotnr is incrementing like you expect it
to.
JDH
|
|
From: Ken M. <mc...@ii...> - 2006-04-17 14:38:27
|
Jakob,
Here's an example of managing axes, etc yourself while plotting.
John covered just about everything I was going to mention in his
email, but I'd like to add that using "from XYZ import *" in scripts
can make them hard for other people to understand.
Ken
import pylab
nrows = 2
ncols = 3
x = pylab.arange(0, 10, 0.1) # your X here
fig = pylab.figure()
for i in range(0, nrows*ncols):
y = i * x # your Y here
# i goes 0..N-1, but the plot number goes 0..N, so add one here
ax = fig.add_subplot(nrows, ncols, i+1)
ax.plot(x, y)
if ax.is_last_row():
ax.set_xlabel('time')
pylab.show()
|
|
From: Ryan K. <rya...@gm...> - 2006-04-17 14:35:38
|
Here is an example that works for me doing this as John mentioned
(figure 2) or the first way that came to my mind (figure 1):
from numpy import zeros, arange, sin, cos, pi
from pylab import figure, subplot, plot, show, cla, clf
t=3Darange(0,1,0.01)
y=3Dzeros([len(t),4],'d')
y[:,0]=3Dsin(2*pi*t)
y[:,1]=3Dcos(2*pi*t)
y[:,2]=3Dsin(2*pi*t*2+1)
y[:,3]=3Dcos(2*pi*t*2+1)
nc=3D1
nr=3D4
figure(1)
clf()
for x in range(nr):
subplot(nr,1,x+1)
plot(t,y[:,x])
figure(2)
clf()
for x in range(nr):
ax =3D figure(2).add_subplot(nr, 1, x+1)
ax.hold(False)
ax.plot(t,y[:,x])
if ax.is_last_row():
ax.set_xlabel('time')
show()
On 4/17/06, John Hunter <jdh...@ac...> wrote:
>
> You seem to be mixing idioms, between pylab which manages current
> figure and current axes, and explicitly managing the Figure and Axes
> instances yourself. Eg
>
> fig =3D figure()
> hold(False) #<-- manipulates current axes
> for counter in counter_list:
> y =3D intensities_calc[counter]
> plotnr =3D plotnr+1
> ax =3D subplot(rownrs, colnrs, plotnr) #<-- uses current =
fig
> fig.add_subplot(ax)
> plot(x,y) #<-- uses current axes
> if ax.is_last_row():
> ax.set_xlabel('time')
>
> If you want to manage the figure and axes attributes yourself, which
> is good practice, I suggest imposing some discipline on yourself and
> only importing 4 things from pylab (this is what I usually do)
>
> from pylab import figure, show, nx, close
>
> Your code would then look something like:
>
> fig =3D figure()
> for counter in counter_list:
> y =3D intensities_calc[counter]
> plotnr =3D plotnr+1
> ax =3D fig.add_subplot(rownrs, colnrs, plotnr)
> ax.hold(False)
> ax.plot(x,y)
> if ax.is_last_row():
> ax.set_xlabel('time')
>
> That should work, as long as plotnr is incrementing like you expect it
> to.
>
> JDH
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting langua=
ge
> that extends applications into web and mobile media. Attend the live webc=
ast
> and join the prime developer group breaking into this new coding territor=
y!
> http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D110944&bid=3D241720&dat=
=3D121642
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
|
|
From: Jakob J. L. <jak...@gm...> - 2006-04-17 14:42:27
|
Thanks John & Ryan,
I'm sitting here in Germany, Berlin, trying to get some data-analysis
up to par during the Easter holidays and can't get over the fact that
I'm getting help from around the globe, within minutes.
It seems to work now!
Jakob
On 4/17/06, Ryan Krauss <rya...@gm...> wrote:
> Here is an example that works for me doing this as John mentioned
> (figure 2) or the first way that came to my mind (figure 1):
>
> from numpy import zeros, arange, sin, cos, pi
> from pylab import figure, subplot, plot, show, cla, clf
> t=3Darange(0,1,0.01)
> y=3Dzeros([len(t),4],'d')
> y[:,0]=3Dsin(2*pi*t)
> y[:,1]=3Dcos(2*pi*t)
> y[:,2]=3Dsin(2*pi*t*2+1)
> y[:,3]=3Dcos(2*pi*t*2+1)
>
> nc=3D1
> nr=3D4
>
> figure(1)
> clf()
> for x in range(nr):
> subplot(nr,1,x+1)
> plot(t,y[:,x])
>
> figure(2)
> clf()
> for x in range(nr):
> ax =3D figure(2).add_subplot(nr, 1, x+1)
> ax.hold(False)
> ax.plot(t,y[:,x])
> if ax.is_last_row():
> ax.set_xlabel('time')
>
> show()
>
>
> On 4/17/06, John Hunter <jdh...@ac...> wrote:
> >
> > You seem to be mixing idioms, between pylab which manages current
> > figure and current axes, and explicitly managing the Figure and Axes
> > instances yourself. Eg
> >
> > fig =3D figure()
> > hold(False) #<-- manipulates current axes
> > for counter in counter_list:
> > y =3D intensities_calc[counter]
> > plotnr =3D plotnr+1
> > ax =3D subplot(rownrs, colnrs, plotnr) #<-- uses curren=
t fig
> > fig.add_subplot(ax)
> > plot(x,y) #<-- uses current axes
> > if ax.is_last_row():
> > ax.set_xlabel('time')
> >
> > If you want to manage the figure and axes attributes yourself, which
> > is good practice, I suggest imposing some discipline on yourself and
> > only importing 4 things from pylab (this is what I usually do)
> >
> > from pylab import figure, show, nx, close
> >
> > Your code would then look something like:
> >
> > fig =3D figure()
> > for counter in counter_list:
> > y =3D intensities_calc[counter]
> > plotnr =3D plotnr+1
> > ax =3D fig.add_subplot(rownrs, colnrs, plotnr)
> > ax.hold(False)
> > ax.plot(x,y)
> > if ax.is_last_row():
> > ax.set_xlabel('time')
> >
> > That should work, as long as plotnr is incrementing like you expect it
> > to.
> >
> > JDH
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by xPML, a groundbreaking scripting lang=
uage
> > that extends applications into web and mobile media. Attend the live we=
bcast
> > and join the prime developer group breaking into this new coding territ=
ory!
> > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D110944&bid=3D241720&dat=
=3D121642
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
>
--
Jakob J. Lopez (Jak...@gm...)
|