3D subfigures in matplotlib?

2011-04-05 Thread MATLABdude
How can I make maybe 3D subfigures with Python and matplotlib?

I found the following example (http://matplotlib.sourceforge.net/
examples/mplot3d/subplot3d_demo.html), but it doesn't work.
---
from mpl_toolkits.mplot3d.axes3d import Axes3D
import matplotlib.pyplot as plt


# imports specific to the plots in this example
import numpy as np
from matplotlib import cm
from mpl_toolkits.mplot3d.axes3d import get_test_data


fig = plt.figure(figsize=(9.5,5.0))

# First subplot
ax = fig.add_subplot(1, 2, 1, projection='3d')
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,
linewidth=0, antialiased=False)
ax.set_zlim3d(-1.01, 1.01)

fig.colorbar(surf, shrink=0.5, aspect=10)

# Second subplot
ax = fig.add_subplot(1, 2, 2, projection='3d')
X, Y, Z = get_test_data(0.05)
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

plt.show()


The error message is:

>>> ax = fig.add_subplot(1, 2, 1, projection='3d')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/pymodules/python2.6/matplotlib/figure.py", line 677,
in add_subplot
projection_class = get_projection_class(projection)
  File "/usr/lib/pymodules/python2.6/matplotlib/projections/
__init__.py", line 61, in get_projection_class
raise ValueError("Unknown projection '%s'" % projection)
ValueError: Unknown projection '3d'
>>>


I am using Python 2.6.6., and matplotlib 0.99.3.

How can I make several subfigures in 3D?
-- 
http://mail.python.org/mailman/listinfo/python-list


MATLAB to Python?

2010-11-17 Thread MATLABdude
Hi!

Can you, please, try to help me with Python? I try to convert a MATLAB
program to Python.

Here are the MATLAB codes:
http://pastebin.com/eJetYizv
http://pastebin.com/0eXTVfyN

Here is my Python code:
http://pastebin.com/jCPdLHx7

What is wrong with my Python code? The program doesn't produce quite
the same lambdas as the MATLAB program does. My code probably has lots
of errors because I'm just learning the basics about Python.

Thanks for all the help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MATLAB to Python?

2010-11-18 Thread MATLABdude
On Nov 17, 10:04 am, MATLABdude  wrote:

Thanks guys!

I still have some problems. I made the code somewhat simpler by
dropping off some parts of it (xx, f).

Now my Python code calculates 8 different values for lambda. The
problem is that I don't know where the minus sign comes from. Also the
values themselves are not identical compared to the values of the
MATLAB program.
nonhomog.py | nonhomog.m
-0.774244159818 | 0.9976
-0.823595831818 | 0.9969
-0.774374006419 | 0.5464
-1.0| -54.3440
-0.774244172803 | 0.9976
-0.774244289666 | 0.9976
-0.823595831818 | 0.9969
-1.0| 0.9674

The new Python code can be found here: http://pastebin.com/c1UvtXxu
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MATLAB to Python?

2010-11-22 Thread MATLABdude
On Nov 17, 10:53 am, Arnaud Delobelle  wrote:
> I guess that the step is supposed to be h, so you should write:
>     xx = range(-kappa, kappa+1, h)

This is what I have in the source code:
---8<---8<---8<---8<---
h =  0.105069988414
xx = range(-kappa, kappa+1, h)
---8<---8<---8<---8<---

This is what Python says: ValueError: range() step argument must not
be zero

Can step not be a float value?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MATLAB to Python?

2010-11-22 Thread MATLABdude
On Nov 22, 11:11 am, Peter Otten <__pete...@web.de> wrote:
> Try numpy.arange() instead:
> >>> numpy.arange(0, 1, .1)
> array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9])

Thanks! It worked.

What's wrong with the following code?
---8<---8<---8<---
T0_orig = [5, 50, 500, 5000]
for counter in T0_orig:
T0 = (L**2)/(D*pi**2)*counter
amax = T0/kappa
alpha = (10**-6)*amax
lambda_, xx, f = nonhomog_solver(kappa, alpha, nu, nx)
V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ )
print "V0 = ", V0
print ""
---8<---8<---8<---

Python says:
---8<---8<---8<---
Traceback (most recent call last):
  File "nonhomog.py", line 159, in 
main()
  File "nonhomog.py", line 157, in main
nonhomog(0.2)
  File "nonhomog.py", line 152, in nonhomog
V0 = sqrt( T0_orig*(m**-1) + pi**2 * D/(m*L**2)*lambda_ )
TypeError: can't multiply sequence by non-int of type 'float'
---8<---8<---8<---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MATLAB to Python?

2010-11-22 Thread MATLABdude
On Nov 23, 9:43 am, Arnaud Delobelle  wrote:
> T0_orig is a list and you are trying to multiply this list by a float
> (m**-1)

Yes, yes of course. Thanks! :)

This works:
---8<---8<---8<---
T0_orig = [5, 50, 500, 5000]
for counter in T0_orig:
T0 = (L**2)/(D*pi**2)*counter
amax = T0/kappa
alpha = (10**-6)*amax
lambda_, xx, f = nonhomog_solver(kappa, alpha, nu, nx)
V0 = sqrt( counter*(m**-1) + pi**2 * D/(m*L**2)*lambda_ )
print "V0 = ", V0
print ""
---8<---8<---8<---
-- 
http://mail.python.org/mailman/listinfo/python-list