Re: [O] python/babel inline images
-Original Message- From: henry atting [mailto:nsmp...@online.de] Sent: Thursday, June 07, 2012 3:43 AM To: Mikhail Titov Cc: 'henry atting'; emacs-orgmode@gnu.org Subject: Re: python/babel inline images The code itself works flawlessly. So the workaround which I already have used is to link to the resulting image. The only drawback with this solution is that after every evaluation I have to remove the empty `'Results:' You can use :results silent This is great! Actually this solves my problem which means: create a link to the file and set results to silent. This has an implication of inability to cache results in case you might want it. I personally would just leave empty #+RESULTS: block as is and I would place link manually two lines below it (leave 1 blank line so re-evaluation won't delete your link). but the heck with it, I can live with it happily till the end of my days. However I find that some inconsistency lies therein. Before python/matplotlib I used gnuplot with which babel had no problem of this type. Try using ... :file exp_csv.svg ... plot.savefig(file=sys.stdout) This does not compile, the compiler complains about missing arguments. I have to write it like this: plot.savefig(file.svg, format='svg') I never used that library but it makes sense:-) The only problem with this solution that you should make sure nothing else goes to stdout. I think it is a huge shortcoming. So, just to mention the current state of affairs (with a simple example): --8---cut here---start-8--- #+begin_src python :results output from pylab import * t = arange(0.0, 2.0, 0.01) s = sin(2*pi*t) plot(t, s) show() savefig(file.svg, format='svg') #+end_src --8---cut here---start-8--- The above code works. But if I set `:file' to `file.svg' with every evaluation the link to the file is placed after #+RESULTS: but the file itself is empty. As William LECHELLE pointed out that in this case file captures the output of the savefig() call which does not output anything to stdout. So it is expected. If the code is evaluated without `:file file.svg' the evaluation simply works and the file.svg appears in the working directory. I think this is the best way to proceed. M.
Re: [O] python/babel inline images
Mikhail Titov m...@gmx.us writes: -Original Message- From: emacs-orgmode-bounces+mlt=gmx...@gnu.org [mailto:emacs-orgmode- bounces+mlt=gmx...@gnu.org] On Behalf Of henry atting Sent: Wednesday, June 06, 2012 10:19 AM To: emacs-orgmode@gnu.org Subject: Re: [O] python/babel inline images I don't think its a path problem. Indeed #+begin_src python :results output import os print(os.getcwd()) #+end_src Shows location of my org doc. Yes, shows my working directory. The code itself works flawlessly. So the workaround which I already have used is to link to the resulting image. The only drawback with this solution is that after every evaluation I have to remove the empty `'Results:' You can use :results silent This is great! Actually this solves my problem which means: create a link to the file and set results to silent. but the heck with it, I can live with it happily till the end of my days. However I find that some inconsistency lies therein. Before python/matplotlib I used gnuplot with which babel had no problem of this type. Try using ... :file exp_csv.svg ... plot.savefig(file=sys.stdout) This does not compile, the compiler complains about missing arguments. I have to write it like this: plot.savefig(file.svg, format='svg') #+begin_src python :results output :file zzz.xxx import os, sys print(os.getcwd(), file=sys.stdout) #+end_src #+RESULTS: [[file:zzz.xxx]] Works as exspected. [...] So, just to mention the current state of affairs (with a simple example): --8---cut here---start-8--- #+begin_src python :results output from pylab import * t = arange(0.0, 2.0, 0.01) s = sin(2*pi*t) plot(t, s) show() savefig(file.svg, format='svg') #+end_src --8---cut here---start-8--- The above code works. But if I set `:file' to `file.svg' with every evaluation the link to the file is placed after #+RESULTS: but the file itself is empty. If the code is evaluated without `:file file.svg' the evaluation simply works and the file.svg appears in the working directory. henry -- http://literaturlatenight.de
Re: [O] python/babel inline images
I don't think its a path problem. The code itself works flawlessly. So the workaround which I already have used is to link to the resulting image. The only drawback with this solution is that after every evaluation I have to remove the empty `'Results:' but the heck with it, I can live with it happily till the end of my days. However I find that some inconsistency lies therein. Before python/matplotlib I used gnuplot with which babel had no problem of this type. Cheers, henry -- http://literaturlatenight.de
Re: [O] python/babel inline images
Mikhail Titov m...@gmx.us writes: -Original Message- From: emacs-orgmode-bounces+mlt=gmx...@gnu.org [mailto:emacs-orgmode- bounces+mlt=gmx...@gnu.org] On Behalf Of Eric Schulte Sent: Tuesday, June 05, 2012 9:57 AM To: henry atting Cc: emacs-orgmode@gnu.org Subject: Re: [O] python/babel inline images I'm not python expert, but the code block should be run in your current directory, e.g., the following outputs the current working path expected for me. #+begin_src sh pwd #+end_src If you want to explicitly pass the current directory to your code block as an argument, you could try something like the following #+begin_src python :var mydir=(file-name-directory (buffer-file-name)) return mydir #+end_src I've noticed some inconsistency between various languages in this aspect. For instance, ob-R starts session in proper working directory, while all looks like everything (?) else does not. Should not it be somewhat standardized? I think it make sense to always cd to org doc folder. Most languages should and (at least those I use regularly) do run in the directory of the containing Org-mode file. Which languages do not? Thanks, -- Eric Schulte http://cs.unm.edu/~eschulte
Re: [O] python/babel inline images
-Original Message- From: emacs-orgmode-bounces+mlt=gmx...@gnu.org [mailto:emacs-orgmode- bounces+mlt=gmx...@gnu.org] On Behalf Of henry atting Sent: Wednesday, June 06, 2012 10:19 AM To: emacs-orgmode@gnu.org Subject: Re: [O] python/babel inline images I don't think its a path problem. Indeed #+begin_src python :results output import os print(os.getcwd()) #+end_src Shows location of my org doc. The code itself works flawlessly. So the workaround which I already have used is to link to the resulting image. The only drawback with this solution is that after every evaluation I have to remove the empty `'Results:' You can use :results silent but the heck with it, I can live with it happily till the end of my days. However I find that some inconsistency lies therein. Before python/matplotlib I used gnuplot with which babel had no problem of this type. Try using ... :file exp_csv.svg ... plot.savefig(file=sys.stdout) #+begin_src python :results output :file zzz.xxx import os, sys print(os.getcwd(), file=sys.stdout) #+end_src #+RESULTS: [[file:zzz.xxx]] Meanwhile I've noticed that I can't return back from editing python code in a sub-editing buffer. C-c ' does not work and M-x org-edit-src-exit says This is not a sub-editing buffer, something is wrong.
Re: [O] python/babel inline images
Mikhail Titov m...@gmx.us writes: Meanwhile I've noticed that I can't return back from editing python code in a sub-editing buffer. C-c ' does not work and M-x org-edit-src-exit says This is not a sub-editing buffer, something is wrong. This works on my system, perhaps the problem is due to something in your configuration. Do you still notice this problem when launching emacs with the -Q option. -- Eric Schulte http://cs.unm.edu/~eschulte
Re: [O] python/babel inline images
-Original Message- From: emacs-orgmode-bounces+mlt=gmx...@gnu.org [mailto:emacs-orgmode- bounces+mlt=gmx...@gnu.org] On Behalf Of Eric Schulte Sent: Wednesday, June 06, 2012 2:25 PM To: Mikhail Titov Cc: emacs-orgmode@gnu.org; 'henry atting' Subject: Re: [O] python/babel inline images Meanwhile I've noticed that I can't return back from editing python code in a sub-editing buffer. C-c ' does not work and M-x org-edit-src-exit says This is not a sub-editing buffer, something is wrong. This works on my system, perhaps the problem is due to something in your configuration. Do you still notice this problem when launching emacs with the -Q option. Huh... -Q solves it. I'm loading CEDET early in dot emacs for matlab-emacs (as per manual) and it does something nasty that ruins normal behavior of C-c '. Bummer. Outdated eieio 1.3 shadowed to meet minimum version 1.4 Outdated semantic 2.0 shadowed to meet minimum version 2.1 Outdated srecode 1.0 shadowed to meet minimum version 1.1 Outdated ede 1.0 shadowed to meet minimum version 1.1 Outdated speedbar 1.0 shadowed to meet minimum version 1.0.4 Setting up CEDET packages...done M.
Re: [O] python/babel inline images
henry atting nsmp...@online.de writes: I do not succeed in generating an inline image as a result of a python code block. The code itself works, C-c C-c generates the according picture, but only in my home directory. The code block: Could you not just follow the block with a hand-written link to the output file? Then, when it becomes available toggle C-c C-x C-v (once or twice) or M-x org-display-inline-images once. Maybe also rewrite the Python to place the output SVG in a directory associated with your ORG file so that link can be relative. I simply use an env. var. to locate where my plots should output. I'm an org-newbie so maybe there are better ways. -Brett. pgpZ7AoYIND5t.pgp Description: PGP signature
Re: [O] python/babel inline images
henry atting nsmp...@online.de writes: Hi, I do not succeed in generating an inline image as a result of a python code block. The code itself works, C-c C-c generates the according picture, but only in my home directory. The code block: -*- org-babel-python-command: python3 -*- #+begin_src python import csv import matplotlib.pyplot as plot x = [] y = [] csv_reader = csv.reader(open('csv_data.csv')) for line in csv_reader: x.append(int(line[0])) y.append(float(line[1])) plot.plot(x, y, label=r'exp', color='green') plot.legend(loc='lower right') plot.savefig(exp_csv.svg) #+end_src It tried different combinations of `:exports results', `:results file', `:file filename' I'm not python expert, but the code block should be run in your current directory, e.g., the following outputs the current working path expected for me. #+begin_src sh pwd #+end_src If you want to explicitly pass the current directory to your code block as an argument, you could try something like the following #+begin_src python :var mydir=(file-name-directory (buffer-file-name)) return mydir #+end_src Hope this helps, -- Eric Schulte http://cs.unm.edu/~eschulte
Re: [O] python/babel inline images
At Tue, 05 Jun 2012 08:57:19 -0600, Eric Schulte wrote: henry atting nsmp...@online.de writes: Hi, I do not succeed in generating an inline image as a result of a python code block. The code itself works, C-c C-c generates the according picture, but only in my home directory. The code block: -*- org-babel-python-command: python3 -*- #+begin_src python import csv import matplotlib.pyplot as plot x = [] y = [] csv_reader = csv.reader(open('csv_data.csv')) for line in csv_reader: x.append(int(line[0])) y.append(float(line[1])) plot.plot(x, y, label=r'exp', color='green') plot.legend(loc='lower right') plot.savefig(exp_csv.svg) #+end_src It tried different combinations of `:exports results', `:results file', `:file filename' I'm not python expert, but the code block should be run in your current directory, e.g., the following outputs the current working path expected for me. #+begin_src sh pwd #+end_src If you want to explicitly pass the current directory to your code block as an argument, you could try something like the following #+begin_src python :var mydir=(file-name-directory (buffer-file-name)) return mydir #+end_src I guess if it's a paths' problem, the python equivalent would be os.getcwd(), from the os module, and a solution to have the picture in the right place could be os.chdir(path) (or maybe plot.savefig can take a full path as an argument), but I think the OP (and I'm very interested too) wants org-babel to manage the python output somehow to inline the image automatically. I don't see that possible, because I don't think the results of plot.savefig is the value of the image, but rather an i/o operation somehow (and I may well be wrong) (and nothing goes to stdout). But maybe to output a link could do ? #+begin_src python :results output file stuff path = exp_csv.svg plot.savefig(path) print path #+end_src HTH
Re: [O] python/babel inline images
-Original Message- From: emacs-orgmode-bounces+mlt=gmx...@gnu.org [mailto:emacs-orgmode- bounces+mlt=gmx...@gnu.org] On Behalf Of Eric Schulte Sent: Tuesday, June 05, 2012 9:57 AM To: henry atting Cc: emacs-orgmode@gnu.org Subject: Re: [O] python/babel inline images I'm not python expert, but the code block should be run in your current directory, e.g., the following outputs the current working path expected for me. #+begin_src sh pwd #+end_src If you want to explicitly pass the current directory to your code block as an argument, you could try something like the following #+begin_src python :var mydir=(file-name-directory (buffer-file-name)) return mydir #+end_src I've noticed some inconsistency between various languages in this aspect. For instance, ob-R starts session in proper working directory, while all looks like everything (?) else does not. Should not it be somewhat standardized? I think it make sense to always cd to org doc folder. M.