From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dror Atariah Subject: Re: [Orgmode] Unable to capture the file name generated using matplotlib Date: Mon, 25 May 2015 19:25:15 +0200 Message-ID: References: <87wq0qsy4o.fsf@alphaville.usersys.redhat.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e01175e8704ca9e0516eb4b6f Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39970) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yww7q-0003zG-NE for emacs-orgmode@gnu.org; Mon, 25 May 2015 13:25:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yww7o-0006Pi-UN for emacs-orgmode@gnu.org; Mon, 25 May 2015 13:25:18 -0400 Received: from mail-wi0-x22c.google.com ([2a00:1450:400c:c05::22c]:32841) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yww7o-0006PY-Jj for emacs-orgmode@gnu.org; Mon, 25 May 2015 13:25:16 -0400 Received: by wicmx19 with SMTP id mx19so45215370wic.0 for ; Mon, 25 May 2015 10:25:15 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nick Dokos Cc: "emacs-orgmode@gnu.org" --089e01175e8704ca9e0516eb4b6f Content-Type: text/plain; charset=UTF-8 I am sorry for reposting, but I'm still in the dark. Am I the only one who experience this kind of issue? Did someone managed to reproduce the problem? Does anyone see this message? :) On Sat, May 23, 2015 at 8:49 PM, Dror Atariah wrote: > I am still helpless here. Any idea how to debug the problem? I would be > happy to provide any kind of help, but I just cannot do it myself. > > Further findings: > 1) I don't think that matplotlib changes Python's '_', since the tmp file > that contains the content of '_' is correct. > 2) Somehow, emacs/orgmode fails to extract the filename. > 3) It doesn't work also when using emacs 24.5 and orgmode 8.2.10. > > > Following is an org file that tries to summarize the issue: > > #+TITLE: Integrate matplotlib figures in an org mode buffer > * Goal > The ultimate goal is to use org-babel as a replacement of IPython. The > first motivation is to enable an easier version controling of the > document. The first challenge I faced is integration of plots returned > by ~matplotlib~ in the org buffer. > * Capturing filename > > I would like to use (babel) orgmode as an interactive python > notebook. Therefore, in order to allow the various code blocks to > "know" each other, it is important to use the ~:session~ > option. However, once ~:session~ is used, together with ~matplotlib~ > the desired behavior is no longer in place. > > * Clean testing, no Matplotlib > For the sake of testing, the following merely suppose to return the > filename > > #+BEGIN_SRC python :session no_matplotlib :results file :exports both > x = 'hello ' > y = 'world' > z = x + y > 'foo.bar' > #+END_SRC > > #+RESULTS: > [[file:foo.bar]] > > *Passed* Indeed, the ~RESULTS~ block contains a link to the filename > indicated by the last string. > > * Importing Matplotlib > > The following minimal example should generate a simple figure, > ~myfig.png~, and orgmode should capture it and interpret it as a > filename to be used by the following ~RESULTS~ block. > > #+BEGIN_SRC python :session with_matplotlib :results file :exports both > import matplotlib > matplotlib.use('Agg') > import matplotlib.pyplot as plt > fig=plt.figure(figsize=(3,2)) > plt.plot([1,3,2]) > plt.savefig('myfig.png') > 'myfig.png' > #+END_SRC > > #+RESULTS: > [[file:]] > > *Failed!* This time, it doesn't work anymore. The file ~myfig.png~ is > properly generated, but the last string is not captured by > ~matplotlib~. Following is the content of the corresponding > interactive python session: > > #+BEGIN_SRC > Process with_matplotlib finished > Python 3.4.3 (default, Mar 10 2015, 14:53:35) > [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> >>> >>> , > '''/var/folders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/py32771xVI''', 'exec')); > import matplotlib > >>> import matplotlib > matplotlib.use('Agg') > matplotlib.use('Agg') > import matplotlib.pyplot as plt > import matplotlib.pyplot as plt > fig=plt.figure(figsize=(3,2)) > fig=plt.figure(figsize=(3,2)) > plt.plot([1,3,2]) > plt.plot([1,3,2]) > plt.savefig('myfig.png') > plt.savefig('myfig.png') > 'myfig.png' > 'myfig.png' > > > open('/var/folders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/babel-32771x4j/python-32771-fO', > 'w').write(str(_)) > open('/var/folders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/babel-32771x4j/python-32771-fO', > 'w').write(str(_)) > > > > > 'org_babel_python_eoe' > 'org_babel_python_eoe' > >>> [] > >>> 'myfig.png' > >>> >>> 9 > >>> >>> >>> 'org_babel_python_eoe' > >>> > #+END_SRC > > * Some background > > ** Python Version > #+BEGIN_SRC python :session background :results raw > import sys > sys.version > #+END_SRC > > #+RESULTS: > 3.4.3 (default, Mar 10 2015, 14:53:35) > [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] > > ** Matplotlib version > #+BEGIN_SRC python :session background :results raw > import matplotlib > matplotlib.__version__ > #+END_SRC > > #+RESULTS: > 1.4.3 > > ** System > I am running Emacs version ~GNU Emacs 24.5.1 (x86_64-apple-darwin14.1.0, > NS apple-appkit-1344.72) of 2015-04-19 on tenten-slave.macports.org~ > > The orgmode version is: ~Org-mode version 8.2.10 > (8.2.10-40-gc763fa-elpaplus @ > /Users/drorata/.emacs.d/elpa/org-plus-contrib-20150518/)~ > > ** Stackoverflow reference > I also posted a question in the SE network: > [[ > http://emacs.stackexchange.com/questions/11075/org-mode-python-session-does-not-return-a-file-name > ]] > > * Question > So, my question is how to tackle/debug this issue? Can someone give me > a hand here? That would be really great! Thanks! > > -- Dror Atariah, Ph.D. de.linkedin.com/in/atariah --089e01175e8704ca9e0516eb4b6f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I am sorry for reposting, but I'm still in the dark. A= m I the only one who experience this kind of issue? Did someone managed to = reproduce the problem? Does anyone see this message? :)

On Sat, May 23, 2015 at 8:49 PM, Dror= Atariah <drorata@gmail.com> wrote:
I am still helpless here. Any idea how to debug= the problem? I would be happy to provide any kind of help, but I just cann= ot do it myself.

Further findings:
1) I don= 9;t think that matplotlib changes Python's '_', since the tmp f= ile that contains the content of '_' is correct.
2) Someh= ow, emacs/orgmode fails to extract the filename.
3) It doesn'= t work also when using emacs 24.5 and orgmode 8.2.10.

<= div>
Following is an org file= that tries to summarize the issue:

#+TITLE: = Integrate matplotlib figures in an org mode buffer
* Goal
The ultimate goal is to use org-babel as a replacement of IPython. The
first motivation is to enable an easier version controling of the<= /div>
document. The first challenge I faced is integration of plots ret= urned
by ~matplotlib~ in the org buffer.
* Capturing fi= lename

I would like to use (babel) orgmode as an i= nteractive python
notebook. Therefore, in order to allow the vari= ous code blocks to
"know" each other, it is important t= o use the ~:session~
option. However, once ~:session~ is used, to= gether with ~matplotlib~
the desired behavior is no longer in pla= ce.

* Clean testing, no Matplotlib
For t= he sake of testing, the following merely suppose to return the filename

#+BEGIN_SRC python :session no_matplotlib :results fi= le :exports both
x =3D 'hello '
y =3D 'worl= d'
z =3D x + y
'foo.bar'
#+END_SR= C

#+RESULTS:
[[file:foo.bar]]
=
*Passed* Indeed, the ~RESULTS~ block contains a link to the = filename
indicated by the last string.

*= Importing Matplotlib

The following minimal exampl= e should generate a simple figure,
~myfig.png~, and orgmode shoul= d capture it and interpret it as a
filename to be used by the fol= lowing ~RESULTS~ block.

#+BEGIN_SRC python :sessio= n with_matplotlib :results file :exports both
im= port matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fig=3Dplt.figure(f= igsize=3D(3,2))
plt.plot([1,3,2])
plt.savefig(&#= 39;myfig.png')
'myfig.png'
#+END_SRC
<= div>
#+RESULTS:
[[file:]]

= *Failed!* This time, it doesn't work anymore. The file ~myfig.png~ is
=C2=A0properly generated, but the last string is not captured by
=C2=A0~matplotlib~. Following is the content of the corresponding<= /div>
=C2=A0interactive python session:

#+BEGI= N_SRC
Process with_matplotlib finished
Python 3.4.3 (de= fault, Mar 10 2015, 14:53:35)
[GCC 4.2.1 Compatible Apple LLVM 6.= 0 (clang-600.0.56)] on darwin
Type "help", "copyri= ght", "credits" or "license" for more information.=
>>> >>> >>> , '''/var/fol= ders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/py32771xVI''', 'ex= ec'));
import matplotlib
>>&= gt; import matplotlib
matplotlib.use('Agg')
mat= plotlib.use('Agg')
import matplotlib.pyplot as plt
<= div>import matplotlib.pyplot as plt
fig=3Dplt.figure(figsize=3D(3= ,2))
fig=3Dplt.figure(figsize=3D(3,2))
plt.plot([1,3,2]= )
plt.plot([1,3,2])
plt.savefig('myfig.png&#= 39;)
plt.savefig('myfig.png')
'myfig.png= 9;
'myfig.png'


op= en('/var/folders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/babel-32771x4j/pyt= hon-32771-fO', 'w').write(str(_))
open('/var/fold= ers/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/babel-32771x4j/python-32771-fO'= , 'w').write(str(_))




'org_babel_python_eoe'
'org_b= abel_python_eoe'
>>> [<matplotlib.lines.Line2D ob= ject at 0x108e01828>]
>>> 'myfig.png'
>>> >>> 9
>>> >>> >>= > 'org_babel_python_eoe'
>>>
#+END_= SRC

* Some background

** = Python Version
#+BEGIN_SRC python :session background :results ra= w
import sys
sys.version
#+END_SRC
=
#+RESULTS:
3.4.3 (default, Mar 10 2015, 14:53:35)<= /div>
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)]
=
** Matplotlib version
#+BEGIN_SRC python :session = background :results raw
import matplotlib
matplotlib.__= version__
#+END_SRC

#+RESULTS:
1.4.3

** System
I am running Emacs vers= ion ~GNU Emacs 24.5.1 (x86_64-apple-darwin14.1.0, NS apple-appkit-1344.72) = of 2015-04-19 on tenten-slave.macports.org~

The orgmode ve= rsion is: ~Org-mode version 8.2.10 (8.2.10-40-gc763fa-elpaplus @ /Users/dro= rata/.emacs.d/elpa/org-plus-contrib-20150518/)~

**= Stackoverflow reference
I also posted a question in the SE netwo= rk:

* Question
So, = my question is how to tackle/debug this issue? Can someone give me
a hand here? That would be really great! Thanks!




--
Dror Atariah, Ph.D.
--089e01175e8704ca9e0516eb4b6f--