LaurentRDC / pandoc-plot

Render and include figures in Pandoc documents using your plotting toolkit of choice
https://laurentrdc.github.io/pandoc-plot/
GNU General Public License v2.0
216 stars 8 forks source link

Ability to modify figure dimensions #38

Closed samuel-emrys closed 2 years ago

samuel-emrys commented 2 years ago

I can't currently see a good way to modify the dimensions of the figure. The equivalent latex code would be:

\begin{center}
    \includegraphics[width=200px]{./plots/pandocplot9558264899394455289.png}
\end{center}

Is it possible to proxy parameters like this to the underlying images? I'm having an issue where the figure is overflowing the boundaries of the slide similar to the following: Screenshot_20220228_153448

This is more than just image overflow though, the caption "Figure 1: XYZ" is also being pushed off the page. Is there currently a way to rectify this?

LaurentRDC commented 2 years ago

Hi Samuel,

pandoc-plot will let all 'unknown' parameter be passed to pandoc. For example:

```{.matplotlib hello="world" foo=10}
fig = plt.figure(figsize=(10, 20)) # figure size in inches
...


would pass the parameters `hello` and `foo` to the underlying format. I can't test right now, but using this you should be able to have more control over the final conversion.
samuel-emrys commented 2 years ago

Hi @LaurentRDC, a working example would be appreciated if you have the time. I haven't been able to get anything to work here - because graphviz doesn't allow you to specify a size i don't think I can modify the way the image is generated, and I can't easily see a way to influence the resulting latex with what you've described

LaurentRDC commented 2 years ago

Here's a minimal example:

Without controlling figure size

starting with this Markdown input:

# Title

Paragraph

```{.graphviz}
digraph D {

  A [shape=diamond]
  B [shape=box]
  C [shape=circle]

  A -> B [style=dashed, color=grey]
  A -> C [color="black:invis:black"]
  A -> D [penwidth=5, arrowhead=none]

}

Render with `pandoc --filter pandoc-plot -i example.md -o example.tex`, gives the following LaTeX output:

```tex
\hypertarget{title}{%
\section{Title}\label{title}}

Paragraph

\begin{figure}
\centering
\includegraphics{plots/11623886912816197297.png}
\caption{}
\end{figure}

With sizing

# Title

Paragraph

```{.graphviz width=50mm height=60mm}
digraph D {

  A [shape=diamond]
  B [shape=box]
  C [shape=circle]

  A -> B [style=dashed, color=grey]
  A -> C [color="black:invis:black"]
  A -> D [penwidth=5, arrowhead=none]

}

Output looks like: 

```tex
\hypertarget{title}{%
\section{Title}\label{title}}

Paragraph

\begin{figure}
\centering
\includegraphics[width=50mm,height=60mm]{plots/11623886912816197297.png}
\caption{}
\end{figure}

As you can see, the parameters width=50mm and height=60mm (which are not understood by pandoc-plot) are passed to pandoc.

Does this help?

LaurentRDC commented 2 years ago

Given the solution above, I'll close this for now. Don't hesitate to re-open this issue if you need further help

ronchaine commented 1 year ago

Would it be possible to add this example to the pandoc-plot documentation? I don't expect everyone using pandoc-plot to be savvy enough to check github issues when they encounter this?

paderevski commented 5 months ago

This behavior no longer exists in v 1.7.0. The example above did not pass through options to .tex