So legen Sie die Breite eines Balkendiagramms in Achseneinheiten fest

So legen Sie die Breite eines Balkendiagramms in Achseneinheiten fest

Ich möchte die folgenden Daten als Balkendiagramm darstellen, wobei die Breite jedes Balkens 784,7913898303067 in Einheiten der Achse beträgt:

-8907.243859923638 2.178160631669683e-06
-8122.452470093331 8.712642526678732e-06
-7337.661080263024 4.356321263339366e-06
-6552.869690432717 1.0890803158348416e-05
-5768.07830060241 1.7425285053357465e-05
-4983.2869107721035 1.9603445685027148e-05
-4198.495520941797 3.9206891370054296e-05
-3413.70413111149 6.752297958176017e-05
-2628.912741281183 0.00012415515600517195
-1844.1213514508763 0.00015900572611188686
-1059.3299616205695 0.00018949997495526245
-274.53857179026284 0.00020039077811361084
510.25281804004385 0.00016989652927023528
1295.0442078703504 0.00011326435284682353
2079.835597700657 7.62356221084389e-05
2864.626987530964 3.267240947504525e-05
3649.418377361271 1.5247124421687783e-05
4434.209767191577 4.356321263339366e-06
5219.001157021884 4.356321263339366e-06
6003.792546852191 1.0890803158348416e-05
6788.583936682498 0.0
7573.375326512804 4.356321263339366e-06
8358.16671634311 0.0
9142.958106173417 0.0

Ich mache:

\begin{tikzpicture}
        \begin{axis}
        [
        width=\linewidth,
        title = {Late Speed Distribution},
        xlabel = {$v$~[m/s]},
        ylabel = {Probability Density},
        ]
        \addplot[ybar, white!45!blue, fill = white!45!blue,bar width=784.7913898303067] table {barSpeeds.txt};
        \addplot[thick, red, domain=-10500:10500, samples=100]  {0.00016312130913239263 * exp(-8.359326130920716e-08*x*x)} node[black, pos = 0, anchor=south west]{$P(v_x) = \sqrt{\frac{m}{2\pi K_B T}}\exp\left(-\frac{1}{2}\frac{mv_x^2}{K_BT}\right)$};
        \end{axis}

Aber ich vermute, dass der Parameter für die Balkenbreite in einigen anderen Einheiten funktioniert. Ich habe es geschafft, es zum Laufen zu bringen, indem ich \pgfplotsset{compat=1.8}die Umgebung vor der Achse verwendet habe, aber aus irgendeinem anderen Grund verschiebt dies meine gesamte Abbildung nach unten und sie ist im Hinblick auf eine andere Abbildung, die ich neben dieser habe, falsch ausgerichtet.

BEARBEITEN: Die Verwendung von \pgfplotsset{compat=1.8}löst das Problem teilweise. Ich kann die Breite in Achseneinheiten festlegen. Aber aus irgendeinem Grund (warum?) verschiebt es die Position meines Bildes und es ist nicht mehr ausgerichtet.

\documentclass[11pt]{article}
\usepackage[top=2.54cm, bottom=2.54cm, left=2.75cm, right=2.75cm]{geometry}
\usepackage{float}
\usepackage{subcaption}
\usepackage{pgfplots}
\usepackage{amsmath}
\begin{filecontents*}{barSpeeds2.txt}
    -8907.243859923638 2.178160631669683e-06
    -8122.452470093331 8.712642526678732e-06
    -7337.661080263024 4.356321263339366e-06
    -6552.869690432717 1.0890803158348416e-05
    -5768.07830060241 1.7425285053357465e-05
    -4983.2869107721035 1.9603445685027148e-05
    -4198.495520941797 3.9206891370054296e-05
    -3413.70413111149 6.752297958176017e-05
    -2628.912741281183 0.00012415515600517195
    -1844.1213514508763 0.00015900572611188686
    -1059.3299616205695 0.00018949997495526245
    -274.53857179026284 0.00020039077811361084
    510.25281804004385 0.00016989652927023528
    1295.0442078703504 0.00011326435284682353
    2079.835597700657 7.62356221084389e-05
    2864.626987530964 3.267240947504525e-05
    3649.418377361271 1.5247124421687783e-05
    4434.209767191577 4.356321263339366e-06
    5219.001157021884 4.356321263339366e-06
    6003.792546852191 1.0890803158348416e-05
    6788.583936682498 0.0
    7573.375326512804 4.356321263339366e-06
    8358.16671634311 0.0
    9142.958106173417 0.0
\end{filecontents*}
\begin{filecontents*}{radialT2.txt}
    x   y   z
    0   724.6251253 27.23673321
    0.00011625  519.0500608 21.50619688
    0.0002325   471.8535621 20.0953379
    0.00034875  458.3159477 20.51917732
    0.000465    378.1946348 15.32643944
    0.00058125  402.6761363 16.59979084
    0.0006975   330.7735982 12.35631702
    0.00081375  483.4846951 17.4573978
    0.00093 879.0654654 17.75191929
\end{filecontents*}
\begin{document} 
    \begin{figure}[H]
        \begin{subfigure}[b]{0.49\textwidth}
            \centering
            \begin{tikzpicture}
            \pgfplotsset{compat=1.16}
            \begin{axis}
            [
            width=\linewidth,
            title = {Late Speed Distribution},
            xlabel = {$v$~[m/s]},
            ylabel = {Probability Density},
            ]
            \addplot[ybar, white!45!blue, fill = white!45!blue,bar width=784.7913898303067] table {barSpeeds2.txt};
            \addplot[thick, red, domain=-10500:10500, samples=100]  {0.00016312130913239263 * exp(-8.359326130920716e-08*x*x)} node[black, pos = 1, anchor=south west]{$P(v_x) = \sqrt{\frac{m}{2\pi K_B T}}\exp\left(-\frac{1}{2}\frac{mv_x^2}{K_BT}\right)$};
            \end{axis}
            \end{tikzpicture}
            \label{fig:tempProbab}
        \end{subfigure}
        \begin{subfigure}[b]{0.49\textwidth}
            \centering
            \begin{tikzpicture}
            \begin{axis}
            [
            width=\linewidth,
            title = {Temperature Radial Distribution},
            xlabel = $r~\text{[m]}$,
            ylabel = {Temperature~[K]},
            ]
            \addplot [blue,dashed,thick]
            plot [error bars/.cd, y dir = both, y explicit]
            table[y error index=2]{radialT2.txt};
            \end{axis}
            \end{tikzpicture}
            \label{fig:radialTemp}
        \end{subfigure}
        \caption{(a) . (b) .}
    \end{figure}
\end{document}

So sieht es derzeit aus: Und gibt es eine Möglichkeit, die Gleichung automatisch irgendwo im Plot einzufügen, wo sie sich nicht mit der Grafik überschneidet?

Danke Graph

Antwort1

Ich verstehe die Frage vielleicht nicht, aber wenn ich Ihre Fragmente zu einem Dokument vervollständige, erhalte ich meiner Meinung nach mit der Version das gewünschte Ergebnis 1.17( 1.15und 1.16es wird dasselbe Ergebnis erzielt, andere Versionen habe ich nicht getestet).

\documentclass{article}
\begin{filecontents*}{barSpeeds.txt}
-8907.243859923638 2.178160631669683e-06
-8122.452470093331 8.712642526678732e-06
-7337.661080263024 4.356321263339366e-06
-6552.869690432717 1.0890803158348416e-05
-5768.07830060241 1.7425285053357465e-05
-4983.2869107721035 1.9603445685027148e-05
-4198.495520941797 3.9206891370054296e-05
-3413.70413111149 6.752297958176017e-05
-2628.912741281183 0.00012415515600517195
-1844.1213514508763 0.00015900572611188686
-1059.3299616205695 0.00018949997495526245
-274.53857179026284 0.00020039077811361084
510.25281804004385 0.00016989652927023528
1295.0442078703504 0.00011326435284682353
2079.835597700657 7.62356221084389e-05
2864.626987530964 3.267240947504525e-05
3649.418377361271 1.5247124421687783e-05
4434.209767191577 4.356321263339366e-06
5219.001157021884 4.356321263339366e-06
6003.792546852191 1.0890803158348416e-05
6788.583936682498 0.0
7573.375326512804 4.356321263339366e-06
8358.16671634311 0.0
9142.958106173417 0.0
\end{filecontents*}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
    \begin{axis}
        [
        width=0.9\linewidth,
        title = {Late Speed Distribution},
        xlabel = {$v$~[m/s]},
        ylabel = {Probability Density},
        ]
        \addplot[ybar, white!45!blue, fill = white!45!blue,bar width=784.7913898303067] table {barSpeeds.txt};
        \addplot[thick, red, domain=-10500:10500, samples=100]  {0.00016312130913239263 * exp(-8.359326130920716e-08*x*x)} node[black, pos = 0, anchor=south west]{$P(v_x) = \sqrt{\frac{m}{2\pi K_B T}}\exp\left(-\frac{1}{2}\frac{mv_x^2}{K_BT}\right)$};
    \end{axis}
\end{tikzpicture}
\end{document}

Bildbeschreibung hier eingeben

Falls dies die Frage nicht beantwortet, hilft es vielleicht zumindest bei der Definition.

Was die aktualisierte Frage betrifft: Das Hauptproblem verschwindet, sobald Sie Bildunterschriften hinzufügen, was Sie meiner Meinung nach sowieso tun sollten. Was die Sichtbarkeit der Formel betrifft: Es gibt meines Wissens nach keinen Zaubertrick. Ich habe zwei Ad-hoc-Möglichkeiten hinzugefügt: contourund erhöhen ymax.

\documentclass[11pt]{article}
\usepackage[top=2.54cm, bottom=2.54cm, left=2.75cm, right=2.75cm]{geometry}
\usepackage{float}
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepackage[outline]{contour}
\contourlength{0.6pt}
\usepackage{amsmath}
\begin{filecontents*}{barSpeeds2.txt}
    -8907.243859923638 2.178160631669683e-06
    -8122.452470093331 8.712642526678732e-06
    -7337.661080263024 4.356321263339366e-06
    -6552.869690432717 1.0890803158348416e-05
    -5768.07830060241 1.7425285053357465e-05
    -4983.2869107721035 1.9603445685027148e-05
    -4198.495520941797 3.9206891370054296e-05
    -3413.70413111149 6.752297958176017e-05
    -2628.912741281183 0.00012415515600517195
    -1844.1213514508763 0.00015900572611188686
    -1059.3299616205695 0.00018949997495526245
    -274.53857179026284 0.00020039077811361084
    510.25281804004385 0.00016989652927023528
    1295.0442078703504 0.00011326435284682353
    2079.835597700657 7.62356221084389e-05
    2864.626987530964 3.267240947504525e-05
    3649.418377361271 1.5247124421687783e-05
    4434.209767191577 4.356321263339366e-06
    5219.001157021884 4.356321263339366e-06
    6003.792546852191 1.0890803158348416e-05
    6788.583936682498 0.0
    7573.375326512804 4.356321263339366e-06
    8358.16671634311 0.0
    9142.958106173417 0.0
\end{filecontents*}
\begin{filecontents*}{radialT2.txt}
    x   y   z
    0   724.6251253 27.23673321
    0.00011625  519.0500608 21.50619688
    0.0002325   471.8535621 20.0953379
    0.00034875  458.3159477 20.51917732
    0.000465    378.1946348 15.32643944
    0.00058125  402.6761363 16.59979084
    0.0006975   330.7735982 12.35631702
    0.00081375  483.4846951 17.4573978
    0.00093 879.0654654 17.75191929
\end{filecontents*}
\begin{document} 
    \begin{figure}[H]
        \begin{subfigure}[b]{0.49\textwidth}
            \centering
            \begin{tikzpicture}
            \pgfplotsset{compat=1.16}
            \begin{axis}
            [
            width=\linewidth,
            title = {Late Speed Distribution},
            xlabel = {$v$~[m/s]},
            ylabel = {Probability Density},
            ]
            \addplot[ybar, white!45!blue, fill = white!45!blue,bar width=784.7913898303067] table {barSpeeds2.txt};
            \addplot[thick, red, domain=-10500:10500, samples=100]  
            {0.00016312130913239263 * exp(-8.359326130920716e-08*x*x)} 
            node[black, pos = 0.5, anchor=south]{\contour{white}{$P(v_x) =
            \sqrt{\frac{m}{2\pi\, k_\mathrm{B}\,
            T}}\exp\left(-\frac{1}{2}\frac{m\,v_x^2}{k_\mathrm{B}\,T}\right)$}};
            \end{axis}
            \end{tikzpicture}
            \caption{}
           \label{fig:tempProbab-2}
        \end{subfigure}
        \begin{subfigure}[b]{0.49\textwidth}
            \centering
            \begin{tikzpicture}
            \begin{axis}
            [
            width=\linewidth,
            title = {Temperature Radial Distribution},
            xlabel = $r~\text{[m]}$,
            ylabel = {Temperature~[K]},
            ]
            \addplot [blue,dashed,thick]
            plot [error bars/.cd, y dir = both, y explicit]
            table[y error index=2]{radialT2.txt};
            \end{axis}
            \end{tikzpicture}
            \caption{}
            \label{fig:radialTemp-2}
        \end{subfigure}
        \caption{Using \texttt{contour}.}
    \end{figure}

    \begin{figure}[h]
        \begin{subfigure}[b]{0.49\textwidth}
            \centering
            \begin{tikzpicture}
            \pgfplotsset{compat=1.16}
            \begin{axis}
            [
            width=\linewidth,
            title = {Late Speed Distribution},
            xlabel = {$v$~[m/s]},
            ylabel = {Probability Density},
            ymax=2.6e-4
            ]
            \addplot[ybar, white!45!blue, fill = white!45!blue,bar width=784.7913898303067] table {barSpeeds2.txt};
            \addplot[thick, red, domain=-10500:10500, samples=100]  
            {0.00016312130913239263 * exp(-8.359326130920716e-08*x*x)} 
            node[black, pos = 0.5, anchor=south,yshift=5mm]{$P(v_x) =
            \sqrt{\frac{m}{2\pi\, k_\mathrm{B}\,
            T}}\exp\left(-\frac{1}{2}\frac{m\,v_x^2}{k_\mathrm{B}\,T}\right)$};
            \end{axis}
            \end{tikzpicture}
            \caption{}
           \label{fig:tempProbab}
        \end{subfigure}
        \begin{subfigure}[b]{0.49\textwidth}
            \centering
            \begin{tikzpicture}
            \begin{axis}
            [
            width=\linewidth,
            title = {Temperature Radial Distribution},
            xlabel = $r~\text{[m]}$,
            ylabel = {Temperature~[K]},
            ]
            \addplot [blue,dashed,thick]
            plot [error bars/.cd, y dir = both, y explicit]
            table[y error index=2]{radialT2.txt};
            \end{axis}
            \end{tikzpicture}
            \caption{}
            \label{fig:radialTemp}
        \end{subfigure}
        \caption{Increasing \texttt{ymax} and shifting the node.}
    \end{figure}
\end{document}

Bildbeschreibung hier eingeben

Bildbeschreibung hier eingeben

verwandte Informationen