5

In this TUGBoat article the author show how to implement tufte style plots with pgfplots.

Currently I am working with Lualatex,texlive 2015.

In the following MWE I implemented the idea from the paper. However, it happens sometimes that I would like to fix the xmin,xmax ymax and ymin of the plot, keeping the axis length given by data@xmin,data@xmax etc . However the following behaviour is observed:

  1. If only data with error bars is plotted the result is good (in the MWE, comment out the second plot).
  2. If only data without errors bar is plotted, the compilation takes forever and never stops. (in the MWE comment out the first plot)

  3. If plotted together, the code works but for the black-axis length are wrong, as you can see in the picture. The y black line should go up to ymax of the red line, and similarly with the x-line.

MWE

How can I solve 2. and 3.?

MWE:

\documentclass{standalone}
\usepackage{verbatim}
\usepackage{pgfplots}
\usepackage{lmodern}
\pgfplotsset{compat = newest}

\pgfplotsset{
  every axis legend/.append style =
    {
      cells = { anchor = east },
      draw  = none
    },
}

\makeatletter
\pgfplotsset{
  tufte axes/.style =
    {
      after end axis/.code =
        {
          \draw ({rel axis cs:0,0} -| {axis cs:\pgfplots@data@xmin,0})      -- ({rel axis cs:0,0}  -| {axis cs:\pgfplots@data@xmax,0});
          \draw ({rel axis cs:0,0} |- {axis cs:0,\pgfplots@data@ymin})            -- ({rel axis cs:0,0}  |-{axis cs:0,\pgfplots@data@ymax});
                 },
      axis line style = {draw = none},
      tick align      = outside,
      tick pos        = left
    },
}
\makeatother


\begin{document}


\begin{tikzpicture}


\pgfplotsset{every axis plot post/.append style={mark=none}}
\pgfplotsset{every axis plot post/.append style={line width=1.pt}}
\begin{axis}[tufte axes,ylabel near ticks,scaled y ticks=false,ymajorgrids,unbounded coords=jump,legend pos= outer north east,legend style={font=, line width=1.pt}, xmin=6.,xmax=11,ymin=5000,ymax=7000,
xlabel={x},
ylabel={y},]
%
\addplot+[thick,mark size=2,error bars/.cd,y dir=both,y explicit]
coordinates {

(7.846, 5614.5) +- (110., 110.)
(8.096, 5530.) +- (69., 69.)
(8.65, 5442.) +- (57., 57.)
};
\addlegendentry{a}

\addplot+[thick,mark=none]
coordinates {
(7.5, 6319.2)
(9.03, 5996.6)
};
\addlegendentry{b}
\end{axis}
\end{tikzpicture}
\end{document}
1

Not a real answer, but a workaround.

Using

\pgfplotsset{error bars/.cd,error mark=none,y dir=both}

It forces pgfplots to plot an invisible error bar, so that it doesn't hang indefinitely and calculate the correct xmin,xmax. Then, the real error bar plot should contain error mark=- in the options.

Correct result:

enter image description here

Full code

\documentclass{standalone}
\usepackage{verbatim}
\usepackage{pgfplots}
\usepackage{lmodern}
\pgfplotsset{compat = newest}

\pgfplotsset{
  every axis legend/.append style =
    {
      cells = { anchor = east },
      draw  = none
    },
}

\makeatletter
\pgfplotsset{
  tufte axes/.style =
    {
      after end axis/.code =
        {
          \draw ({rel axis cs:0,0} -| {axis cs:\pgfplots@data@xmin,0})      -- ({rel axis cs:0,0}  -| {axis cs:\pgfplots@data@xmax,0});
          \draw ({rel axis cs:0,0} |- {axis cs:0,\pgfplots@data@ymin})            -- ({rel axis cs:0,0}  |-{axis cs:0,\pgfplots@data@ymax});
                 },
      axis line style = {draw = none},
      tick align      = outside,
      tick pos        = left
    },
}
\makeatother


\begin{document}


\begin{tikzpicture}

\pgfplotsset{error bars/.cd,error mark=none,y dir=both}
\pgfplotsset{every axis plot post/.append style={mark=none}}
\pgfplotsset{every axis plot post/.append style={line width=1.pt}}
\begin{axis}[tufte axes,ylabel near ticks,scaled y ticks=false,ymajorgrids,unbounded coords=jump,legend pos= outer north east,legend style={font=, line width=1.pt}, xmin=6.,xmax=11,ymin=5000,ymax=7000,
xlabel={x},
ylabel={y},]
%
\addplot+[thick,mark size=2,error bars/.cd,y dir=both,y explicit,error mark=- ]
coordinates {

(7.846, 5614.5) +- (110., 110.)
(8.096, 5530.) +- (69., 69.)
(8.65, 5442.) +- (57., 57.)
};
\addlegendentry{a}

\addplot+[thick,mark=none]
coordinates {
(7.5, 6319.2)
(9.03, 5996.6)
};
\addlegendentry{b}
\end{axis}
\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.