4

Given a picture like that:

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize
\pgfplotsset{compat=newest}

\pgfplotstableread[col sep=comma]{
netname,index,gxccmean,gxprmean,gxssspmean
COMLJ,1,431.14445,919.70278,266.85096
SOCSINAWEIBO,2,20723.41791,nan,2827.05371
RGGN224S0,3,nan,12293.6209,340.84044
COMORKUT,4,1139.28039,2503.06515,622.09671  
}\realtable


\begin{document}

    \begin{figure}[h]
        \centering
        \begin{tikzpicture}
                \begin{axis}[
                    columns/realname/.style={string type},
                    legend style={at={(1.5,1)},anchor=north},
                    xtick style={draw=none},
                    ybar=0pt,
                    log origin=infty,
                    xtick style={draw=none},
                    xticklabel style={rotate=90,inner sep=0mm},
                    xtick=data,
                    xticklabels from table={\realtable}{netname},
                    ymode=log,
                ]
                    \addplot table [x=index, y=gxccmean] {\realtable};
                    \addlegendentry{Connected Components};
                    \addplot table [x=index, y=gxprmean] {\realtable};
                    \addlegendentry{Page Rank};
                    \addplot table [x=index, y=gxssspmean] {\realtable};
                    \addlegendentry{Single Source Shortest Paths};
                \end{axis}
        \end{tikzpicture}
    \end{figure}

\end{document}

Whenever "gxccmean" y value is NaN, the xticklabels are not plotted. It seems that pgfplots only considers the first addplot in order to plot the tick labels. If I change the order of addplot table commands, the label is placed correctly (the y value for the second addplot is not NaN). Moreover, pgfplots shifts the label to the tick at the right side.

I'd not like to change the order of addplots. Thus, I wonder whether there is a way to force the xticklabels plotting:

enter image description here

4
  • Hi Daniel, welcome to the site! There are a couple of ways to fix this, but which one works best depends on your setup. Could you include the necessary parts of your generalfigures2 style and a dummy data file that's set up the same way as your proper data file. Also, as Kurt says, it's always best to post a complete but minimal example document (starting from \documentclass) that people can just compile straight away, without having to fill in the blanks themselves.
    – Jake
    May 20 '16 at 19:13
  • I posted a compilable code snippet.
    – Daniel
    May 20 '16 at 20:07
  • Will your data always be sorted according to the index column? Does your index column always start at 1, and will it always be "gapless"?
    – Jake
    May 20 '16 at 20:44
  • Yes to all questions.
    – Daniel
    May 20 '16 at 20:52
2

If your data is going to be plotted in the order that it appears in the table and the index column is not used to adjust the order or position of the bars, you can simply use

xtick = {1,...,20}

where 20 is just an arbitrary number that's greater than the number of rows in your table. This will generate a tick position at every integer value of x between 1 and 20.

Note that in this case, you could also do away with the index column entirely, and use \addplot table [x expr=\coordindex] {...} to generate the x positions automatically.

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize
\pgfplotsset{compat=newest}

\pgfplotstableread[col sep=comma]{
netname,index,gxccmean,gxprmean,gxssspmean
COMLJ,1,431.14445,919.70278,266.85096
SOCSINAWEIBO,2,20723.41791,nan,2827.05371
RGGN224S0,3,nan,12293.6209,340.84044
COMORKUT,4,1139.28039,2503.06515,622.09671  
}\realtable


\begin{document}

    \begin{figure}[h]
        \centering
        \begin{tikzpicture}
                \begin{axis}[
                    columns/realname/.style={string type},
                    legend style={at={(1.5,1)},anchor=north},
                    xtick style={draw=none},
                    ybar=0pt,
                    log origin=infty,
                    xtick style={draw=none},
                    xticklabel style={rotate=90,inner sep=0mm},
                    xtick={1,...,20},
                    xticklabels from table={\realtable}{netname},
                    ymode=log,
                ]
                    \addplot table [x=index, y=gxccmean] {\realtable};
                    \addlegendentry{Connected Components};
                    \addplot table [x=index, y=gxprmean] {\realtable};
                    \addlegendentry{Page Rank};
                    \addplot table [x=index, y=gxssspmean] {\realtable};
                    \addlegendentry{Single Source Shortest Paths};
                \end{axis}
        \end{tikzpicture}
    \end{figure}

\end{document}
0

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.