1

I created different plots with matplotlib, which I export as .pgf files. I then import these plots again in latex to display them in my document. This process works fine with the following code:

matplotlib example code:

import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)

fig, ax = plt.subplots(1,1)

ax.plot(t, s)

ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='About as simple as it gets, folks')
ax.legend(["Test label long"])
ax.grid()

fig.savefig("test.pgf", bbox_inches='tight', format='pgf')
plt.show()

Latex:

\documentclass{article}

\usepackage{pgf}

\begin{document}

\begin{figure}[htbp]
    \centering
    \resizebox{0.6\textwidth}{!}{
        \input{test.pgf}
    }
\end{figure}

\end{document}

Resulting plot:

document example

I want to include this plot in a presentation as well. So, I created a simple presentation with beamer and used the following code to include the plot:

\documentclass[11pt,t,usepdftitle=false,aspectratio=169]{beamer}

\RequirePackage[T1]{fontenc}
\RequirePackage[scaled=.9]{berasans}

\begin{document}

\begin{frame}
    \frametitle{My Title}
        \begin{figure}[htbp]
        \centering
        \resizebox{0.6\textwidth}{!}{
            \input{test.pgf}
        }
    \end{figure}
\end{frame}

\end{document}

The problem now is that the legend label is not completely inside the legend anymore. You can see it (red circle) in the following image:

enter image description here

I tried different things to scale the plots, but nothing changes the output. The problem occurs also with the axis labels (not shown in the posted example). I suspect that it has to do with the scaling of the text in the plots but I cannot figure out how to control it. Any help would be greatly appreciated!

EDIT: As suggested by the comment I added the latex code to directly reproduce the problem. When creating the example I noticed that the problem was coming from the theme I have to use.

I could narrow down the problem to the two \RequirePackage statements that I included in the beamer code example. Interestingly, if only one package is included the plot appears normal, but if I include both the problem occurs. Could it be that these two packages are somehow conflicting?

Also, I notice that the length of the label changes if I change the scaling factor of \RequirePackage[scaled=.9]{berasans}. Could it be that this scaling factor is "wrong" in the theme I have to use?

2
  • Welcome! It would be much better if you add to the LaTeX snippet the necessary minimum boilerplate to make them compilable (documentclass, packages etc.). The answer may depend a lot on those. See tex.meta.stackexchange.com/questions/6255/…
    – Rmano
    Commented Feb 3, 2022 at 11:25
  • 1
    Thank you very much! I created the snippets and could narrow down the problem to two statements in the theme I have to use. Hopefully, someone can help me with the more precise problem.
    – JANO
    Commented Feb 3, 2022 at 12:46

0

You must log in to answer this question.

Browse other questions tagged .