Why Is This Code Failing?

Here is the relevant code fragment:

   for i in range(1, compList[0][16]):
           pylab.hold(True)
           if compList[0][4] == 'Decay S-Curve':
             testFunctions.zCurve(compList[0][10],compList[0][9])
           elif compList[0][4] == 'Bell Curve':
             testFunctions.gaussCurve(compList[0][14],compList[0][14])
           elif compList[0][4] == 'Growth S-Curve':
             testFunctions.sCurve(compList[0][8],compList[0][11])
           elif compList[0][4] == 'Beta':
       testFunctions.betaCurve(compList[0][13],compList[0][12],compList[0][14])
           elif compList[0][4] == 'Data':
             continue
           elif compList[0][4] == 'Linear Increasing':
             testFunctions.linearIncrCurve(compList[0][8],compList[0][11])
           elif compList[0][4] == 'Linear Decreasing':
             testFunctions.linearDecrCurve(compList[0][10],compList[0][9])
           elif compList[0][4] == 'Left Shoulder':
       testFunctions.leftShoulderCurve(compList[0][10],compList[0][11],compList[0][9])
           elif compList[0][4] == 'Trapezoid':
       testFunctions.trapezoidCurve(compList[0][8],compList[0][10],compList[0][11],compList[0][9])
           elif compList[0][4] == 'Right Shoulder':
       testFunctions.rightShoulderCurve(compList[0][8],compList[0][10],compList[0][11])
           elif compList[0][4] == 'Triangle':
       testFunctions.triangleCurve(compList[0][8],compList[0][13],compList[0][9])
           elif compList[0][4] == 'Singleton':
             testFunctions.singletonCurve(compList[0][13],compList[0][14])
           elif compList[0][4] == 'Rectangle':
       testFunctions.rectangleCurve(compList[0][8],compList[0][10],compList[0][11],compList[0][9])
           elif compList[0][4] == 'Outcome':
             testFunctions.outcomeCurve()
         pylab.savefig(curVar+'.png')
         pylab.hold()

   When it runs in the test script the first curve is plotted in a matplotlib
window and the program pauses until I close that window by clicking on the
upper right button on the frame. Then this traceback is displayed:

Traceback (most recent call last):
   File "termset-test-data.py", line 391, in ?
     testCode()
   File "termset-test-data.py", line 388, in testCode
     pylab.hold()
   File "/usr/lib/python2.4/site-packages/matplotlib/pyplot.py", line 334, in
hold
     rc('axes', hold=b)
   File "/usr/lib/python2.4/site-packages/matplotlib/pyplot.py", line 74, in
rc
     matplotlib.rc(*args, **kwargs)
   File "/usr/lib/python2.4/site-packages/matplotlib/__init__.py", line 712,
in rc
     rcParams[key] = v
   File "/usr/lib/python2.4/site-packages/matplotlib/__init__.py", line 552,
in __setitem__
     cval = self.validate[key](val)
   File "/usr/lib/python2.4/site-packages/matplotlib/rcsetup.py", line 43, in
validate_bool
     raise ValueError('Could not convert "%s" to boolean' % b)
ValueError: Could not convert "None" to boolean

   What I want is to have all curves from 1 to the maximum number (in
compList[0][16]) plotted on the same set of axes, then save that figure and
go on to the next one.

   Is my problem an indentation error at the end of the IF...ELIF tests?

TIA,

Rich

···

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

I need to efficiently plot a set of x,y points where each point has a
different color. I tried multiple calls to plot() with a single point each
but that is way too slow. I switched to using scatter() and passing in a
list of colors which works great. However, I'd really like to have the
marker options from plot() (things like '+' and 'x') which don't work w/
scatter.

What's the easiest way to get the markers from plot() with the efficiency
(and multi-colors) from scatter?

Thanks,
Ted

Ted Drain wrote:

I need to efficiently plot a set of x,y points where each point has a
different color. I tried multiple calls to plot() with a single point each
but that is way too slow. I switched to using scatter() and passing in a
list of colors which works great. However, I'd really like to have the
marker options from plot() (things like '+' and 'x') which don't work w/
scatter.

What's the easiest way to get the markers from plot() with the efficiency
(and multi-colors) from scatter?

Thanks,
Ted

Hi Ted,
oh - you can use '+' and 'x' and many more markers with scatter. It's unfortunately just not documented in the current release but is fixed in the repository.

   pylab.scatter(x,y, marker=(4,2))

gives a '+', and

   pylab.scatter(x,y, marker=(4,2,math.pi/4.))

gives a 'x'. The logic is a follows:

   marker(numside, type, angle)

numside is the number of edges, i.e. 4 for a plus or a cross.

type : 0 -> a filled symbol,
        1 -> a star-like symbol,
        2 -> a asterisk like symbol

angle: the symbol gets rotated by this angle

So in principle with this you can produce an endless number of different markers... :slight_smile:

Manuel

···

--
---------------------------------------
   Manuel Metz ............ Stw@...1936...
   Argelander Institut fuer Astronomie
   Auf dem Huegel 71 (room 3.06)
   D - 53121 Bonn

   E-Mail: mmetz@...1721...
   Web: www.astro.uni-bonn.de/~mmetz
   Phone: (+49) 228 / 73-3660
   Fax: (+49) 228 / 73-3672
---------------------------------------

Thanks! I had originally just tried it (ignoring the docs) but my plot just
showed dots instead of markers for both 'x' and '+'. Then I read the docs
which seemed to indicate they wouldn't work.

Late last night I was digging through axes.py and noticed that they should
be supported (and I found the scatter example that uses them). My problem
was that the point scale input needed to be 3-4 times larger than the
default value for the marker to be visible. Once I changed that, everything
worked fine.

Thanks for the doc patch - that will help everyone else in the future...

Ted

···

-----Original Message-----
From: Manuel Metz [mailto:mmetz@…1721…]
Sent: Thursday, March 20, 2008 1:13 AM
To: Ted Drain
Cc: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] Efficient scatter() w/ markers from
plot()?

Ted Drain wrote:
> I need to efficiently plot a set of x,y points where each point has a
> different color. I tried multiple calls to plot() with a single
point each
> but that is way too slow. I switched to using scatter() and passing
in a
> list of colors which works great. However, I'd really like to have
the
> marker options from plot() (things like '+' and 'x') which don't work
w/
> scatter.
>
> What's the easiest way to get the markers from plot() with the
efficiency
> (and multi-colors) from scatter?
>
> Thanks,
> Ted
>

Hi Ted,
oh - you can use '+' and 'x' and many more markers with scatter. It's
unfortunately just not documented in the current release but is fixed
in
the repository.

   pylab.scatter(x,y, marker=(4,2))

gives a '+', and

   pylab.scatter(x,y, marker=(4,2,math.pi/4.))

gives a 'x'. The logic is a follows:

   marker(numside, type, angle)

numside is the number of edges, i.e. 4 for a plus or a cross.

type : 0 -> a filled symbol,
        1 -> a star-like symbol,
        2 -> a asterisk like symbol

angle: the symbol gets rotated by this angle

So in principle with this you can produce an endless number of
different
markers... :slight_smile:

Manuel

--
---------------------------------------
   Manuel Metz ............ Stw@...1936...
   Argelander Institut fuer Astronomie
   Auf dem Huegel 71 (room 3.06)
   D - 53121 Bonn

   E-Mail: mmetz@...1721...
   Web: www.astro.uni-bonn.de/~mmetz
   Phone: (+49) 228 / 73-3660
   Fax: (+49) 228 / 73-3672
---------------------------------------

Update:

   I stripped the test data file down to a single plot's worth. Tried
different tuples in the data so different plotting functions were called. I
have pylab.hold(True) as the first statement in the for loop, and now --
with the single plot data -- there is no error trace.

   However, the code still displays the first curve of the three until I
manually close the matplotlib display window. Then the code proceeds to open
a new window and draw all three curves, then close itself after the save()
command.

   I've no idea how to clean up the drawing of the first curve and the pause
until that window is manually closed. Nothing I've read in the docs or on
the web site give me any clues.

   Clue appreciated.

Rich

···

On Wed, 19 Mar 2008, Rich Shepard wrote:

  When it runs in the test script the first curve is plotted in a
matplotlib window and the program pauses until I close that window by
clicking on the upper right button on the frame. Then this traceback is
displayed:

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Bingo! Found the problem.

   The plotting functions are in a separate module, and each was developed
interactively using ipython, then copied into the module. As a result, each
function retained the show() command at the end, and that was interfering
with the intent of the programmatic generation.

   Commenting out the p.show() command removes the display, but the stored
.png is there. Whew!

Rich

···

On Thu, 20 Mar 2008, Rich Shepard wrote:

  Clue appreciated.

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863