Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Tabellen und Grafiken erstellen und anordnen


Kazter
Forum-Newbie
Forum-Newbie
Beiträge: 3
Registriert: Mi 17. Aug 2022, 08:45

Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Beitrag von Kazter »

Hallo zusammen,
leider komme ich nicht weiter.. Habe das Problem, dass die Ausrichtung der Bildunterschrift verrutscht, wenn ein Diagramm in der X-Achse eine Kommadarstellung hat und das andere nicht.

Kann mir jemand helfen. Vielen Dank!!
test.png
\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
}

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{width=0.45\textwidth, height=.25\textheight}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}

rais
Forum-Guru
Forum-Guru
Beiträge: 407
Registriert: Di 21. Sep 2010, 00:37

Re: Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Beitrag von rais »

Wenn Du genau hinschaust, siehst Du, daß die beiden `label x' bereits auf unterschiedlicher Höhe landen. Die Kommata besitzen eine Tiefe, die besagte Marke etwas weiter nach unten drängt, als die andere. Versuch es so:
\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
   x tick label style={text depth=0.25ex}%<--
}

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{width=0.45\textwidth, height=.25\textheight}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}
BTW: der Wert für `text depth' stammt hier aus der tikz-Doku, schau dort nach `dance around' (derzeit am Ende von Abschnitt 5.1) :wink:

VG
Rainer
One of the joys of travel is visiting new towns and meeting new people---G.Khan (Robert Asprin, Another Fine Myth)

esdd
Forum-Meister
Forum-Meister
Beiträge: 2561
Registriert: So 7. Feb 2010, 16:36

Re: Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Beitrag von esdd »

Man kann auch typeset ticklabels with strut entweder global in der Präambel
\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
   typeset ticklabels with strut
}
oder lokal verwenden:
\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
}

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{
  width=0.45\textwidth, height=.25\textheight,
  typeset ticklabels with strut% <- eingefügt
}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}

Kazter
Forum-Newbie
Forum-Newbie
Beiträge: 3
Registriert: Mi 17. Aug 2022, 08:45

Re: Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Beitrag von Kazter »

Erst einmal vielen Dank für Eure Antworten!

Habe jetzt etwas erweitert und bekomme wieder Probleme mit der Ausrichtung, wenn ich das Paket "siunitx" einbinde...

Habe sowohl die Variante mit
typeset ticklabels with strut
als auch mit
x tick label style={text depth=0.25ex}
probiert..
\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
}

\usepackage{siunitx}% <- eingefügt
\sisetup{
	locale = DE, 
	group-minimum-digits=4,
	per-mode=symbol-or-fraction,
  }

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{
  width=0.45\textwidth, height=.25\textheight,
  typeset ticklabels with strut
}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x \si{\cubic\metre\per\hour}},% <- eingefügt
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x \si{\litre\per\hour}},% <- eingefügt
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}

Gute*r Gȧst*in

Re: Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Beitrag von Gute*r Gȧst*in »

Dieses Mal sind wohl nicht die ticks label, sondern die xlabel das Problem. Die haben (durch den Exponenten) eine unterschiedliche Höhe. Im Beispiel kann das recht einfach über explizite \strut gelöst werden:
\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
}

\usepackage{siunitx}
\sisetup{
	locale = DE, 
	group-minimum-digits=4,
	per-mode=symbol-or-fraction,
  }

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{
  width=0.45\textwidth, height=.25\textheight,
  typeset ticklabels with strut
}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x \strut\si{\cubic\metre\per\hour}},% <- \strut eingefügt
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x \strut\si{\litre\per\hour}},% <- \strut eingefügt
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}
Das geht häufig aber nicht immer so einfach. Sobald die beispielsweise unterschiedliche Zeilenzahl haben, wird es das so nicht mehr funktionieren.

Kazter
Forum-Newbie
Forum-Newbie
Beiträge: 3
Registriert: Mi 17. Aug 2022, 08:45

Re: Anordnung von zwei Diagrammen nebeneinander (mit Komma in xaxis)

Beitrag von Kazter »

Mit etwas basteln, habe ich jetzt folgendes gefunden:

x label style={yshift=-3.00ex,anchor=south}

im lokalen \pgfplotsset{...}, siehe MWE.

Bin aber auch gerne für Alternativen offen ;)
\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
}

\usepackage{siunitx}
\sisetup{
	locale = DE, 
	group-minimum-digits=4,
	per-mode=symbol-or-fraction,
  }

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{
  width=0.45\textwidth, height=.25\textheight,
  typeset ticklabels with strut,
  x label style={yshift=-3.00ex,anchor=south}% <- \strut eingefügt
}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x \strut\si{\cubic\metre\per\hour}},% <- \strut eingefügt
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x \strut\si{\litre\per\hour}},% <- \strut eingefügt
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}

Antworten