3

I've currently got several figures indicating how many people have a certain amount of annotations. The first figure below, for example, shows that 55,981 people have no annotations, 13,236 have 1 annotation, 51,419 have between 1 and 10 annotations, et cetera.

Example figures

Because the bars and the corresponding node coords are directly above the tick the fact that these bins are between two values is not immediately obvious. What I've been trying to do is to move these bars and nodes (/labels) to the left. The sample below (pardon the ASCII) illustrates what I mean. Everything is shifted to the left, and an extra tick is added at the start (possibly without value if it's below 0, and otherwise the previous bin).

    55k           51k
    ----          ----
    |  |   13k    |  |
    |  |   ----   |  |
  , |  | , |  | , |  | ,
         0     10    10^2

            55
           ----    37
     6     |  |   ----
    ----   |  |   |  |
  , |  | , |  | , |  | ,
10^5   10^6   10^7   10^8

Unfortunately at the moment I have no idea how to achieve this. I've tried variations like using an interval to get it to show at the right spot, however this would appear to make the bar width inconsistent over graphs, and the labels at the top of the bars would still appear right above the tick (although they can be manually moved with something like every node near coord/.append style={xshift=13pt}, but this would have to be tweaked for every figure).

Does anyone have a suggestion how to get this to look right?

The latex below was used to generate the previously shown figures.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{geometry}
\geometry{a4paper}
\pgfplotsset{compat=1.12}
\begin{document}
    \begin{figure}[!ht]
        \centering
        \caption{Distribution of person annotations over different bins}
        \label{fig:facc1-person-dist}
        \begin{tikzpicture}
            \begin{axis}[
                ybar = 0.5,
                height=0.3\textheight,
                width=\columnwidth,
                ymin=0,
                symbolic x coords={$0$, $1$, $10$, $10^2$, $10^3$, $10^4$, $10^5$, $10^6$, $10^7$, $10^8$},
                bar width=26pt,
                ylabel={Number of persons},
                xlabel={Number of annotations},
                nodes near coords,
                every node near coord/.append style={font=\footnotesize},
                axis lines*=left,
                % Hide y indicators
                y axis line style={opacity=0},
                yticklabels={\empty},
                ytick style={draw=none},
                xtick=data
            ]
                \addplot[fill=black!20,draw=black!60] coordinates {($0$, 55981) ($1$, 13236) ($10$, 51419) ($10^2$, 107296) ($10^3$, 107378) ($10^4$, 42463) ($10^5$, 7150) ($10^6$, 475) ($10^7$, 26) ($10^8$, 2)};
            \end{axis}
        \end{tikzpicture}
    \end{figure}
    \begin{figure}[!ht]
        \centering
        \caption{Distribution of FRANK1 nationality annotations over different bins}
        \label{fig:frank1-nationality-dist}
        \begin{tikzpicture}
            \begin{axis}[
                ybar = 0.5,
                height=0.3\textheight,
                width=\columnwidth,
                ymin=0,
                symbolic x coords={$10^6$, $10^7$, $10^8$, $10^9$},
                bar width=26pt,
                ylabel={Number of persons},
                xlabel={Number of annotations},
                nodes near coords,
                every node near coord/.append style={font=\footnotesize},
                axis lines*=left,
                % Hide y indicators
                y axis line style={opacity=0},
                yticklabels={\empty},
                ytick style={draw=none},
                xtick=data
            ]
                \addplot[fill=black!20,draw=black!60] coordinates {($10^6$, 6) ($10^7$, 55) ($10^8$, 37) ($10^9$, 2)};
            \end{axis}
        \end{tikzpicture}
    \end{figure}
\end{document}
3

You need to use numeric coordinates, not symbolic ones. Then you can use xticklabels to provide the textual labels. Change your coordinates to {(0,6) (1,55), ...}. Add xmin and xmax to get the axis long enough and may be enlarge x limits for some additional space. Finially, adding bar shift=0.5 moves the bar where you want them.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{geometry}
\geometry{a4paper}
\pgfplotsset{compat=1.12}
\begin{document}
    \begin{figure}[!ht]
        \centering
        \caption{Distribution of person annotations over different bins}
        \label{fig:facc1-person-dist}
        \begin{tikzpicture}
            \begin{axis}[
                ybar = 0.5,
                height=0.3\textheight,
                width=\columnwidth,
                ymin=0,
                % added
                xmin=0, xmax=10,
                enlarge x limits=0.05,
                % changed from symbolic x coords to this
                xticklabels={$0$, $1$, $10$, $10^2$, $10^3$, $10^4$, $10^5$, $10^6$, $10^7$, $10^8$},
                bar width=26pt,
                % added
                bar shift=0.5,
                ylabel={Number of persons},
                xlabel={Number of annotations},
                nodes near coords,
                every node near coord/.append style={font=\footnotesize},
                axis lines*=left,
                % Hide y indicators
                y axis line style={opacity=0},
                yticklabels={\empty},
                ytick style={draw=none},
                xtick=data
            ]
                % changed coordinates from {($0$,55981) ($10$,13236) ...}
                \addplot[fill=black!20,draw=black!60] coordinates {(0, 55981) (1, 13236) (2, 51419) (3, 107296) (4, 107378) (5, 42463) (6, 7150) (7, 475) (8, 26) (9, 2)};
            \end{axis}
        \end{tikzpicture}
    \end{figure}
    \begin{figure}[!ht]
        \centering
        \caption{Distribution of FRANK1 nationality annotations over different bins}
        \label{fig:frank1-nationality-dist}
        \begin{tikzpicture}
            \begin{axis}[
                ybar = 0.5,
                height=0.3\textheight,
                width=\columnwidth,
                ymin=0,
                xmin=0, xmax=4,
                enlarge x limits=0.05,
                xticklabels={$10^6$, $10^7$, $10^8$, $10^9$},
                bar width=26pt,
                bar shift=0.5,
                ylabel={Number of persons},
                xlabel={Number of annotations},
                nodes near coords,
                every node near coord/.append style={font=\footnotesize},
                axis lines*=left,
                % Hide y indicators
                y axis line style={opacity=0},
                yticklabels={\empty},
                ytick style={draw=none},
                xtick=data
            ]
                \addplot[fill=black!20,draw=black!60] coordinates {(0, 6) (1, 55) (2, 37) (3, 2)};
            \end{axis}
        \end{tikzpicture}
    \end{figure}
\end{document}

enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.