jupyter-book
jupyter-book copied to clipboard
Inserting subfigures with Myst-Markdown that render in book
hey @broncio123 - could you open up a new issue if you've got a question? I believe this issue is targeted for displaying figures in both myst-markdown and jupyter interfaces
Originally posted by @choldgraf in https://github.com/executablebooks/jupyter-book/issues/629#issuecomment-659454521
The syntax in the documentation - shown below- works for singles figures, but it's not obvious how to tweak this to insert subfigures so that they appear under the same figure number, referenced with the same label, and they can have separate captions in addition to the main one. Is this even possible?
```{figure} path_to_my_figure
---
name: my-label
---
My caption
Hmmm I'm not currently sure how to insert multiple figures in one with different captions. I think our assumption is that you'd do this on the figure rendering side (e.g. use matplotlib with multiple subplots). Would that work for you?
My figures are not generated via code.
My current solution was jut to add figures sequentially separately without a caption, and just add the caption to the last one. Something like this:
```{figure} path_to_my_figure1A
---
name:
---
```
```{figure} path_to_my_figure1B
---
name:
---
My caption
```
The issue with this is that it will generate a number per figure, which is not ideal for appearance. Couldn't get my head around how to disable figure numbers. HOWEVER, this is works for now.
thanks @broncio123, its certainly on my wish-list; to implement more latex features into myst/sphinx, in the same way that sphinxcontrib-bibtex implements bibliography features. (I have actually already written one previously for LaTeX glossaries) This would include subcaption.
To the best of my knowledge there is currently no sphinx extension which achieves this. If so, I would like to look into writing one at some point (or help someone else). Unfortunately, this is behind many other things on the priority list at the moment 😞
For me, it is a important feature lacking in MyST. I don't care about the subcaptions, but it should be easy to reproduce something like
\begin{figure}[!ht]
\centering
\includegraphics[width=0.4\linewidth]{./figs/2013_FordFusion_CFDTopandSide}
\includegraphics[width=0.55\linewidth]{./figs/airfoil_turbulence}
\caption{Turbulent wake of vehicles, car and airfoil.}
\label{fig_turbulent_wake_vehicles}
\end{figure}
The ugly workaround that I found (but no figure):
``````{admonition} Turbulent wake of vehicles, car and airfoil
`````{grid}
:gutter: 2
````{grid-item}
```{image} ./figs/2013_FordFusion_CFDTopandSide.png
:alt: 2013_FordFusion_CFDTopandSide.png
:width: 80%
:align: center
```
````
````{grid-item}
```{image} ./figs/airfoil_turbulence.jpg
:alt:
:width: 80%
:align: center
```
````
`````
``````
I think it should be possible to define a figure without a file and to describe the content of the figure in the directive content.
@paugier Take a look at https://sphinx-subfigure.readthedocs.io 😉
Oh great! It works like a charm. I should try to make a PR to include a mention of sphinx-subfigure in https://jupyterbook.org/en/stable/content/figures.html.
Unfortunately, I am not able to get the subfigure displayed. I installed: pip install sphinx-subfigure and in modified the _config.yml as shown below sphinx: extra_extensions: - sphinx_subfigure
However, I don't get a subfigure displayed, could you please tell me what you did in order to get it working?
The question has become irrelevant for. However, thank you