3d plot examples

FYI: I believe the best way to check for None is to use:

if Z is None

or

if Z is not None

This eliminates the possibility of Z implementing the __cmp__ method which would get called if you use "if Z == None". I only know this after wasting several hours trying to figure out why some code that looked perfectly reasonable wouldn't work after I adding a comparison method...

Ted

···

At 08:44 AM 2/14/2006, J.Brandenburg@...909... wrote:

Hello again,

in mplot3d.py I changed line 729:

- if Z:
+if Z==None:

Could this work too??? 'Python mplot3d.py' seems to work then but 'python
surface.py' fails with:

jens-ifw@...913...:/media/exchange/Python/3d> python surface.py
Traceback (most recent call last):
  File "surface.py", line 16, in ?
    ax = mplot3d.Axes3D(fig, axisbg='k')
AttributeError: 'module' object has no attribute 'Axes3D'

Cheers

Jens

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I've fallen into this trap too. Using if Z is None seems to be the *only* sensible way with numpy; it was explained in a mail of Robert Kern's last week.

It still seems to me a real 'gotcha' that if Z: doesn't work. Is there any possibility of it being allowed to work in numpy?

--George.

···

On 14 Feb 2006, at 16:59, Ted Drain wrote:

FYI: I believe the best way to check for None is to use:

if Z is None

or

if Z is not None

This eliminates the possibility of Z implementing the __cmp__ method which would get called if you use "if Z == None". I only know this after wasting several hours trying to figure out why some code that looked perfectly reasonable wouldn't work after I

George Nurser wrote:

It still seems to me a real 'gotcha' that if Z: doesn't work. Is there
any possibility of it being allowed to work in numpy?

We've had a long discussion about this. No.

http://www.scipy.net/pipermail/scipy-dev/2005-November/thread.html#3799

In short, that "if Z:" worked in Numeric was a *huge* gotcha that got almost
everyone who ever used that feature.

···

--
Robert Kern
robert.kern@...287...

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
  -- Richard Harter

Robert Kern wrote:

George Nurser wrote:

It still seems to me a real 'gotcha' that if Z: doesn't work. Is there
any possibility of it being allowed to work in numpy?

As Robert said, this was changed intentionally. The construct if Z: is usually used to determine if an argument was passed in. It is usually better to replace this construct with if Z is None: anyway.

The major problem is that the 'and' and the 'or' operations do "truth" value testing not "element-by-element" testing. This is going to cause an algorithmic error (but not raise an exception) over and over again. It is better to tell the person they are being ambiguous and move on.

I know it can be a bit of a pain to convert code that uses this construct, sorry about that. In the long run I think it will be better than having code that doesn't work because you forgot that 'and' and '&' do two entirely different things.

-Travis