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: Tue, 26 May 2015 16:37:15 +0200 Message-ID: References: <87wq0qsy4o.fsf@alphaville.usersys.redhat.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1136012e15d1820516fd1006 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxFys-0003cg-Dn for emacs-orgmode@gnu.org; Tue, 26 May 2015 10:37:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YxFyn-00075f-Fl for emacs-orgmode@gnu.org; Tue, 26 May 2015 10:37:22 -0400 Received: from mail-wg0-x236.google.com ([2a00:1450:400c:c00::236]:35118) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxFyn-00075N-2d for emacs-orgmode@gnu.org; Tue, 26 May 2015 10:37:17 -0400 Received: by wgme6 with SMTP id e6so30664312wgm.2 for ; Tue, 26 May 2015 07:37:16 -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: Ken Mankoff Cc: Nick Dokos , "emacs-orgmode@gnu.org" --001a1136012e15d1820516fd1006 Content-Type: text/plain; charset=UTF-8 On Tue, May 26, 2015 at 4:02 PM, Ken Mankoff wrote: > > On 2015-05-26 at 09:26, Dror Atariah wrote: > >> #+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)) # 4 > >> plt.plot([1,3,2]) # 3 > >> plt.savefig('myfig.png') # 2 > >> 'myfig.png' # 1 > >> #+END_SRC > >> > >> #+RESULTS: > >> [[file:myfig.png]] > >> > > > > As I mentioned before, if I evaluate the second block as-is I get the > > error. However, if I comment out all the lines except #1 then the code > > returns the correct results block. Then, I started to add the numbered > > lines. Adding #2 and #3 still doesn't break the behavior. Once adding > line > > #4 the behavior breaks. Maybe this observation can be helpful? This > happens > > both when starting Emacs -Q or without -Q. > > > Still no solution but a few comments: > > 1) What you write here and on SE are not the same. Please cut-and-paste > because details matter. For example, the SE code has "import > matplotlib.pyplot" and then "plt.figure" but that code crashes because you > did not import "as plt" like you do here... > I see. Let's focus on the code posted in this thread and assume that the problem is not related to python mistakes. > > 2) It seems to be an echo issue. In my *with_matplotlib* buffer in Emacs, > I see: > > #+BEGIN_EXAMPLE > Python 2.7.9 |Anaconda 2.2.0 (x86_64)| (default, Dec 15 2014, 10:37:34) > [GCC 4.2.1 (Apple Inc. build 5577)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > Anaconda is brought to you by Continuum Analytics. > Please check out: http://continuum.io/thanks and https://binstar.org > >>> 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' > > open('/var/folders/bl/trcxdptd1_q4k6q5fdhvp2m00000gn/T/babel-52565cmH/python-525659vF', > 'w').write(str(_)) > 'org_babel_python_eoe' > >>> [] > >>> 'myfig.png' > >>> 'org_babel_python_eoe' > >>> > #+END_EXAMPLE > > Where you see everything printed twice. I notice that in addition, you have > > > r/folders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/py6499_X0''', 'exec')); > > at the top of your buffer, and I do not. I think the "exec" might be > causing everything to echo as it runs, so everything is printed 2x, and > that confuses Org, and it is not able to capture your filename. > This sounds like a promising hint. Where is this first line coming from? How can I disable this double printing or figure out why is happening? > > -k. > > -- Dror Atariah, Ph.D. de.linkedin.com/in/atariah --001a1136012e15d1820516fd1006 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Tue, May 26, 2015 at 4:02 PM, Ken Mankoff <mankoff@gmail.com>= ; wrote:

On 2015-05-26 at 09:26, Dror Atariah <drorata@gmail.com> wrote:
>> #+BEGIN_SRC python :session with_matplotlib :results file :exports= both
>> import matplotlib
>> matplotlib.use('Agg')
>> import matplotlib.pyplot as plt
>> fig=3Dplt.figure(figsize=3D(3,2))=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 # 4
>> plt.plot([1,3,2])=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # 3
>> plt.savefig('myfig.png')=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 # 2
>> 'myfig.png'=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0# 1
>> #+END_SRC
>>
>> #+RESULTS:
>> [[file:myfig.png]]
>>
>
> As I mentioned before, if I evaluate the second block as-is I get the<= br> > error. However, if I comment out all the lines except #1 then the code=
> returns the correct results block. Then, I started to add the numbered=
> lines. Adding #2 and #3 still doesn't break the behavior. Once add= ing line
> #4 the behavior breaks. Maybe this observation can be helpful? This ha= ppens
> both when starting Emacs -Q or without -Q.


Still no solution but a few comments:

1) What you write here and on SE are not the same. Please cut-and-paste bec= ause details matter. For example, the SE code has "import matplotlib.p= yplot" and then "plt.figure" but that code crashes because y= ou did not import "as plt" like you do here...
I see. Let's focus on the code posted in this thread and assume that= the problem is not related to python mistakes.
=C2=A0

2) It seems to be an echo issue. In my *with_matplotlib* buffer in Emacs, I= see:

#+BEGIN_EXAMPLE
Python 2.7.9 |Anaconda 2.2.0 (x86_64)| (default, Dec 15 2014, 10:37:34)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credit= s" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: = http://continuum.io/thanks and https://binstar.org
>>> import matplotlib
>>> matplotlib.use('Agg')
>>> import matplotlib.pyplot as plt
fig=3Dplt.figure(figsize=3D(3,2))
plt.plot([1,3,2])

plt.savefig('myfig.png')
'myfig.png'

open('/var/folders/bl/trcxdptd1_q4k6q5fdhvp2m00000gn/T/babel-525= 65cmH/python-525659vF', 'w').write(str(_))
'org_babel_python_eoe'
>>> [<matplotlib.lines.Line2D object at 0x10454dd10>]
>>> 'myfig.png'
>>> 'org_babel_python_eoe'
>>>
#+END_EXAMPLE

Where you see everything printed twice. I notice that in addition, you have=

> r/folders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/py6499_X0'''= , 'exec'));

at the top of your buffer, and I do not. I think the "exec" might= be causing everything to echo as it runs, so everything is printed 2x, and= that confuses Org, and it is not able to capture your filename.
This sounds like a promising hint. Where is this first line comi= ng from? How can I disable this double printing or figure out why is happen= ing?

=C2=A0

=C2=A0 -k.




--
Dror Atariah, Ph.D.
<= a href=3D"http://de.linkedin.com/in/atariah" target=3D"_blank">de.linkedin.= com/in/atariah
--001a1136012e15d1820516fd1006--