2

In the following code for a pgfplots bar chart, I use explicit xticklabels because I want simple integer labels, not exponentials or not-quite-right integers derived from them. But that means I also need to specify or adjust the placement of the xtick labels. Using xshift almost solves the problem, but somehow it loses the first tick label --- which should be a 10 under the first group of 3 bars. What's a good fix for this problem?

\documentclass[a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{semilogxaxis}[
        log basis x=4,
        width=10cm,
        xlabel=size of input expressions,
        xticklabels={10,40,160,640,2560},
        x tick label style={xshift=2.5cm},
        xmin=5, xmax=5120,
    ylabel=geo. mean (output-size / input-size),
        yticklabel=\pgfmathprintnumber{\tick}\%,
    enlargelimits=0.05,
    ybar,
]
\addplot 
    coordinates {(10,75.16) (40,76.38)
         (160,76.91) (640,77.35) (2560,77.41)};
\addplot 
    coordinates {(10,65.35) (40,59.68)
         (160,56.85) (640,57.50) (2560,57.01)};
\addplot 
    coordinates {(10,52.48) (40,23.40)
         (160,6.09) (640,1.64) (2560,0.37)};
\legend{std.,fuse,lift}
\end{semilogxaxis}
\end{tikzpicture}
\end{document}
2
  • Do you want the ticks between the bar groups, and the tick labels directly below, or both ticks and ticklabels directly below the bar groups? Aug 3 '20 at 20:00
  • I don't need the xtick marks; I could set draw=none for these. I'd like each label to appear beneath the middle bar in a group of three --- as the labels from 40 do, but the leftmost bar group is currently missing the label 10.
    – Colin R
    Aug 4 '20 at 9:29
1

You really just need to specify the x-values where you want the ticks. Seeings as all five groups are represented in the first \addplot, you can simply add xtick=data to the axis options, and remove the xshift for the labels.

If you want to remove the ticks you can do x tick style={/pgfplots/tickwidth=0}.

enter image description here

\documentclass[a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{semilogxaxis}[
        log basis x=4,
        width=10cm,
        xlabel=size of input expressions,
        xticklabels={10,40,160,640,2560},
        xmin=5, xmax=5120,
        ylabel=geo. mean (output-size / input-size),
        yticklabel=\pgfmathprintnumber{\tick}\%,
        enlargelimits=0.05,
        ybar,
        xtick=data,
        x tick style={/pgfplots/tickwidth=0}
]
\addplot 
    coordinates {(10,75.16) (40,76.38)
         (160,76.91) (640,77.35) (2560,77.41)};
\addplot 
    coordinates {(10,65.35) (40,59.68)
         (160,56.85) (640,57.50) (2560,57.01)};
\addplot 
    coordinates {(10,52.48) (40,23.40)
         (160,6.09) (640,1.64) (2560,0.37)};
\legend{std.,fuse,lift}
\end{semilogxaxis}
\end{tikzpicture}
\end{document}

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.