3

I got 2 erros with the code below.

  • Package PGF Math Error: Unknown function `Criadas' (in 'Criadas').
  • Package PGF Math Error: Sorry, an internal routine of the floating point unit got an ill-formatted floating point number `0'. The unreadable part was near '0'.
\begin{figure}
    \centering
    \caption{Total de Ideias Legislativas}
    \label{fig:ideia-total}
    \begin{tikzpicture}
      \begin{axis}[
          width=12cm,
          height=8cm,
          ybar,
          bar width=1.2cm,
          enlarge x limits=0.1,
          major x tick style = transparent,
          symbolic x coords={Criadas,Debatidas,Projetos de Lei,Leis},
          xtick=data,
          ymajorgrids = true,
          ylabel={Ideias Legislativas},
          scaled y ticks=false,
          ymin=0,
          ymax=100
        ]

        \addplot [gray, fill]
          coordinates {
            (Criadas,100)
            (Debatidas,78)
            (Projetos de Lei,25)
            (Leis,1)
          };
        \draw [->, thick, white, xshift=-.2cm] (Criadas,90) -- (Criadas,100)
          node [pos=0, rotate=90, anchor=east] {\(73.003\)};
      \end{axis}
    \end{tikzpicture}
\end{figure}

2 Answers 2

3

Welcome! If you supply the coordinates in the \draw path with axis cs:, it works.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{figure}
    \centering
    \caption{Total de Ideias Legislativas.}
    \label{fig:ideia-total}
    \begin{tikzpicture}
      \begin{axis}[
          width=12cm,
          height=8cm,
          ybar,
          bar width=1.2cm,
          enlarge x limits=0.1,
          major x tick style = transparent,
          symbolic x coords={Criadas,Debatidas,Projetos de Lei,Leis},
          xtick=data,
          ymajorgrids = true,
          ylabel={Ideias Legislativas},
          scaled y ticks=false,
          ymin=0,
          ymax=100
        ]

        \addplot[gray, fill]
          coordinates {
            (Criadas,100)
            (Debatidas,78)
            (Projetos de Lei,25)
            (Leis,1)
          };
        \draw [->, thick, white, xshift=-.2cm] 
        (axis cs:Criadas,90) -- (axis cs:Criadas,100)
          node [pos=0, rotate=90, anchor=east] {\(73.003\)};
      \end{axis}
    \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

You can also use the normalized key and use numeric coordinates instead. This key accepts fractional coordinates, too.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{figure}
    \centering
    \caption{Total de Ideias Legislativas.}
    \label{fig:ideia-total}
    \begin{tikzpicture}
      \begin{axis}[
          width=12cm,
          height=8cm,
          ybar,
          bar width=1.2cm,
          enlarge x limits=0.1,
          major x tick style = transparent,
          symbolic x coords={Criadas,Debatidas,Projetos de Lei,Leis},
          xtick=data,
          ymajorgrids = true,
          ylabel={Ideias Legislativas},
          scaled y ticks=false,
          ymin=0,
          ymax=100
        ]

        \addplot[gray, fill]
          coordinates {
            (Criadas,100)
            (Debatidas,78)
            (Projetos de Lei,25)
            (Leis,1)
          };
        \draw [->, thick,white] 
        (axis cs:{[normalized]0},90) -- (axis cs:{[normalized]0},100)
          node [pos=0, rotate=90, anchor=east] {\(73.003\)};          
      \end{axis}
    \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

Note that I have randomly added versions 1.16 or 1.17, depending on which installation you use you may need to change \pgfplotsset{compat=1.17} to \pgfplotsset{compat=newest}, say.

0

There is no need for the \draw command. You can also add a pin (with the desired options) to achieve what you want ...

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        width=12cm,
        height=8cm,
        ybar,
        bar width=1.2cm,
        enlarge x limits=0.1,
        major x tick style = transparent,
        symbolic x coords={Criadas,Debatidas,Projetos de Lei,Leis},
        xtick=data,
        ymajorgrids = true,
        ylabel={Ideias Legislativas},
        scaled y ticks=false,
        ymin=0,
        ymax=100,
    ]

        \addplot [gray, fill] coordinates {
            (Criadas,100)
            (Debatidas,78)
            (Projetos de Lei,25)
            (Leis,1)
        }
            node [
                at start,
                coordinate,
                pin={
                    [%
                        pin edge={
                            white,
                            thick,
                            <-,
                        },
                        white,
                        rotate=90,
                    ]
                    left:{\pgfmathprintnumber{73003}}
                },
            ] {}
        ;
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .