Re: [matplotlib-devel] imsave function

2009-02-08 Thread Gary Ruben
Thanks for the quick test and comments Andrew. I've made your suggested 
changes and attached a new patch.


Gary

Andrew Straw wrote:

Hi Gary, I have a couple comments:

1) No need for:

+ax = fig.add_subplot(111)
+ax.set_axis_off()

2) It's probably best to have maximum compatibility with imshow().
Therefore, use vmin=None and vmax=None as keyword arguments (rather than
clims).

Otherwise, I tested and it works for me.

-Andrew


Index: matplotlib/CHANGELOG
===
--- matplotlib/CHANGELOG(revision 6889)
+++ matplotlib/CHANGELOG(working copy)
@@ -1,3 +1,6 @@
+2009-02-08 Added a new imsave function to image.py and exposed it in
+   the pyplot interface - GR
+
 2009-02-04 Some reorgnization of the legend code. anchored_text.py
added as an example. - JJL
 
Index: matplotlib/doc/_templates/index.html
===
--- matplotlib/doc/_templates/index.html(revision 6889)
+++ matplotlib/doc/_templates/index.html(working copy)
@@ -567,6 +567,17 @@
 
 
   
+imsave
+
+  
+
+  
+save array as an image file
+  
+
+
+
+  
 imshow
 
   
Index: matplotlib/doc/api/api_changes.rst
===
--- matplotlib/doc/api/api_changes.rst  (revision 6889)
+++ matplotlib/doc/api/api_changes.rst  (working copy)
@@ -19,6 +19,9 @@
 
 Changes for 0.98.x
 ==
+* Added new :func:`matplotlib.image.imsave` and exposed it to the
+  :mod:`matplotlib.pyplot` interface.
+
 * Remove support for pyExcelerator in exceltools -- use xlwt
   instead 
 
Index: matplotlib/lib/matplotlib/pyplot.py
===
--- matplotlib/lib/matplotlib/pyplot.py (revision 6889)
+++ matplotlib/lib/matplotlib/pyplot.py (working copy)
@@ -6,6 +6,7 @@
 from matplotlib.figure import Figure, figaspect
 from matplotlib.backend_bases import FigureCanvasBase
 from matplotlib.image import imread as _imread
+from matplotlib.image import imsave as _imsave
 from matplotlib import rcParams, rcParamsDefault, get_backend
 from matplotlib.rcsetup import interactive_bk as _interactive_bk
 from matplotlib.artist import getp, get, Artist
@@ -1181,6 +1182,7 @@
 legend  add a legend to the axes
 loglog  a log log plot
 imread  load image file into array
+imsave  save array as an image file
 imshow  plot image data
 matshow display a matrix in a new figure preserving aspect
 pcolor  make a pseudocolor plot
@@ -1230,7 +1232,7 @@
 def get_plot_commands(): return ( 'axes', 'axis', 'bar', 'boxplot', 'cla', 
'clf',
 'close', 'colorbar', 'cohere', 'csd', 'draw', 'errorbar',
 'figlegend', 'figtext', 'figimage', 'figure', 'fill', 'gca',
-'gcf', 'gci', 'get', 'gray', 'barh', 'jet', 'hist', 'hold', 'imread',
+'gcf', 'gci', 'get', 'gray', 'barh', 'jet', 'hist', 'hold', 'imread', 
'imsave',
 'imshow', 'legend', 'loglog', 'quiver', 'rc', 'pcolor', 'pcolormesh', 
'plot', 'psd',
 'savefig', 'scatter', 'set', 'semilogx', 'semilogy', 'show',
 'specgram', 'stem', 'subplot', 'table', 'text', 'title', 'xlabel',
@@ -1370,6 +1372,11 @@
 if _imread.__doc__ is not None:
 imread.__doc__ = dedent(_imread.__doc__)
 
+def imsave(*args, **kwargs):
+return _imsave(*args, **kwargs)
+if _imsave.__doc__ is not None:
+imsave.__doc__ = dedent(_imsave.__doc__)
+
 def matshow(A, fignum=None, **kw):
 """
 Display an array as a matrix in a new figure window.
Index: matplotlib/lib/matplotlib/pylab.py
===
--- matplotlib/lib/matplotlib/pylab.py  (revision 6889)
+++ matplotlib/lib/matplotlib/pylab.py  (working copy)
@@ -50,6 +50,7 @@
   ion  - turn interaction mode on
   isinteractive - return True if interaction mode is on
   imread   - load image file into array
+  imsave   - save array as an image file
   imshow   - plot image data
   ishold   - return the hold state of the current axes
   legend   - make an axes legend
Index: matplotlib/lib/matplotlib/image.py
===
--- matplotlib/lib/matplotlib/image.py  (revision 6889)
+++ matplotlib/lib/matplotlib/image.py  (working copy)
@@ -747,7 +747,43 @@
 return handler(fname)
 
 
+def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None, 
origin=None):
+"""
+Saves a 2D :class:`numpy.array` as an image with one pixel per element.
+The output formats available depend on the backend being used.
 
+Arguments:
+  *fname*:
+A string containing a path to a filename, or a Python file-like object.
+If *format* is *None* and *fname* is a string, the output
+format is deduced from the extension of the filename.
+  *

[matplotlib-devel] plot directive in reST tutorials

2009-02-08 Thread Fernando Perez
Howdy,

recently, Matthew Brett pointed out that reST supports a mode that's
very handy for writing tutorial-like documents that contain code
blocks including their output, and they can even be run as tests.
Here's a simple example with its corresponding source:

http://neuroimaging.scipy.org/site/doc/manual/html/users/analysis_pipeline.html
http://neuroimaging.scipy.org/site/doc/manual/html/_sources/users/analysis_pipeline.txt

and they can even use the MPL math support, as seen here:

http://neuroimaging.scipy.org/site/doc/manual/html/users/glm_spec.html
http://neuroimaging.scipy.org/site/doc/manual/html/_sources/users/glm_spec.txt

But we were thinking it would be great to have also plot support for
this, without being forced to use standalone scripts like in mpl's
current form of the plot directive.  I unfortunately have to go now
and will be mostly offline for a week, but I just had a chat about
this with John, so I want to leave some context in here in case this
is of interest to you guys.  If there's a discussion on the API, I'll
do my best to keep up, but I'm also cc'ing the nipy list so those
interested can pitch in (though we should keep the conversation to the
MPL list, where the plot machinery is implemented).

Cheers,

f

--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] Fwd: [sage-devel] Re: Massively collaborative mathematics + Sage-ready blogs and forums

2009-02-08 Thread Fernando Perez
Interesting: gnuplot rendered in HTML5.  It would be interesting to
see this in mpl...


-- Forwarded message --
From: Pat LeSmithe 
Date: Sun, Feb 8, 2009 at 3:44 AM
Subject: [sage-devel] Re: Massively collaborative mathematics +
Sage-ready blogs and forums
To: sage-de...@googlegroups.com



William Stein wrote:
> I just want to point out that the above *is* what the 3d plotting in
> Sage currently does.
>
> Doing something similar for 2d plots would be great.

I just stumbled upon this announcement for a HTML5 'canvas' driver for
gnuplot:

http://www.nabble.com/New-terminal-driver%3Aset-term-canvas-tc21364389.html

The demos are at:

http://skuld.bmsc.washington.edu/~merritt/gnuplot/canvas_demos/


--~--~-~--~~~---~--~~
To post to this group, send email to sage-de...@googlegroups.com
To unsubscribe from this group, send email to
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---

--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] Interactive wx/pylab with no threads (PyOS_InputHook)

2009-02-08 Thread Brian Granger
IPython and matplotlib devs,

Over the weekend I have been playing around to see if it is possible
to do interactive GUI work with wx from IPython *without using
threads*.  The idea here is to use PyOS_InputHook.  Currently, recent
versions of PyQt4 and PyGTK do this and if we can get wx working, we
can probably get rid of IPython's subtle threaded shells that
currently allow interactive GUIs to work.

I am attaching a Cython module that mostly works.  Here is a simple
example that works in IPython (without the -wthread option!)

In [1]: import pyximport

In [2]: pyximport.install()

In [3]: import inputhook

In [4]: inputhook.set_input_hook()

In [5]: import wx

In [6]: app = wx.PySimpleApp()

In [7]: app.MainLoop()

In [8]: f = wx.Frame(None,-1,"Look mom, no threads!")

In [9]: f.Show()
Out[9]: True

The docstring of the module also has a matplotlib example.  This
really does work and I am pretty sure it will also work in plain
vanilla python as well.  There are a few issues to work out:

* When frame are closed by clicking the red button or the "X", the
Windows don't close.  In addition, in matplotlib, this causes further
problems.

* In the current matplotlib backend wx.Yield() is called in a way that
is not safe as far as protecting against recursive calls to Yield.  I
think it should be called in this way:

app = wx.GetApp()
if app is not None:
  app.Yield(True)

* I don't think that interupts work yet, but I haven't tested this
thoroughly yet.

I don't have any more time to work on this right now, but I at least
wanted to share my findings with both IPython and matplotlib devs.  It
would be great if someone familiar with wx could try to figure out the
remaining issues.  If there are no takers here, I might eventually see
if wxpython itself is interested in this code (that is probably where
it really belongs anyway).

Cheers,

Brian
#include 

static PyThreadState *event_tstate = NULL;

static void set_input_hook_c(int (*f)(void))
{
event_tstate = PyThreadState_Get();
PyOS_InputHook = f;
}

static void clear_input_hook_c(void)
{
PyOS_InputHook = NULL;
}

inputhook.pyx
Description: Binary data
--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Interactive wx/pylab with no threads (PyOS_InputHook)

2009-02-08 Thread Gael Varoquaux
On Sun, Feb 08, 2009 at 04:08:31PM -0800, Brian Granger wrote:
> * In the current matplotlib backend wx.Yield() is called in a way that
> is not safe as far as protecting against recursive calls to Yield.  I
> think it should be called in this way:

> app = wx.GetApp()
> if app is not None:
>   app.Yield(True)

The problem I see with this approach is that arbitrary wx programs will
always be doing this. The matplotlib guys can fix matplotib not to do
this. I can fix Mayavi not to do this, but there are many more wx
programs. And anyhow, most of the time, Yield should not be called, as it
is a hack. Unfortunately, you often end up having to call it. :(

Gaƫl

--
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel