emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Add caption to babel-generated images
@ 2016-08-30  9:27 Florian Lindner
  2016-08-30 10:11 ` Nicolas Goaziou
  2016-08-30 11:04 ` Georgiy Tugai
  0 siblings, 2 replies; 7+ messages in thread
From: Florian Lindner @ 2016-08-30  9:27 UTC (permalink / raw)
  To: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Add caption to babel-generated images
  2016-08-30  9:27 Add caption to babel-generated images Florian Lindner
@ 2016-08-30 10:11 ` Nicolas Goaziou
  2016-08-30 10:40   ` Florian Lindner
  2016-08-30 11:04 ` Georgiy Tugai
  1 sibling, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2016-08-30 10:11 UTC (permalink / raw)
  To: Florian Lindner; +Cc: emacs-orgmode

Hello,

Florian Lindner <mailinglists@xgm.de> writes:

> 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.

What did you write? What doesn't work?

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Add caption to babel-generated images
  2016-08-30 10:11 ` Nicolas Goaziou
@ 2016-08-30 10:40   ` Florian Lindner
  0 siblings, 0 replies; 7+ messages in thread
From: Florian Lindner @ 2016-08-30 10:40 UTC (permalink / raw)
  To: emacs-orgmode

Am 30.08.2016 um 12:11 schrieb Nicolas Goaziou:
> Hello,
> 
> Florian Lindner <mailinglists@xgm.de> writes:
> 
>> I have this code block:
>>
[...]

>> 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.
> 
> What did you write? What doesn't work?

This org mode document

#+NAME: fig:org_fig
#+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
#+CAPTION: Org Fig
#+LABEL: fig:org_fig

Exports to:

\begin{document}

\maketitle
\tableofcontents

\includegraphics[width=.9\linewidth]{rbf-gaussian-4.pdf} \\
% Emacs 24.5.1 (Org mode 8.2.10)
\end{document}

Additionally, when evaluating it's changed to:

[...]
#+END_SRC

#+RESULTS: fig:org_fig
[[file:rbf-gaussian-4.pdf]]

#+CAPTION: Org Fig
#+LABEL: fig:org_fig


Splitting off the caption and label.

Best,
Florian

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Add caption to babel-generated images
  2016-08-30  9:27 Add caption to babel-generated images Florian Lindner
  2016-08-30 10:11 ` Nicolas Goaziou
@ 2016-08-30 11:04 ` Georgiy Tugai
  2016-08-30 11:54   ` Florian Lindner
  2016-08-30 11:55   ` Nicolas Goaziou
  1 sibling, 2 replies; 7+ messages in thread
From: Georgiy Tugai @ 2016-08-30 11:04 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1987 bytes --]

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.

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
> 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Add caption to babel-generated images
  2016-08-30 11:04 ` Georgiy Tugai
@ 2016-08-30 11:54   ` Florian Lindner
  2016-08-30 12:02     ` Florian Lindner
  2016-08-30 11:55   ` Nicolas Goaziou
  1 sibling, 1 reply; 7+ messages in thread
From: Florian Lindner @ 2016-08-30 11:54 UTC (permalink / raw)
  To: emacs-orgmode

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
>>
>>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Add caption to babel-generated images
  2016-08-30 11:04 ` Georgiy Tugai
  2016-08-30 11:54   ` Florian Lindner
@ 2016-08-30 11:55   ` Nicolas Goaziou
  1 sibling, 0 replies; 7+ messages in thread
From: Nicolas Goaziou @ 2016-08-30 11:55 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Georgiy Tugai <georgiy.tugai@gmail.com> writes:

> 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.

Exactly. 

Also, there is no need for #+LABEL, which is an obsolete synonym for
#+NAME.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Add caption to babel-generated images
  2016-08-30 11:54   ` Florian Lindner
@ 2016-08-30 12:02     ` Florian Lindner
  0 siblings, 0 replies; 7+ messages in thread
From: Florian Lindner @ 2016-08-30 12:02 UTC (permalink / raw)
  To: emacs-orgmode

Am 30.08.2016 um 13:54 schrieb Florian Lindner:
> 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.

Of course, using NAME instead of CAPTION. But I just learned that CAPTION is just an obsolete alias for NAME.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-08-30 12:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-30  9:27 Add caption to babel-generated images Florian Lindner
2016-08-30 10:11 ` Nicolas Goaziou
2016-08-30 10:40   ` Florian Lindner
2016-08-30 11:04 ` Georgiy Tugai
2016-08-30 11:54   ` Florian Lindner
2016-08-30 12:02     ` Florian Lindner
2016-08-30 11:55   ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).