Seite 1 von 1

Pgfplot Boxplot Medianwert

Verfasst: Sa 17. Apr 2021, 22:32
von Holger Witte

Hallo liebes Forum,
mir ist aufgefallen, dass die Angabe des Median bei Beschriftung einer Boxplot (mit Pgfplot erstellt) im Nachkommabereich unterschiedliche Ergebnisse liefert. Die Ergebnisse verändern sich, sobald ein weiteres Paket neben "\usepgfplotslibrary{statistics}" eingebunden wird. Es reicht bereits aus, nach "statistics" ein Komma einzufügen und die berechneten Werte für den Median ändern sich. In meinem Beispiel wird einmal 51,45 berechnet und einmal 51,17. Der zweite Wert ist falsch. Ist das ein Fehler des Pakets oder mache ich etwas falsch?
Vielen Dank im Voraus und Grüße
Holger

\documentclass[paper=a4]{paper}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{statistics}

\begin{document}
\begin{tikzpicture}
\begin{axis}[]
\addplot+ [boxplot]
table [row sep=\\,y index=0] {
data\\
12.11\\12.11\\12.11\\12.11\\15\\15\\15\\15\\19.5\\19.5\\19.5\\19.5\\20.39\\20.39\\20.39\\20.39\\20.81\\20.81\\20.81\\20.81\\24\\24.8\\24.8\\24.8\\24.8\\24.8\\24.8\\25\\25\\25\\25\\31\\31\\31\\31\\31\\31\\31\\31\\33.47\\33.47\\33.47\\33.47\\33.47\\33.47\\33.47\\34.25\\34.25\\34.25\\34.25\\35\\35\\35\\35\\35\\35\\35\\40\\40\\40\\40\\42\\42\\42\\44.89\\45.5\\45.5\\45.5\\45.5\\48.19\\50.77\\50.77\\51.17\\51.74\\51.89\\51.89\\51.89\\51.89\\53.94\\55.01\\55.01\\55.01\\55.01\\55.02\\56.29\\57.2\\57.2\\59.93\\60\\60\\60\\60.83\\60.83\\62\\62\\62\\62\\63.72\\65\\65\\65\\67.8\\74.37\\74.37\\74.37\\74.37\\75\\75\\75\\75\\75\\76.92\\78.72\\78.72\\78.72\\78.72\\80\\80\\80\\80\\80.63\\80.63\\84.96\\85.11\\93.75\\95\\95\\95\\95\\95\\100\\100\\100\\100\\101.38\\101.38\\101.38\\104.76\\118.1\\123.1\\123.1\\133.86\\179.55\\183.97\\222.17\\236.19\\
}
[above]
node[below] at
(boxplot box cs: \boxplotvalue{median},0)
{\pgfmathprintnumber{\boxplotvalue{median}}}
;
\end{axis}
\end{tikzpicture}
\end{document}

und hier der falsche Wert

\documentclass[paper=a4]{paper}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{statistics,}

\begin{document}
\begin{tikzpicture}
\begin{axis}[]
\addplot+ [boxplot]
table [row sep=\\,y index=0] {
data\\
12.11\\12.11\\12.11\\12.11\\15\\15\\15\\15\\19.5\\19.5\\19.5\\19.5\\20.39\\20.39\\20.39\\20.39\\20.81\\20.81\\20.81\\20.81\\24\\24.8\\24.8\\24.8\\24.8\\24.8\\24.8\\25\\25\\25\\25\\31\\31\\31\\31\\31\\31\\31\\31\\33.47\\33.47\\33.47\\33.47\\33.47\\33.47\\33.47\\34.25\\34.25\\34.25\\34.25\\35\\35\\35\\35\\35\\35\\35\\40\\40\\40\\40\\42\\42\\42\\44.89\\45.5\\45.5\\45.5\\45.5\\48.19\\50.77\\50.77\\51.17\\51.74\\51.89\\51.89\\51.89\\51.89\\53.94\\55.01\\55.01\\55.01\\55.01\\55.02\\56.29\\57.2\\57.2\\59.93\\60\\60\\60\\60.83\\60.83\\62\\62\\62\\62\\63.72\\65\\65\\65\\67.8\\74.37\\74.37\\74.37\\74.37\\75\\75\\75\\75\\75\\76.92\\78.72\\78.72\\78.72\\78.72\\80\\80\\80\\80\\80.63\\80.63\\84.96\\85.11\\93.75\\95\\95\\95\\95\\95\\100\\100\\100\\100\\101.38\\101.38\\101.38\\104.76\\118.1\\123.1\\123.1\\133.86\\179.55\\183.97\\222.17\\236.19\\
}
[above]
node[below] at
(boxplot box cs: \boxplotvalue{median},0)
{\pgfmathprintnumber{\boxplotvalue{median}}}
;
\end{axis}
\end{tikzpicture}
\end{document}

Re: Pgfplot Boxplot Medianwert

Verfasst: Sa 17. Apr 2021, 22:36
von Holger Witte

Wie kann ich den Code hier so einbetten, dass er automatisch mit einem Knopf versehen wird, sodass man ihn ausführen kann?


Verfasst: Sa 17. Apr 2021, 22:58
von Gast.

Verfasst: Sa 17. Apr 2021, 23:35
von Gast.

Man kann das Problem zumindest umgehen.


Re: Pgfplot Boxplot Medianwert

Verfasst: So 18. Apr 2021, 13:07
von Holger Witte

Lädt man die Pakete nacheinander mit neuem Befehl \usepgfplotslibrary{} stimmen die Werte. Besten Dank!