Re: [Matplotlib-users] Memory usage

2011-01-14 Thread CASOLI Jules
Hooo, well done! This is it.

I didn't knew about caching...
I was indeed using ipython, but I did led some test using the basic python 
interpreter,with same results, so I did not mention this point.
In fact, python's basic interpreter still records the last three outputs. As my 
tests were really short (plt.close() ; mpl.cbook.report_memory() ; gc.collect() 
is only two lines before the collect, only o)ne o,f theme outputt ing 
something) even pyhton's caching was still at work, and the garbage collector 
could not free anything.

Thanks a lot, and also thanks to Ben for taking interest !

Jules

PS : Gary, sorry, for the duplicated mail...

Le 14 janv. 2011 à 04:04, gary ruben a écrit :

 You're not doing this from ipython are you? It's cache hangs onto the
 plot object references and stops python's garbage collector from
 releasing them. If so, you can disable the cache as a workaround. A
 better option would be if ipython implemented an option to avoid
 caching references to matplotlib objects.
 
 Gary R.
 
 On Fri, Jan 14, 2011 at 2:59 AM, Benjamin Root ben.r...@ou.edu wrote:
 On Thu, Jan 13, 2011 at 7:54 AM, CASOLI Jules jules.cas...@cea.fr wrote:
 
 Hello to all,
 
 This is yet another question about matplotlib not freeing memory, when
 closing a figure (using close()).
 Here is what I'm doing (tried with several backends, on MacOSX and Linux,
 with similar results):
 
 import matplotlib as mpl
 from matplotlib import pylot as plt
 import numpy as np
 
 a = np.arange(100)
 mpl.cbook.report_memory()
 # - output: 54256
 plt.plot(a)
 mpl.cbook.report_memory()
 # - output: 139968
 plt.close()
 mpl.cbook.report_memory()
 # - output: 138748
 
 
 Shouldn't plt.close() close the figure _and_ free the memory used by it?
 What am I doing wrong ?
 I tried several other ways to free the memory, such as f = figure(); ... ;
 del f, without luck.
 
 Any help appreciated !
 
 P.S. : side question : how come the call to plot take so much memory (90MB
 for a 8MB array ?). I have read somewhere that each point is coded on three
 RGB floats, but it only means an approx. 12MB plot... (plus small overhead)
 
 Jules
 
 
 
 Jules,
 
 Which version of Matplotlib are you using and which backend?  On my Linux
 install of matplotlib (development branch) using GTKAgg, the memory usage
 does get high during the call to show(), but returns to (near) normal
 amounts after I close.  An interesting observation is that if the
 interactive mode is off, the memory usage returns back to just a few
 kilobytes above where it was before, but if interactive mode was turned on,
 the memory usage returned to being a few hundred kilobytes above where it
 started.
 
 Ben Root
 
 P.S. - As a side note, estimating the memory size of these plots from the
 given data isn't as straight-forward as multiplying by three (actually, it
 would be four because of the transparency value in addition to rgb).  There
 are many other parts of the graph that needs to be represented (all having
 rgba values) but there are also a lot of simplifications that are done to
 reduce the amount of memory needed to represent these objects.
 
 --
 Protect Your Site and Customers from Malware Attacks
 Learn about various malware tactics and how to avoid them. Understand
 malware threats, the impact they can have on your business, and how you
 can protect your company and customers by using code signing.
 http://p.sf.net/sfu/oracle-sfdevnl
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 
 


--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] colorbar with Axes3D for a set of collections?

2011-01-14 Thread Daniel Mader
Hi Eric,

thanks for your feedback, it helped a lot! I have some questions left,
see below.

2011/1/14 Eric Firing efir...@hawaii.edu:
 Quick thoughts with no testing or concrete examples:

 1) Don't set the cmap or norm for the colorbar; let it inherit those
 properties from the mappable to which it is connected.

Am I doing this correctly in the attached code? It seems there are
several ways of doing this... Which is the suggested one? How can I
label the colorbar?

 2) Ensure that the cmap and norm are the same for all collections.  You
 are already taking care of the cmap, so the problem is that you are
 autoscaling the collections separately, which is setting vmin and vmax
 to different values for the different collections.  Use the data to
 figure out the range (vmin, vmax) that you want the colors to span, and
 then for each collection, instead of col.autoscale(), use

        col.norm.vmin = vmin
        col.norm.vmax = vmax

That was what I needed, see code :)

 (You could also make a single norm instance for all the collections to
 use, just as with the cmap, so that you only have to set vmin and vmax
 once.)

And this I don't understandm could you please elaborate?

Thanks a very lot in advance
best regards from Austria,

Daniel


3D_colorbar.py
Description: Binary data
--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Why no STIX fonts?

2011-01-14 Thread Neal Becker
I have several machines running fedora f14.  2 of them produce plots fine with 
STIX, but 1 doesn't, but gives:
/usr/lib64/python2.7/site-packages/matplotlib/font_manager.py:1242: 
UserWarning: 
findfont: Font family ['STIXSizeOneSym'] not found. Falling back to Bitstream 
Vera Sans
  (prop.get_family(), self.defaultFamily[fontext]))
/usr/lib64/python2.7/site-packages/matplotlib/font_manager.py:1252: 
UserWarning: 
findfont: Could not match :family=Bitstream Vera 
Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0. 
Returning /usr/share/fonts/thai-scalable/Waree-Oblique.ttf
  UserWarning)
/usr/lib64/python2.7/site-packages/matplotlib/font_manager.py:1242: 
UserWarning: 
findfont: Font family ['STIXSizeThreeSym'] not found. Falling back to Bitstream 
Vera Sans
  (prop.get_family(), self.defaultFamily[fontext]))
...

On that machine I have:
Package stix-variants-fonts-1.0.0-1.fc14.noarch already installed and latest 
version
Package stix-pua-fonts-1.0.0-1.fc14.noarch already installed and latest version
Package stix-fonts-1.0.0-1.fc14.noarch already installed and latest version
Package stix-fonts-doc-1.0.0-1.fc14.noarch already installed and latest version
Package stix-sizes-fonts-1.0.0-1.fc14.noarch already installed and latest 
version
Package stix-integrals-fonts-1.0.0-1.fc14.noarch already installed and latest 
version

 rpm -q python-matplotlib
python-matplotlib-1.0.0-2.fc14.x86_64

Any ideas how to debug this?


--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Axes3D:adjusting the parameters of the plot

2011-01-14 Thread Bala subramanian
Friends,
I sent the following mail to mpl users with a figure. Since the size was
bigger, it bounced back to my email. So i am fwd it again without attaching
the figure.

It seems that i can only set tick labels and limits of the axes using
set_xlabel and set_xlim3d functions.Basically i want to know how to
manipulate the x,y and z ticks intervals for a graph created with Axes3D.


On Fri, Jan 14, 2011 at 12:06 PM, Bala subramanian 
bala.biophys...@gmail.com wrote:

 Dear Friends, i used the following code to create a 3D plot (attached
 figure). I manipulate the appearance of the graph. Someone please enlighten
 me on the same. I dnt get what functions should i use to do the following
 manipulations.

 1) How to remove the blue shading in the grid
 2) How to change the distance between the axis label and axis tick labels
 3) How to set the interval of the axis ticks. For example the xlim varies
 from -80 to 60. I want to set xticks at an interval of 30 rather than 20 as
 in the plot.

 My code.
 import numpy as np
 import matplotlib as mpl
 from mpl_toolkits.mplot3d import Axes3D
 import matplotlib.pyplot as plt

 FIG=plt.figure(figsize=(4.,3.27),dpi=200)
 ax = Axes3D(FIG,azim=-60,elev=15)

 x=np.reshape(np.loadtxt(data[0]),15000)
 y=np.reshape(np.loadtxt(data[1]),15000)
 z=np.reshape(np.loadtxt(data[2]),15000)

 ax.scatter3D(x[::10],y[::10],z[::10],edgecolors=col[i],facecolors='white',marker=mar[i],s=5,alpha=0.7)
 ax.set_xlabel('PC1',size=8)
 ax.set_ylabel('PC2',size=8)
 ax.set_zlabel('PC3',size=8)
 ax.set_xlim3d(-80,60,30)
 ax.set_ylim3d(-40,50,30)
 ax.set_zlim3d(-40,40,30)











--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Axes3D:adjusting the parameters of the plot

2011-01-14 Thread Benjamin Root
On Fri, Jan 14, 2011 at 5:06 AM, Bala subramanian bala.biophys...@gmail.com
 wrote:

 Dear Friends, i used the following code to create a 3D plot (attached
 figure). I manipulate the appearance of the graph. Someone please enlighten
 me on the same. I dnt get what functions should i use to do the following
 manipulations.

 1) How to remove the blue shading in the grid
 2) How to change the distance between the axis label and axis tick labels


Unfortunately, this is not possible to do with the current version of
matplotlib.  I have been working on making this (somewhat) possible in the
next release.  One thing you can do to make the axes labels look better is
to trigger mplot3d's internal logic to rotate the labels to be parallel to
the axes.  mplot3d automatically rotates labels that have more than 4
characters in them.  So, if you want PC1 to be rotated, set the axis label
to  PC1  with spaces so that it will have 5 characters and get rotated.


 3) How to set the interval of the axis ticks. For example the xlim varies
 from -80 to 60. I want to set xticks at an interval of 30 rather than 20 as
 in the plot.

 My code.
 import numpy as np
 import matplotlib as mpl
 from mpl_toolkits.mplot3d import Axes3D
 import matplotlib.pyplot as plt

 FIG=plt.figure(figsize=(4.,3.27),dpi=200)
 ax = Axes3D(FIG,azim=-60,elev=15)

 x=np.reshape(np.loadtxt(data[0]),15000)
 y=np.reshape(np.loadtxt(data[1]),15000)
 z=np.reshape(np.loadtxt(data[2]),15000)

 ax.scatter3D(x[::10],y[::10],z[::10],edgecolors=col[i],facecolors='white',marker=mar[i],s=5,alpha=0.7)
 ax.set_xlabel('PC1',size=8)
 ax.set_ylabel('PC2',size=8)
 ax.set_zlabel('PC3',size=8)
 ax.set_xlim3d(-80,60,30)
 ax.set_ylim3d(-40,50,30)
 ax.set_zlim3d(-40,40,30)



Passing '30' to set_xlim to set the tick intervals is not a feature in both
regular 2d plotting and 3d plotting, so I don't know how you expected that
to work.  If you want to manually control the axis ticks, you can use axis
locators just like for 2D plots, keeping in mind that the axis objects for
3d plots are ax.w_xaxis, ax.w_yaxis, and ax.w_zaxis (where for a 2d plot, it
would be ax.xaxis, ax.yaxis, ax.zaxis).

I hope this helps!
Ben Root
--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Only one colorbar for a figure?

2011-01-14 Thread Thøger Emil Juul Thorsen
Hi list; 

I am trying to do an imshow() comparison of four different data sets
(astronomical photos), and since I want to show the differences in
strength, I use fixed vmin and vmax.

I would very much like one and only one colour bar for the entire
figure, but I haven't been able to figure out how to do it without
creating an entire subplot for it, and that is really kludgey and
unhandy.

I tried the Interwebz but have had no luck figuring it out.

Cheers; 

Emil


signature.asc
Description: This is a digitally signed message part
--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Why no STIX fonts?

2011-01-14 Thread Michael Droettboom
You can try deleting matplotlib's font cache in 
~/.matplotlib/fontList.cache.

If that doesn't work, set the rcParam verbose.level to 
debug-annoying and send us the output...

Mike

On 01/14/2011 08:10 AM, Neal Becker wrote:
 I have several machines running fedora f14.  2 of them produce plots fine with
 STIX, but 1 doesn't, but gives:
 /usr/lib64/python2.7/site-packages/matplotlib/font_manager.py:1242: 
 UserWarning:
 findfont: Font family ['STIXSizeOneSym'] not found. Falling back to Bitstream
 Vera Sans
(prop.get_family(), self.defaultFamily[fontext]))
 /usr/lib64/python2.7/site-packages/matplotlib/font_manager.py:1252: 
 UserWarning:
 findfont: Could not match :family=Bitstream Vera
 Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0.
 Returning /usr/share/fonts/thai-scalable/Waree-Oblique.ttf
UserWarning)
 /usr/lib64/python2.7/site-packages/matplotlib/font_manager.py:1242: 
 UserWarning:
 findfont: Font family ['STIXSizeThreeSym'] not found. Falling back to 
 Bitstream
 Vera Sans
(prop.get_family(), self.defaultFamily[fontext]))
 ...

 On that machine I have:
 Package stix-variants-fonts-1.0.0-1.fc14.noarch already installed and latest
 version
 Package stix-pua-fonts-1.0.0-1.fc14.noarch already installed and latest 
 version
 Package stix-fonts-1.0.0-1.fc14.noarch already installed and latest version
 Package stix-fonts-doc-1.0.0-1.fc14.noarch already installed and latest 
 version
 Package stix-sizes-fonts-1.0.0-1.fc14.noarch already installed and latest
 version
 Package stix-integrals-fonts-1.0.0-1.fc14.noarch already installed and latest
 version

   rpm -q python-matplotlib
 python-matplotlib-1.0.0-2.fc14.x86_64

 Any ideas how to debug this?


 --
 Protect Your Site and Customers from Malware Attacks
 Learn about various malware tactics and how to avoid them. Understand
 malware threats, the impact they can have on your business, and how you
 can protect your company and customers by using code signing.
 http://p.sf.net/sfu/oracle-sfdevnl
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users



-- 
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA


--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Only one colorbar for a figure?

2011-01-14 Thread Benjamin Root
2011/1/14 Thøger Emil Juul Thorsen thoe...@fys.ku.dk

 Hi list;

 I am trying to do an imshow() comparison of four different data sets
 (astronomical photos), and since I want to show the differences in
 strength, I use fixed vmin and vmax.

 I would very much like one and only one colour bar for the entire
 figure, but I haven't been able to figure out how to do it without
 creating an entire subplot for it, and that is really kludgey and
 unhandy.

 I tried the Interwebz but have had no luck figuring it out.

 Cheers;

 Emil


Emil,

I had this problem once before.  You can use the axes_grid1 tool to do this:

http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html

Unfortunately, our documentation is a little broken on that page, but if you
take a look at this source code example, you can see how to use AxesGrid to
create a subplot grid that pre-allocates space for a single cbar
automatically!

http://matplotlib.sourceforge.net/plot_directive/mpl_toolkits/axes_grid/examples/demo_axes_grid.py

I hope this helps!

Ben Root
--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Why no STIX fonts?

2011-01-14 Thread Neal Becker
Seems that deleting fontList.cache did it.

Michael Droettboom wrote:

 You can try deleting matplotlib's font cache in
 ~/.matplotlib/fontList.cache.
 
 If that doesn't work, set the rcParam verbose.level to
 debug-annoying and send us the output...
 
 Mike
 
 On 01/14/2011 08:10 AM, Neal Becker wrote:
 I have several machines running fedora f14.  2 of them produce plots fine
 with STIX, but 1 doesn't, but gives:
 /usr/lib64/python2.7/site-packages/matplotlib/font_manager.py:1242:
 UserWarning: findfont: Font family ['STIXSizeOneSym'] not found. Falling back
 to Bitstream Vera Sans
(prop.get_family(), self.defaultFamily[fontext]))
 /usr/lib64/python2.7/site-packages/matplotlib/font_manager.py:1252:
 UserWarning: findfont: Could not match :family=Bitstream Vera
 Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0.
 Returning /usr/share/fonts/thai-scalable/Waree-Oblique.ttf
UserWarning)
 /usr/lib64/python2.7/site-packages/matplotlib/font_manager.py:1242:
 UserWarning: findfont: Font family ['STIXSizeThreeSym'] not found. Falling
 back to Bitstream Vera Sans
(prop.get_family(), self.defaultFamily[fontext]))
 ...

 On that machine I have:
 Package stix-variants-fonts-1.0.0-1.fc14.noarch already installed and latest
 version
 Package stix-pua-fonts-1.0.0-1.fc14.noarch already installed and latest
 version Package stix-fonts-1.0.0-1.fc14.noarch already installed and latest
 version Package stix-fonts-doc-1.0.0-1.fc14.noarch already installed and
 latest version Package stix-sizes-fonts-1.0.0-1.fc14.noarch already installed
 and latest version
 Package stix-integrals-fonts-1.0.0-1.fc14.noarch already installed and latest
 version

   rpm -q python-matplotlib
 python-matplotlib-1.0.0-2.fc14.x86_64

 Any ideas how to debug this?


 
--
 Protect Your Site and Customers from Malware Attacks
 Learn about various malware tactics and how to avoid them. Understand
 malware threats, the impact they can have on your business, and how you
 can protect your company and customers by using code signing.
 http://p.sf.net/sfu/oracle-sfdevnl
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users

 
 



--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] MemoryError with import matplotlib

2011-01-14 Thread sprobst

Hi all,

I tried to plot parts of a large 3D array with each 4 float64 entries.
Loading the array with numpy.fromfile and performing a type conversion
afterwards ends up in a MemoryError.

The following code reproduces the error:
***
import gc

from os import path
from numpy import zeros, empty, float32, float64, fromfile

# With the imports of the next three lines a memory error occurs
#import matplotlib
#matplotlib.use(AGG) 
#import matplotlib.pylab as plt 

_filename = mt.dat

if (path.exists(_filename)==False):
print Write file ...
_mtf = file(_filename, wb)
_mtd = zeros( (300,300,300,4),dtype=float64)
_mtd.tofile(_mtf)
_mtf.close()

_mtd = empty((0))
gc.collect();

print Try to read file ...

_mtf = file(_filename, rb)
# The memory error occurs with the type conversion to float 64, 
# but only if mathplotlib is imported! 
_mtd = fromfile(_mtf,float64).astype(float32)
_mtf.close()

print Successful read:,_mtd.shape

# Here some plot stuff would be :) 
***

If the import of matplotlib is not included, no error occures otherwise it
will not work. Perhaps anybody can help me (I tested it only on a Windows XP
32Bit).

 Best regards and thank you
  Stefan
-- 
View this message in context: 
http://old.nabble.com/MemoryError-with-import-matplotlib-tp30674798p30674798.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] colorbar with Axes3D for a set of collections?

2011-01-14 Thread Eric Firing

On 01/14/2011 02:02 AM, Daniel Mader wrote:

Hi Eric,

thanks for your feedback, it helped a lot! I have some questions left,
see below.

2011/1/14 Eric Firingefir...@hawaii.edu:

Quick thoughts with no testing or concrete examples:

1) Don't set the cmap or norm for the colorbar; let it inherit those
properties from the mappable to which it is connected.


Am I doing this correctly in the attached code? It seems there are
several ways of doing this... Which is the suggested one? How can I
label the colorbar?


The way you did it is fine. For the label, modify by keeping a reference 
to the colorbar and then calling set_label:


cb = fig.colorbar(collist[-1], shrink=0.85,)#, aspect=5)
cb.set_label('whatever this is')





2) Ensure that the cmap and norm are the same for all collections.  You
are already taking care of the cmap, so the problem is that you are
autoscaling the collections separately, which is setting vmin and vmax
to different values for the different collections.  Use the data to
figure out the range (vmin, vmax) that you want the colors to span, and
then for each collection, instead of col.autoscale(), use

col.norm.vmin = vmin
col.norm.vmax = vmax


That was what I needed, see code :)


(You could also make a single norm instance for all the collections to
use, just as with the cmap, so that you only have to set vmin and vmax
once.)


And this I don't understandm could you please elaborate?


See attached modification.

Eric



Thanks a very lot in advance
best regards from Austria,

Daniel


import sys
import scipy,pylab
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D

##--
def closePolys(elements):
  '''
  close the open polygon elements by adding the first node of each poly again.
  '''
  closed = []
  for nodes in elements:
i = nodes[0]
ii = list(nodes)
ii.append(i)
closed.append(ii)
  return closed

elements = [ [ (0,0), (0,1), (1,1), (1,0) ],
  [ (4,1), (2,3), (2,2), (3,1)],
  [ (0,1), (2,3), (2,2), (1,1)],
  [ (3,0), (3,1), (4,1), (4,0)]]
tmp = scipy.array([1,1.1,0.9,1])
data = [tmp, tmp*2, tmp*4]

## workaround for bug in mpl: close polys manually, no auto-closing!
polys = closePolys(elements)

##--
fig = pylab.figure()
ax = Axes3D(fig)

stacks = 3
zpos = scipy.arange(stacks)

vmin,vmax = scipy.amin(data), scipy.amax(data)
norm = mpl.colors.Normalize(vmin=vmin, vmax=vmax)
cmap = mpl.cm.cool

collist = []
for i in range(stacks):
  col = mpl.collections.PolyCollection(polys, linewidths=0.05, closed=False,
norm=norm, cmap=cmap)
  col.set_array(data[i])
  collist.append(col)


for i,col in enumerate(collist):
  ## get number of elements per collection
  elemno = len(col.get_paths())
  ## create *iterable* for the 3D collection slices [z,z,z,...,z]
  zs = [zpos[i]]*elemno
  ## collection transparency (opaque == 1), needed for projection bug workaround
  col.set_alpha(0.3)

  ax.add_collection3d(col, zs=zs, zdir='y')
  #pylab.draw()

## colorbar:

cb = fig.colorbar(collist[-1], shrink=0.85,)#, aspect=5)
cb.set_label('whatever this is')


## axis limit settings:
ax.set_xlim3d(0,4)
ax.set_zlim3d(0,3)
ax.set_ylim3d(-0.1,stacks-1+0.1)

## labels:
ax.set_title('Transparency workaround')
ax.set_xlabel('x')
ax.set_ylabel('slice')
ax.set_zlabel('y')

##--
pylab.show()
--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] MemoryError with import matplotlib

2011-01-14 Thread Christoph Gohlke
Works for me on Windows 7 64 bit with 32 bit Python. I believe you 
simply run out of memory. On a 32 bit Windows OS, Python can only use 2 
GB, which it has to share with other all processes. 
zeros((300,300,300,4),dtype=float64) requires ~820MB of contiguous 
memory, which might not be available even if you have 1 GB free RAM. 
Better use a 64 bit OS and Python.

Christoph

On 1/14/2011 11:40 AM, sprobst wrote:

 Hi all,

 I tried to plot parts of a large 3D array with each 4 float64 entries.
 Loading the array with numpy.fromfile and performing a type conversion
 afterwards ends up in a MemoryError.

 The following code reproduces the error:
 ***
 import gc

 from os import path
 from numpy import zeros, empty, float32, float64, fromfile

 # With the imports of the next three lines a memory error occurs
 #import matplotlib
 #matplotlib.use(AGG)
 #import matplotlib.pylab as plt

 _filename = mt.dat

 if (path.exists(_filename)==False):
   print Write file ...
   _mtf = file(_filename, wb)
   _mtd = zeros( (300,300,300,4),dtype=float64)
   _mtd.tofile(_mtf)
   _mtf.close()
   
   _mtd = empty((0))
   gc.collect();

 print Try to read file ...

 _mtf = file(_filename, rb)
 # The memory error occurs with the type conversion to float 64,
 # but only if mathplotlib is imported!
 _mtd = fromfile(_mtf,float64).astype(float32)
 _mtf.close()

 print Successful read:,_mtd.shape

 # Here some plot stuff would be :)
 ***

 If the import of matplotlib is not included, no error occures otherwise it
 will not work. Perhaps anybody can help me (I tested it only on a Windows XP
 32Bit).

   Best regards and thank you
Stefan

--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] MemoryError with import matplotlib

2011-01-14 Thread Benjamin Root
On Fri, Jan 14, 2011 at 1:40 PM, sprobst stefanpro...@gmx.net wrote:


 Hi all,

 I tried to plot parts of a large 3D array with each 4 float64 entries.
 Loading the array with numpy.fromfile and performing a type conversion
 afterwards ends up in a MemoryError.

 The following code reproduces the error:
 ***
 import gc

 from os import path
 from numpy import zeros, empty, float32, float64, fromfile

 # With the imports of the next three lines a memory error occurs
 #import matplotlib
 #matplotlib.use(AGG)
 #import matplotlib.pylab as plt

 _filename = mt.dat

 if (path.exists(_filename)==False):
print Write file ...
_mtf = file(_filename, wb)
_mtd = zeros( (300,300,300,4),dtype=float64)
_mtd.tofile(_mtf)
_mtf.close()

_mtd = empty((0))
gc.collect();

 print Try to read file ...

 _mtf = file(_filename, rb)
 # The memory error occurs with the type conversion to float 64,
 # but only if mathplotlib is imported!
 _mtd = fromfile(_mtf,float64).astype(float32)
 _mtf.close()

 print Successful read:,_mtd.shape

 # Here some plot stuff would be :)
 ***

 If the import of matplotlib is not included, no error occures otherwise it
 will not work. Perhaps anybody can help me (I tested it only on a Windows
 XP
 32Bit).

 Best regards and thank you
  Stefan



Stefan,

I don't know if it would make a difference, but I see that you are importing
matplotlib.pylab as plt.  This is not a typical way of importing
matplotlib.  Try instead:

import matplotlib.pyplot as plt

Ben Root
--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] MemoryError with import matplotlib

2011-01-14 Thread sprobst

Dear Christoph,

It is not a memory problem, because before the programm starts I have more
than 1.3 GB free memory left. And on the other hand it depends on the import
line! There seems to be some interference of the packages. My Python version
is 2.6 (needed by another programm), perhaps that also makes the difference.

But thank you for the quick answer!
  Stefan

-- 
View this message in context: 
http://old.nabble.com/MemoryError-with-import-matplotlib-tp30674798p30675089.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] MemoryError with import matplotlib

2011-01-14 Thread Christoph Gohlke
The zeros(...) statement needs a contiguous block of  800 MB RAM and 
the conversion another contiguous block of  400 MB. Memory allocated 
during the matplotlib import statement could easily fragment the 
available memory such that no 800 + 400 MB blocks exist. Try monitoring 
your memory usage and import matplotlib after allocating/converting the 
array. Anyway, you'll be better off using a 64 bit system if you deal 
with such amount of data.

Christoph

On 1/14/2011 12:17 PM, sprobst wrote:

 Dear Christoph,

 It is not a memory problem, because before the programm starts I have more
 than 1.3 GB free memory left. And on the other hand it depends on the import
 line! There seems to be some interference of the packages. My Python version
 is 2.6 (needed by another programm), perhaps that also makes the difference.

 But thank you for the quick answer!
Stefan


--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] colorbar with Axes3D for a set of collections?

2011-01-14 Thread Daniel Mader
Thank you very much for your patience, your explanations helped me a
very lot in getting beautiful plots for my thesis!
Best regards,
Daniel

--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] specgram with zeros array

2011-01-14 Thread Gus
I am using Matplotlib version 1.0.1 and I get errors if I try the following:

import matplotlib.pyplot as plt
import numpy as np
plt.specgram(np.zeros(50))

I have pasted the error output below, but hopefully it would reproduce 
in other systems. I'm not sure if this is intended behavior and was 
wondering. I came across this when I was plotting the specgram of my 
sound input, but my microphone was muted!

---
AttributeErrorTraceback (most recent call last)

/usr/local/lib/python2.6/dist-packages/matplotlib/backends/backend_wx.pyc in 
_onPaint(self, evt)
1192 drawDC = wx.PaintDC(self)
1193 if not self._isDrawn:
- 1194 self.draw(drawDC=drawDC)
1195 else:
1196 self.gui_repaint(drawDC=drawDC)

/usr/local/lib/python2.6/dist-packages/matplotlib/backends/backend_wxagg.pyc 
in draw(self, drawDC)
  57 
  58 DEBUG_MSG(draw(), 1, self)
--- 59 FigureCanvasAgg.draw(self)
  60
  61 self.bitmap = 
_convert_agg_to_wx_bitmap(self.get_renderer(), None)

/usr/local/lib/python2.6/dist-packages/matplotlib/backends/backend_agg.pyc 
in draw(self)
 392
 393 self.renderer = self.get_renderer()
-- 394 self.figure.draw(self.renderer)
 395
 396 def get_renderer(self):

/usr/local/lib/python2.6/dist-packages/matplotlib/artist.pyc in 
draw_wrapper(artist, renderer, *args, **kwargs)
  53 def draw_wrapper(artist, renderer, *args, **kwargs):
  54 before(artist, renderer)
--- 55 draw(artist, renderer, *args, **kwargs)
  56 after(artist, renderer)
  57

/usr/local/lib/python2.6/dist-packages/matplotlib/figure.pyc in 
draw(self, renderer)
 796 dsu.sort(key=itemgetter(0))
 797 for zorder, func, args in dsu:
-- 798 func(*args)
 799
 800 renderer.close_group('figure')

/usr/local/lib/python2.6/dist-packages/matplotlib/artist.pyc in 
draw_wrapper(artist, renderer, *args, **kwargs)
  53 def draw_wrapper(artist, renderer, *args, **kwargs):
  54 before(artist, renderer)
--- 55 draw(artist, renderer, *args, **kwargs)
  56 after(artist, renderer)
  57

/usr/local/lib/python2.6/dist-packages/matplotlib/axes.pyc in draw(self, 
renderer, inframe)
1944
1945 for zorder, a in dsu:
- 1946 a.draw(renderer)
1947
1948 renderer.close_group('axes')

/usr/local/lib/python2.6/dist-packages/matplotlib/artist.pyc in 
draw_wrapper(artist, renderer, *args, **kwargs)
  53 def draw_wrapper(artist, renderer, *args, **kwargs):
  54 before(artist, renderer)
--- 55 draw(artist, renderer, *args, **kwargs)
  56 after(artist, renderer)
  57

/usr/local/lib/python2.6/dist-packages/matplotlib/image.pyc in 
draw(self, renderer, *args, **kwargs)
 352 warnings.warn(Image will not be shown 
correctly with this backend.)
 353
-- 354 im = self.make_image(renderer.get_image_magnification())
 355 if im is None:
 356 return

/usr/local/lib/python2.6/dist-packages/matplotlib/image.pyc in 
make_image(self, magnification)
 567 im, xmin, ymin, dxintv, dyintv, sx, sy = \
 568 self._get_unsampled_image(self._A, [_x1, _x2, _y1, 
_y2],
-- 569   transformed_viewLim)
 570
 571 fc = self.axes.patch.get_facecolor()

/usr/local/lib/python2.6/dist-packages/matplotlib/image.pyc in 
_get_unsampled_image(self, A, image_extents, viewlim)
 199 else:
 200 if self._rgbacache is None:
-- 201 x = self.to_rgba(self._A, self._alpha)
 202 self._rgbacache = x
 203 else:

/usr/local/lib/python2.6/dist-packages/matplotlib/cm.pyc in 
to_rgba(self, x, alpha, bytes)
 191 pass
 192 x = ma.asarray(x)
-- 193 x = self.norm(x)
 194 x = self.cmap(x, alpha=alpha, bytes=bytes)
 195 return x

/usr/local/lib/python2.6/dist-packages/matplotlib/colors.pyc in 
__call__(self, value, clip)
 809 if vmin  vmax:
 810 raise ValueError(minvalue must be less than or 
equal to maxvalue)
-- 811 elif vmin==vmax:
 812 result = 0.0 * val
 813 else:

/usr/lib/python2.6/dist-packages/numpy/ma/core.pyc in __eq__(self, other)
3117 mask =  np.all([[f[n].all() for n in 
mask.dtype.names]
3118 for f in mask], axis=axis)
- 3119 check._mask = mask
3120 return check
3121 #


AttributeError: 'numpy.bool_' object has no attribute '_mask'



Re: [Matplotlib-users] MemoryError with import matplotlib

2011-01-14 Thread sprobst

Problem solved ... even as orginally C++ or Java programmer it is strange,
but a interpreted language makes it possible to obtain with an import at a
different position a complety different behaviour during run-time. 

I just putted the import of mathplotlib and pylab after the file reading and
after the type conversion and it works. :jumping:

Comment to just switch to another system with 64bit. Sometimes if your are
not admin of a machine, than it is hard to change the system ;-)

Thank you anyhow, based on your comments I found the solution. Do you
perhaps know if there is something like a memdefrag :-/?
Have a nice weekend
Stefan
-- 
View this message in context: 
http://old.nabble.com/MemoryError-with-import-matplotlib-tp30674798p30676114.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users