nschloe / tikzplotlib

:bar_chart: Save matplotlib figures as TikZ/PGFplots for smooth integration into LaTeX.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Figure alignment in subfloats

youcann opened this issue · comments

Hi,
what is your workflow when generating plots to be used as subfloats?

(I'm not happy with groupplots because of the lack of configurability, the visual appeal and it being complicated to add/change subcaptions of the plots)

I've tried it with the code below. But i have several size issues. Is it possible so set the 'drawing area' to a fixed size or sth? And how to do this from tikzplotlib?

Thanks!

Python:

import matplotlib.pyplot as plt
import tikzplotlib
import numpy as np

x1=np.arange(0,10)*10e9
x2=np.arange(0,1000)
y1=np.random.randn(1,len(x1))[0]
y2=0.01*x2*np.random.randn(1,len(x2))[0]

KIT_green=(0/255,150/255,130/255)
KIT_blue=(70/255,100/255,170/255)

plt.figure()
plt.plot(x2,y2,label="second trace",color=KIT_green)
plt.xlabel(r"Time $t$ (in \si{\milli\second})")
plt.ylabel(r"Amplitude $S_{11}$ \\ (some measurement) \\ (and another meaningless line) (in \si{\volt})");
tikzplotlib.save("subfigs_left.tikz",extra_axis_parameters=["ylabel style={align=center}"],axis_width="5cm",axis_height="5cm")

plt.figure()
plt.plot(x1,y1,label="first trace",color=KIT_blue)
plt.xlabel(r"Time $t$ (in \si{\milli\second})")
plt.ylabel(r"Amplitude $S_{11}$, $S_{35}$ (in \si{\volt})");
tikzplotlib.save("subfigs_right.tikz",extra_axis_parameters=["ylabel style={align=center}"],axis_width="5cm",axis_height="5cm")

LaTeX:

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{siunitx}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{tikzscale}

\begin{document}
\begin{figure}
    \centering
        \subfloat[Plot 1: this shows this]{\includegraphics[width=0.4\textwidth]{subfigs_left.tikz}}
        \qquad
        \subfloat[Plot 2: and this shows that. But this explanation is quite long. blablabla]{\includegraphics[width=0.4\textwidth]{subfigs_right.tikz}}
       \caption{Two plots}
    \label{fig:subfig}
\end{figure}
\end{document}

image