Posicionamiento de tikzpicture y determinación del rango para el eje

Posicionamiento de tikzpicture y determinación del rango para el eje

En otra pregunta recibí gran ayuda para crear esta imagen:

diagrama de barras

En realidad se ve como debería, pero hay dos cosas más que me gustaría aclarar:

En primer lugar, recibo esta advertencia: Axis range for axis x is approximately empty; enlarging it (it is [0.0:0.0]). Intenté determinar el rango, pero no puedo encontrar un valor para xmax que mantenga todas las barras aún visibles.

Yen segundo lugar, ¿cómo puedo determinar la posición de la imagen? por ejemplo, ¿alineado a la izquierda? Cualquier intento con \flushleft y \raggedright finalizó sin éxito.

Hay una cosa que noté cuando hice Ctrl+clic \end{axis}: Supongo que algo está sucediendo mal. No tengo idea de lo que sucede más allá de la frontera allí...

error de diagrama de barras

\documentclass[paper=a4, parskip=half-, draft]{scrreprt}

\tolerance=2000
\emergencystretch=1em
\hfuzz=2pt
\usepackage[ngerman]{babel} 
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{shapes,arrows,positioning,shadows,trees}
\pgfplotsset{compat=1.7}    %bestimmt exakte version zur gleichen

\setlength{\parindent}{0pt}
\begin{document}
        \begin{figure}[!h]
            \begin{tikzpicture}[scale=0.8]
            \begin{axis}[
            title=\textbf{Aus welchen Gründen wurde eLearning in Ihrem Klinikum implementiert?},
            ybar=15,            %Abstand zwischen den Balken
            ymin=0,
            ymax=50,            %maximale Diagrammhöhe
            xmin=0,
            xmax=,
            %ymajorgrids,       %Horizontale Guidelines
            bar width=30pt,     %Balkenbreite
            xtick=\empty,       %keine kleinen Striche auf x achse
            nodes near coords={\pgfmathprintnumber\pgfplotspointmeta \%},           %Fügt Prozent an
            nodes near coords align={vertical},
            legend style={
                legend pos=outer north east,
                row sep=10pt,
                /tikz/nodes={text width=135pt,text depth=}
            }]

            \addplot coordinates{(0,31.1)};
            \addlegendentry{Aufgrund der gesetzlichen Nachweispflicht (Brandschutz, Arbeitsschutz, etc.)}

            \addplot coordinates{ (0,17.8)};
            \addlegendentry{Einweisung zur Nutzung medizinischer Geräte}

            \addplot coordinates{ (0,44.4)};
            \addlegendentry{Zur generellen zeit- und ortsungebundenen Weiterbildung von Mitarbeitern}

            \addplot coordinates{ (0,6.7)};
            \addlegendentry{Sonstige}

            \end{axis}
            \end{tikzpicture}
        \end{figure}

\end{document}

¡Agradezco cualquier ayuda!

Respuesta1

Primero: puede ignorar la advertencia o configurarlo xminde xmaxforma simétrica 0. Por ejemplo: xmin=-1y xmax=1.

Segundo: el cuadro delimitador de su imagen se amplía hacia la izquierda por el título largo de la trama. Entonces, \raggedrightel título de la trama está alineado a la izquierda. Entonces tienes que cambiar la posición del título de la trama.

ingrese la descripción de la imagen aquí

Código:

\documentclass[paper=a4, parskip=half-, draft]{scrreprt}
\usepackage{showframe}% show the page layout

\usepackage[ngerman]{babel} 
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{pgfplots}
\pgfplotsset{compat=1.7}    %bestimmt exakte version zur gleichen

%\setlength{\parindent}{0pt}% <- not needed because you use parskip=half- option
\begin{document}
\begin{figure}[!h]
    \begin{tikzpicture}[scale=0.8]
    \begin{axis}[
    title=\textbf{Aus welchen Gründen wurde eLearning in Ihrem Klinikum implementiert?},
    title style={at={(0,1)},anchor=south west,inner xsep=0pt},% <- added
    ybar=15,            %Abstand zwischen den Balken
    ymin=0,
    ymax=50,            %maximale Diagrammhöhe
    xmin=-1,% <-changed
    xmax=1,% <- changed
    %ymajorgrids,       %Horizontale Guidelines
    bar width=30pt,     %Balkenbreite
    xtick=\empty,       %keine kleinen Striche auf x achse
    nodes near coords={\pgfmathprintnumber\pgfplotspointmeta \%},           %Fügt Prozent an
    nodes near coords align={vertical},
    legend style={
        legend pos=outer north east,
        row sep=10pt,
        /tikz/nodes={text width=135pt,text depth=}
    }]

    \addplot coordinates{(0,31.1)};
    \addlegendentry{Aufgrund der gesetzlichen Nachweispflicht (Brandschutz, Arbeitsschutz, etc.)}

    \addplot coordinates{ (0,17.8)};
    \addlegendentry{Einweisung zur Nutzung medizinischer Geräte}

    \addplot coordinates{ (0,44.4)};
    \addlegendentry{Zur generellen zeit- und ortsungebundenen Weiterbildung von Mitarbeitern}

    \addplot coordinates{ (0,6.7)};
    \addlegendentry{Sonstige}

    \end{axis}
    \end{tikzpicture}
\end{figure}
\end{document}

O si el título de la trama debería estar centrado en la trama.yleyenda

ingrese la descripción de la imagen aquí

Código:

\documentclass[paper=a4, parskip=half-, draft]{scrreprt}
\usepackage{showframe}% show the page layout

\usepackage[ngerman]{babel} 
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{pgfplots}
\pgfplotsset{compat=1.7}    %bestimmt exakte version zur gleichen

%\setlength{\parindent}{0pt}% <- not needed because you use parskip=half- option
\begin{document}
\begin{figure}[!h]
    \begin{tikzpicture}[scale=0.8]
    \begin{axis}[
    %title=\textbf{Aus welchen Gründen wurde eLearning in Ihrem Klinikum implementiert?},% <- removed
    ybar=15,            %Abstand zwischen den Balken
    ymin=0,
    ymax=50,            %maximale Diagrammhöhe
    xmin=-1,% <-changed
    xmax=1,% <- changed
    %ymajorgrids,       %Horizontale Guidelines
    bar width=30pt,     %Balkenbreite
    xtick=\empty,       %keine kleinen Striche auf x achse
    nodes near coords={\pgfmathprintnumber\pgfplotspointmeta \%},           %Fügt Prozent an
    nodes near coords align={vertical},
    legend style={
        legend pos=outer north east,
        row sep=10pt,
        /tikz/nodes={text width=135pt,text depth=}
    }]

    \addplot coordinates{(0,31.1)};
    \addlegendentry{Aufgrund der gesetzlichen Nachweispflicht (Brandschutz, Arbeitsschutz, etc.)}

    \addplot coordinates{ (0,17.8)};
    \addlegendentry{Einweisung zur Nutzung medizinischer Geräte}

    \addplot coordinates{ (0,44.4)};
    \addlegendentry{Zur generellen zeit- und ortsungebundenen Weiterbildung von Mitarbeitern}

    \addplot coordinates{ (0,6.7)};
    \addlegendentry{Sonstige}

    \end{axis}
    \node[anchor=south,font=\bfseries\footnotesize]at (current bounding box.north){Aus welchen Gründen wurde eLearning in Ihrem Klinikum implementiert?};% <- added
    \end{tikzpicture}
\end{figure}
\end{document}

información relacionada