Posicionando tikzpicture e determinando o intervalo do eixo

Posicionando tikzpicture e determinando o intervalo do eixo

Em outra pergunta recebi grande ajuda para criar esta imagem:

gráfico de barras

Na verdade, parece como deveria, mas há mais duas coisas que gostaria de esclarecer:

Primeiramente, recebo este aviso: Axis range for axis x is approximately empty; enlarging it (it is [0.0:0.0]). Tentei determinar o intervalo, mas não consigo encontrar um valor para xmax que mantenha todas as barras ainda visíveis.

Eem segundo lugar, como posso determinar a posição da imagem? por exemplo, alinhado à esquerda? Quaisquer tentativas com \flushleft e \raggedright terminaram sem sucesso.

Há uma coisa que notei quando pressionei Ctrl + clique \end{axis}: acho que está acontecendo algo errado. Não tenho ideia do que está acontecendo além da fronteira lá...

erro de gráfico 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}

Agradeço qualquer ajuda!

Responder1

Primeiro: você pode ignorar o aviso ou definir xmine xmaxsimétrico para 0. Por exemplo: xmin=-1e xmax=1.

Segundo: A caixa delimitadora da sua imagem é ampliada para a esquerda pelo longo título do enredo. Assim, \raggedrighto título do enredo fica alinhado à esquerda. Então você tem que mudar a posição do título do enredo.

insira a descrição da imagem aqui

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}

Ou se o título do enredo deve ser centralizado no enredoelenda

insira a descrição da imagem aqui

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}

informação relacionada