2

When tweaking some axis options, I found this strange behaviour. When setting both bar width and bar shift auto without units, the bar are positionned incorrectly. There is no warning or error message in the log.

Is this really a bug, or do I miss something here ?

% arara: pdflatex
\documentclass[tikz]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{times}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[width=7cm,height=7cm,bar shift auto=0pt]
        \addplot[ybar, bar width=1, fill=blue] coordinates {(10,5) (15,10) (5,15) (24,20) (30,25)};
        \addplot[ybar, bar width=1, fill=red]  coordinates {(10,5) (15,10) (5,15) (24,20) (30,25)};
        \node[anchor=north west] at (rel axis cs:0,1) {bar shift auto=0pt,bar width=1};
    \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
    \begin{axis}[width=7cm,height=7cm,bar shift auto=0]
        \addplot[ybar, bar width=1, fill=blue] coordinates {(10,5) (15,10) (5,15) (24,20) (30,25)};
        \addplot[ybar, bar width=1, fill=red]  coordinates {(10,5) (15,10) (5,15) (24,20) (30,25)};
        \node[anchor=north west] at (rel axis cs:0,1) {bar shift auto=0,bar width=1};
    \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
    \begin{axis}[width=7cm,height=7cm,bar shift auto=0pt]
        \addplot[ybar, bar width=5pt, fill=blue] coordinates {(10,5) (15,10) (5,15) (24,20) (30,25)};
        \addplot[ybar, bar width=5pt, fill=red]  coordinates {(10,5) (15,10) (5,15) (24,20) (30,25)};
        \node[anchor=north west] at (rel axis cs:0,1) {bar shift auto=0pt,bar width=5pt};
    \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
    \begin{axis}[width=7cm,height=7cm,bar shift auto=0]
        \addplot[ybar, bar width=5pt, fill=blue] coordinates {(10,5) (15,10) (5,15) (24,20) (30,25)};
        \addplot[ybar, bar width=5pt, fill=red]  coordinates {(10,5) (15,10) (5,15) (24,20) (30,25)};
        \node[anchor=north west] at (rel axis cs:0,1) {bar shift auto=0,bar width=5pt};
    \end{axis}
\end{tikzpicture}%
\end{document}

enter image description here

6
  • 1
    No problem, modifications are done – BambOo Sep 6 '19 at 19:22
  • Generally I would say that bar shift auto expects a length. Thus I guess you are lucky when stating 0 works. When you really want to know if this is a bug I recommend adding a bug to the PGFPlots Tracker. – Stefan Pinnow Sep 6 '19 at 19:58
  • @StefanPinnow I do not agree that bar shift auto expects a length. It may expect a length, but the way it it used is not that specific. If you look at the pgfplots manual it is used to define the bar shift based on this expression n·bar width+(n−1)·<shift for multiple plots>, where bar width may not have a unit, hence my example. bar width should be <dimension or unit>, which is much more specific thant <shift for multiple plots> by the way. – BambOo Sep 7 '19 at 1:21
  • @StefanPinnow Regarging the bug, my little experience here has taught me that something that seems to be a bug is often just a misunderstanding of the use of a functionnality. Asking first here seems about right in such situations. – BambOo Sep 7 '19 at 1:25
  • Reading the related manual parts (again) you may be right. It is not explicitly written what a valid input is. The only thing that is clear is that a length is a valid input because of the default value of 2pt. Thus, my suggestion with the Tracker still holds in case you question isn't answered here satisfyingly. – Stefan Pinnow Sep 7 '19 at 5:31

Your Answer

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

Browse other questions tagged or ask your own question.