From mboxrd@z Thu Jan 1 00:00:00 1970 From: Florian Lindner Subject: Re: Add caption to babel-generated images Date: Tue, 30 Aug 2016 13:54:00 +0200 Message-ID: References: <20160830110410.GA19154@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1behcR-0005Dv-9D for emacs-orgmode@gnu.org; Tue, 30 Aug 2016 07:54:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1behcN-0001er-6r for emacs-orgmode@gnu.org; Tue, 30 Aug 2016 07:54:18 -0400 Received: from [195.159.176.226] (port=47536 helo=blaine.gmane.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1behcM-0001e4-Vj for emacs-orgmode@gnu.org; Tue, 30 Aug 2016 07:54:15 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1behcG-0002Jz-0P for emacs-orgmode@gnu.org; Tue, 30 Aug 2016 13:54:08 +0200 In-Reply-To: <20160830110410.GA19154@gmail.com> 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" To: emacs-orgmode@gnu.org Am 30.08.2016 um 13:04 schrieb Georgiy Tugai: > I don't know if it'll work for Python, but here's an example of what > works for me with Ditaa: > >> #+BEGIN_SRC ditaa :file figs/-mininet-ovsk.png :cache yes >> /----+ /----+ /----+ /----+ >> |host| |host| |host| |host| Containers >> +-+--/ +-+--/ +--+-/ +--+-/ >> | | | | >> --------------------------------------------- >> | | | | >> +-+------+-------+------+-+ >> | Open VSwitch | Host kernel >> +-----+-------------+---=-+ >> | | >> +------+-----+ +-----+------+ >> | controller | | controller | Host userspace >> +------------+ +------------+ >> #+END_SRC >> >> #+ATTR_LATEX: :width "" :options [scale=0.75] >> #+CAPTION: [[label:fig:mininet-arch]]Mininet with OpenVSwitch architecture >> #+RESULTS[1d367d39f18523f4eb247cb13aabd6c6f633fbdf]: [[file:figs/-mininet-ovsk.png]] > > First, execute your Babel block in order to generate a #+RESULTS line. > Then, add CAPTION, ATTR_LATEX etc. lines before the RESULTS line. This seems to work mostly, yes. Problem is, that org puts the label inside the caption: \begin{figure}[htb] \centering \includegraphics[width=.9\linewidth]{rbf-gaussian-4.pdf} \caption{\label{fig:GaussianExample}Gaussian Basis functions with vertex distances marked at $n \cdot \frac{1}{6}$.} \end{figure} This way the label does not work, i.e. won't be found by ref links. #+BEGIN_SRC python :exports results :results file import matplotlib.pyplot as plt, numpy as np x = np.linspace(-2, 2, 1000) plt.plot(x, np.exp(-np.power(4*x, 2)), label="shape-parameter=4") for i in range(-4, 5): plt.axvline(1/6 * i, ymax = 0.1, ls = "-.", color="r") plt.grid() plt.savefig('rbf-gaussian-4.pdf') return "rbf-gaussian-4.pdf" #+END_SRC #+LABEL: fig:GaussianExample #+CAPTION: Gaussian Basis functions with vertex distances marked at $n \cdot \frac{1}{6}$. #+RESULTS: [[file:rbf-gaussian-4.pdf]] Using NAME instead of caption results in the same latex output. Thanks, Florian > > Good luck! > Georgiy > > On 30 Aug, Florian Lindner wrote: >> Hello, >> >> I have this code block: >> >> #+BEGIN_SRC python :exports results :results file >> import matplotlib.pyplot as plt, numpy as np >> x = np.linspace(-2, 2, 1000) >> plt.plot(x, np.exp(-np.power(4*x, 2)), label="shape-parameter=4") >> for i in range(-4, 5): plt.axvline(1/6 * i, ymax = 0.1, ls = "-.", color="r") >> plt.grid() >> plt.savefig('rbf-gaussian-4.pdf') >> return "rbf-gaussian-4.pdf" >> #+END_SRC >> >> When exporting to latex it nicely compiles into \includegraphics[width=.9\linewidth]{rbf-gaussian-4.pdf}. >> >> Now I want to have this \includegraphics in a figure environement including a label (to reference it) and a caption. >> >> How can do this best? >> >> I have found: >> http://emacs.stackexchange.com/questions/12150/add-caption-to-an-image-generated-by-a-code-block >> >> but it doesn't work for me. >> >> Thanks, >> Florian >> >>