1

I'm trying to draw a horizontal histogram, but I struggle to hide the last two nodes near the coordinates. I want the y-axis showing a tick also at >1000.0ms, but I don't want ot show a value for it.

How do I hide both top zeros on the y-axis? Any trick is very welcome, including changing the data.

My code so far:

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{filecontents*}{data}
    index;ytl;ms
    1;$<1.0$\,ms;4.2
    2;$1.1-100.9$\,ms;83.8
    3;$101.0-200.8$\,ms;6.9
    4;$200.9-300.7$\,ms;1.7
    5;$300.8-400.6$\,ms;0.8
    6;$400.7-500.5$\,ms;0.5
    7;$500.6-600.4$\,ms;0.4
    8;$600.5-700.3$\,ms;0.3
    9;$700.4-800.3$\,ms;0.2
    10;$800.3-900.1$\,ms;0.2
    11;$900.2-1000.0$\,ms;1.1
    12;$>1000.0$\,ms;0
    13;;0
    }
\end{filecontents*}

\pgfplotstableread[col sep=semicolon]{data}{\mytable}

\begin{tikzpicture}
        \begin{axis}[
            every node near coord/.append style={yshift=7pt},
            grid=none,
                axis lines=left,
                xlabel=percentage,
                xbar interval,
            x=0.1cm,    
                xlabel style={yshift=-0.5cm},
            x tick label style={%
                /pgf/number format/.cd,
                fixed,
                fixed zerofill,
                precision=1,
                /tikz/.cd
            },
            xticklabel={$\pgfmathprintnumber{\tick}$\%},
            xmax=100,
            nodes near coords={\pgfkeys{/pgf/fpu}\pgfmathparse{\pgfplotspointmeta}\pgfmathprintnumber{\pgfmathresult}\,\%},
            max space between ticks=100,
                ymax=13,
            ymin=1,
                yticklabels from table={\mytable}{ytl},
                title=distribution,
                bar width=14pt,
        ]

        \addplot table [x=ms, y=index] {\mytable};
    \end{axis}

\end{tikzpicture}

\end{document}

My result:

enter image description here

1 Answer 1

1

You can use conditional formatting. As there is no text=none (like draw=none or fill=none), I use opacity=0.

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{filecontents*}{data}
    index;ytl;ms
    1;$<1.0$\,ms;4.2
    2;$1.1-100.9$\,ms;83.8
    3;$101.0-200.8$\,ms;6.9
    4;$200.9-300.7$\,ms;1.7
    5;$300.8-400.6$\,ms;0.8
    6;$400.7-500.5$\,ms;0.5
    7;$500.6-600.4$\,ms;0.4
    8;$600.5-700.3$\,ms;0.3
    9;$700.4-800.3$\,ms;0.2
    10;$800.3-900.1$\,ms;0.2
    11;$900.2-1000.0$\,ms;1.1
    12;$>1000.0$\,ms;0
    13;;0
    }
\end{filecontents*}

\pgfplotstableread[col sep=semicolon]{data}{\mytable}

\begin{tikzpicture}
        \begin{axis}[
            every node near coord/.append style={yshift=7pt},
            grid=none,
                axis lines=left,
                xlabel=percentage,
                xbar interval,
            x=0.1cm,    
                xlabel style={yshift=-0.5cm},
            x tick label style={%
                /pgf/number format/.cd,
                fixed,
                fixed zerofill,
                precision=1,
                /tikz/.cd
            },
            xticklabel={$\pgfmathprintnumber{\tick}$\%},
            xmax=100,
            nodes near coords={\pgfkeys{/pgf/fpu}\pgfmathparse{\pgfplotspointmeta}\pgfmathprintnumber{\pgfmathresult}\,\%},
            max space between ticks=100,
                ymax=13,
            ymin=1,
                yticklabels from table={\mytable}{ytl},
                title=distribution,
                bar width=14pt,
        ]

        \addplot+[coordinate style/.condition={x==0}{opacity=0}] table [x=ms, y=index] {\mytable};
    \end{axis}

\end{tikzpicture}

\end{document}

Horizontal bar graph

1

You must log in to answer this question.

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