Re: [Matplotlib-users] Polar 3D plot?

2010-03-18 Thread Armin Moser
Hi,

you can create your supporting points on a regular r, phi grid and
transform them then to cartesian coordinates:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib
import numpy as np
from matplotlib import cm
from matplotlib import pyplot as plt
step = 0.04
maxval = 1.0
fig = plt.figure()
ax = Axes3D(fig)

# create supporting points in polar coordinates
r = np.linspace(0,1.25,50)
p = np.linspace(0,2*np.pi,50)
R,P = np.meshgrid(r,p)
# transform them to cartesian system
X,Y = R*np.cos(P),R*np.sin(P)

Z = ((R**2 - 1)**2)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet)
ax.set_zlim3d(0, 1)
ax.set_xlabel(r'$\phi_\mathrm{real}$')
ax.set_ylabel(r'$\phi_\mathrm{im}$')
ax.set_zlabel(r'$V(\phi)$')
ax.set_xticks([])
plt.show()

hth
Armin


klukas schrieb:
 I'm guessing this is currently impossible with the current mplot3d
 functionality, but I was wondering if there was any way I could generate a
 3d graph with r, phi, z coordinates rather than x, y, z?  
 
 The point is that I want to make a figure that looks like the following:
 http://upload.wikimedia.org/wikipedia/commons/7/7b/Mexican_hat_potential_polar.svg
 
 Using the x, y, z system, I end up with something that has long tails like
 this:
 http://upload.wikimedia.org/wikipedia/commons/4/44/Mecanismo_de_Higgs_PH.png
 
 If I try to artificially cut off the data beyond some radius, I end up with
 jagged edges that are not at all visually appealing.
 
 I would appreciate any crazy ideas you can come up with.
 
 Thanks,
 Jeff
 
 P.S. Code to produce the ugly jaggedness is included below:
 
 ---
 from mpl_toolkits.mplot3d import Axes3D
 import matplotlib
 import numpy as np
 from matplotlib import cm
 from matplotlib import pyplot as plt
 
 step = 0.04
 maxval = 1.0
 fig = plt.figure()
 ax = Axes3D(fig)
 X = np.arange(-maxval, maxval, step)
 Y = np.arange(-maxval, maxval, step)
 X, Y = np.meshgrid(X, Y)
 R = np.sqrt(X**2 + Y**2)
 Z = ((R**2 - 1)**2) * (R  1.25)
 ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet)
 ax.set_zlim3d(0, 1)
 #plt.setp(ax.get_xticklabels(), visible=False)
 ax.set_xlabel(r'$\phi_\mathrm{real}$')
 ax.set_ylabel(r'$\phi_\mathrm{im}$')
 ax.set_zlabel(r'$V(\phi)$')
 ax.set_xticks([])
 plt.show()
 


-- 
Armin Moser
Institute of Solid State Physics
Graz University of Technology
Petersgasse 16
8010 Graz
Austria
Tel.: 0043 316 873 8477


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Can matplotlib generate charts like this?

2009-09-10 Thread Armin Moser
Erik Wickstrom schrieb:
 Hi all,

 Can matplotlib (or any other Python charting library) generate charts
 like this: (also attached if you prefer)
Here is a demo-script. The second way is inspired by matlab. Can this be
done more easily in python? Can X and Y be built more elegantly with numpy?

Armin
---8
from pylab import *
# data generation
x = linspace(0,10,100)
y = exp(-x)
ye = y + rand(y.size)-0.5
# plot the vertical lines
# with loop
for xl,yl,yel in zip(x,y,ye):
plot([xl,xl],[yl,yel],'r')
plot(x,y,x,ye,'d')

# plot by separating with NaN
figure()
X = zeros((x.size,3))
Y = zeros((x.size,3))
X[:,0],X[:,1],X[:,2] = x,x,NaN
Y[:,0],Y[:,1],Y[:,2] = y,ye,NaN
plot(X.flatten(),Y.flatten(),x,y,x,ye,'d')

show()
---8

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] zero division: warning and exception

2009-05-15 Thread Armin Moser
darkside schrieb:
 Hi list,
 I have to make a division that sometimes yields and inf, and I want to
 replace it by 0.
 I have try this:
 ---
 import pylab as p
 p.seterr(divide='raise')
 l = array vector defined along the program
 try:
 a = (dr*R*dl)/(1.-((R0/R)*p.sin(l))**2)**(1./2)
 except FloatingPointError:
 a=0
 -
 It works, but it doesn't return an array as expect, if some of the values
 are zero, then a = 0.
 So I tried:
 --
 a = p.zeros(len(l))
 for i in range(len(l)):
 try:
 a[i] = (dr*R*dl)/(1.-((R0/R)*p.sin(l[i]))**2)**(1./2)
 except FloatingPointError:
 a[i]=0
 
 But doing it this way I'm not able to get an exception:
 array([ Inf])
 And I don't know what I have to change to get an exception doing things this
 way.
You can do it that way:
a = rand(5,5)
b = a.round()
c = a/b
c[isinf(c)] = 0 # use indexing with boolean array [1] to set zero

In your case:
a = (dr*R*dl)/(1.-((R0/R)*p.sin(l))**2)**(1./2)
a[isinf(a)] = 0

HTH
Armin

[1]http://www.scipy.org/Tentative_NumPy_Tutorial#head-0dffc419afa7d77d51062d40d2d84143db8216c2

--
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] contour overlapping

2009-05-14 Thread Armin Moser
Sebastian Busch schrieb:
 Armin Moser wrote:
 Sebastian Busch wrote:
 ...
 array([list(a[i,:i])+list(b[i,i:]) for i in range(a.shape[0])])
 It seems that I did not understand what you tried to reach.
 ...
 
 Sorry. I wanted to do the same as Matthias -- taking his example:
I meant I did not understand in the first what Bala tried to reach. I
have answered to the wrong mail and quoted badly. Sorry

Armin


--
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] contour overlapping

2009-05-13 Thread Armin Moser
Bala subramanian schrieb:
 Dear Matthias,
 
 Thank you for the information. Could you please provide me a small example
 of such overlapping.
Look at
http://matplotlib.sourceforge.net/examples/pylab_examples/contour_image.html

or any other contour example from this page:
http://matplotlib.sourceforge.net/examples/index.html

Armin

--
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] contour overlapping

2009-05-13 Thread Armin Moser
Bala subramanian schrieb:
 hai Armin,
 
 I looked through the examples. I could not find any example of overlapping
 two differnet countours on the same plot.
I think the first example filled contours does exactly that. You want to
show two contours over each other in the same plot.
You just have to substitute the Z in cset_1 with matrix_1 and in cset_2
with matrix_2. Of course it will be helpful to use different colormaps.
E.g. a grey one for the underlying contour and a colored for the top one.

x = arange(5)
y = arange(5)
x,y = meshgrid(x,y)
Z = x**2+y**2
#contourf(Z,cmap=cm.binary) # filled contours gray
contour(Z) # not filled contours colored
error = rand(x.shape[0],x.shape[1]) # to generate a new Z
Z = (x+error)**2+(y+error)**2
contour(Z) # colored not filled contours

Armin

--
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] contour overlapping

2009-05-13 Thread Armin Moser
Sebastian Busch wrote:
 Matthias Michler wrote:
 ...
 for i in xrange(len(matrix3[:, 0])): # all rows
 for j in xrange(len(matrix3[0, :])):# all columns
 ...
 
 if your matrices a and b are rectangular (and i think the diagonal
 makes only sense in this case), you can also say:
 
 array([list(a[i,:i])+list(b[i,i:]) for i in range(a.shape[0])])
It seems that I did not understand what you tried to reach. Sorry for
pointing into the wrong direction.

Another possibility would be to use masked arrays:

8-
from pylab import *

x = arange(100)
y = arange(100)
x,y = meshgrid(x,y)
Z = x**2+y**2
mask = ones(Z.shape)
# contour, imshow, pcolor do not show values at positions
# where the mask is True
lower_left_masked = triu(mask)==0 # lower left part in matrix masked
Z = ma.masked_array(Z,mask=lower_left_masked)
contourf(Z,origin='lower')

error = rand(x.shape[0],x.shape[1])
upper_right_masked = tril(mask)==0
Z = (x+error)**2+(y+error)**2
Z = ma.masked_array(Z,mask=upper_right_masked)
contourf(Z,cmap=cm.binary)
axis('tight')
show()

--
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Tight axis after deletion of image

2009-04-22 Thread Armin Moser
Armin Moser schrieb:
 Hi,
 
 i have an application showing some pseudo color plots as images using
 imshow. After deleting an image and calling ax.axis('tight') the limits
 of the axes are not updated correctly. Is this a bug, incorrect use or
 intended? The behavior is demonstrated in the appended script.
It looks like calling ax.relim() is the preferred way of setting limits
after deleting artists. Unfortunately this method does only consider
patches and lines. I added some lines in axes.py to support images to
(the patch against the current svn-version is appended).

If this is not the correct place for submitting patches please tell me
where I should put it instead.

Thanks and best regards
Armin
--- C:\DOKUME~1\ArminM\LOKALE~1\Temp\axes.py-revBASE.svn001.tmp.py  Mi Apr 
22 11:40:58 2009
+++ C:\Dokumente und Einstellungen\ArminM\Eigene 
Dateien\matplotlib_trunk\matplotlib\lib\matplotlib\axes.py Mi Apr 22 
11:40:49 2009
@@ -1430,6 +1430,14 @@
 for p in self.patches:
 self._update_patch_limits(p)
 
+for im in self.images:
+self._update_image_limits(im)
+
+def _update_image_limits(self,im):
+xmin,xmax,ymin,ymax = im.get_extent()
+corners = (xmin,ymin),(xmax,ymax)
+self.update_datalim(corners)
+
 def update_datalim(self, xys, updatex=True, updatey=True):
 'Update the data lim bbox with seq of xy tups or equiv. 2-D array'
 # if no data is set currently, the bbox will ignore its
--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Tight axis after deletion of image

2009-04-21 Thread Armin Moser
Hi,

i have an application showing some pseudo color plots as images using
imshow. After deleting an image and calling ax.axis('tight') the limits
of the axes are not updated correctly. Is this a bug, incorrect use or
intended? The behavior is demonstrated in the appended script.

Best regards,
Armin

-8-
#!/usr/bin/env python
from pylab import *

a = rand(5,5)
ax = axes()
ax.imshow(a,extent=(0,5,0,5))
ax.imshow(a,extent=(5,10,5,10))
ax.axis('tight')
waitforbuttonpress()

ax.images.pop(0)
ax.axis('tight')
show()
-8-

--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] griddata performance

2009-02-20 Thread Armin Moser
Hi,

I would like to interpolate an array of shape (801,676) to regularily
spaced datapoints using griddata. This interpolation is quick if the
(x,y) supporting points are computed as X,Y = meshgrid(x,y). If this
condition is not fullfilled the delaunay triangulation is extremely
slow, i.e. not useable. Is this a known property of the used
triangulation? The triangulation can be performed with matlab without
any problems.

Armin

--
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] griddata performance

2009-02-20 Thread Armin Moser
Jeff Whitaker wrote:
 Armin Moser wrote:
 Hi,

 I would like to interpolate an array of shape (801,676) to regularily
 spaced datapoints using griddata. This interpolation is quick if the
 (x,y) supporting points are computed as X,Y = meshgrid(x,y). If this
 condition is not fullfilled the delaunay triangulation is extremely
 slow, i.e. not useable. Is this a known property of the used
 triangulation? The triangulation can be performed with matlab without
 any problems.

 Armin
   
 
 Armin:  You could try installing the natgrid toolkit and see if that
 speeds up griddata at all.  If not, please post a test script with data
 and maybe we can figure out what is going on.
I have already tried natgrid and it didn't improve the situation. As
suggested I append a script demonstrating the problem.

Thanks
Armin

--8-
from numpy import *
from pylab import *
import time

deg2rad = pi/180.0
ai = 0.12*deg2rad
x  = linspace(13,40,676)
y  = linspace(10,22,801)

x  = x*deg2rad
y  = y*deg2rad
[x,y] = meshgrid(x,y)
z = (x**2+y**2)

xi = linspace(x.min(),x.max(),x.shape[1])
yi = linspace(y.min(),y.max(),y.shape[0])
tic= time.time()
zi = griddata(x.flatten(),y.flatten(),z.flatten(),xi,yi)
toc = time.time()
print toc-tic

fac = 2*pi/1.2681
nx  = fac * (cos(y)*cos(x) - cos(ai))
ny  = fac * (cos(y)*sin(x))
nz  = fac * (sin(y) + sin(ai))
np  = sqrt(nx**2 + ny**2)

z = (np**2+nz**2)*exp(-0.001*nz)

xi = linspace(np.min(),np.max(),x.shape[1])
yi = linspace(nz.min(),nz.max(),y.shape[0])
tic = time.time()
zi = griddata(np.flatten(),nz.flatten(),z.flatten(),xi,yi)
toc = time.time()
print toc-tic

--
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] griddata performance

2009-02-20 Thread Armin Moser
Jeff Whitaker wrote:
 Armin Moser wrote:
 Jeff Whitaker wrote:
  
 Armin Moser wrote:

 Hi,

 I would like to interpolate an array of shape (801,676) to regularily
 spaced datapoints using griddata. This interpolation is quick if the
 (x,y) supporting points are computed as X,Y = meshgrid(x,y). If this
 condition is not fullfilled the delaunay triangulation is extremely
 slow, i.e. not useable. Is this a known property of the used
 triangulation? The triangulation can be performed with matlab without
 any problems.

 Armin
 
 Armin:  You could try installing the natgrid toolkit and see if that
 speeds up griddata at all.  If not, please post a test script with data
 and maybe we can figure out what is going on.
 
 I have already tried natgrid and it didn't improve the situation. As
 suggested I append a script demonstrating the problem.

 Thanks
 Armin
   
 
 Armin:  On my mac, your two benchmarks take 15 and 14 seconds.  Do you
 consider that too slow?
No definitely not but up to now I always killed the process (after more
than 10 minutes). I tried the script again and it worked... I have to
check the original on monday at work.
 
 Perhaps this is just a toy example to test griddata, but I assume you
 realize that you wouldn't normally use griddata to interpolate data on
 one regular grid to another regular grid.  griddata is strictly for
 interpolating scatter data (not on a regular mesh) to a regular mesh.
Yes I do, but the supporting points of the second example are not on a
regular grid.

Thanks a lot
Armin

--
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] griddata performance

2009-02-20 Thread Armin Moser
Eric Firing wrote:
 Jeff Whitaker wrote:
 Armin Moser wrote:
 Jeff Whitaker wrote:
  
 Armin Moser wrote:

 Hi,

 I would like to interpolate an array of shape (801,676) to regularily
 spaced datapoints using griddata. This interpolation is quick if the
 (x,y) supporting points are computed as X,Y = meshgrid(x,y). If this
 condition is not fullfilled the delaunay triangulation is extremely
 slow, i.e. not useable. Is this a known property of the used
 triangulation? The triangulation can be performed with matlab without
 any problems.

 Armin
 
 Armin:  You could try installing the natgrid toolkit and see if that
 speeds up griddata at all.  If not, please post a test script with data
 and maybe we can figure out what is going on.
 
 I have already tried natgrid and it didn't improve the situation. As
 suggested I append a script demonstrating the problem.

 Thanks
 Armin
   

 Armin:  On my mac, your two benchmarks take 15 and 14 seconds.  Do you
 consider that too slow?
 
 I got 10 s and 8 s on my Thinkpad--but that was without natgrid.  When I
 installed natgrid, the benchmark was taking so long I killed the window.
Thats the behaviour I observed (on Windows and Linux) with and without
natgrid. I'm very puzzled at the moment.

Thanks a lot
Armin

--
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users