5

I am trying to plot a set of points with error bars on top of a very dense scatter plot, and the error bars are hidden behind the data as shown in the attached figure.

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
  \begin{semilogyaxis}
    \addplot[blue,mark=x] table [x index=0,y index=1]
      {PSF_blue_0_prof.dat};
    \addplot[green,mark=x, error bars/.cd,y explicit,y dir=both]
      table [x index=0,y index=1,y error index=2]
      {PSF_blue_1.0_prof.dat};
  \end{semilogyaxis}
\end{tikzpicture}

\end{document}

enter image description here

Data files are available here:

The green data points are added in the end using error bars/.cd,y explicit,y dir=both but the error bars appear behind the previous blue and red data. How could I plot the error bars in this figure?

2
  • Can you provide a MWE?
    – percusse
    Commented Aug 27, 2013 at 22:25
  • @percusse I have updated the question
    – gypaetus
    Commented Aug 27, 2013 at 22:40

1 Answer 1

8

Possibility 1: clip mode=individual

You need to set clip mode=individual. The clip modecontrols whether markers are placed on top of everything else (clip mode=global) or are overdrawn by following plots (clip mode=individual). But some parts of the plot can overflow the axis boundaries which may be undesirable. From the pgfplots manual:

The choice global tells pgfplots to install one single clip path for the complete picture. In order to avoid clipped marker paths, any markers are processed after the clip path has been closed, i.e. on a separate layer (see clip marker paths). An unexpected side effect is that marks are on top of plots, even if the plots have been added after the markers. The choice individual instructs pgfplots to install a separate clip path for every \addplot command. Consequently, the plot will be clipped. But most importantly, its markers will be drawn immediately after the clip path has been deactivated.

enter image description here

Possibility 2: clip marker paths=true

Another option is to set clip marker paths=true instead. Then the plot will be clipped by the axis' boundaries. This option prevents an overflow of the plot over the axis' boundaries.

The initial choice clip marker paths=false causes markers to be drawn after the clipped region. Only their positions will be clipped. As a consequence, markers will be drawn completely, or not at all. The value clip marker paths=true is here for backwards compatibility: it does not introduce special marker treatment, so markers may be drawn partially if they are close to the clipping boundary. This key has no effect if clip=false. Note that clip marker paths also acts the sequence in which plots and their markers are drawn on top of each other.

enter image description here

Possibility 3: clip=false

Finally there is also the possibility to set clip=false. Then the entire plot won't be clipped by the axis' boundaries. This feature can be useful if you use only one x and one y axis.

enter image description here

MWE

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
  \begin{semilogyaxis}[
    % clip mode=individual,      % Possibility 1
    % clip marker paths=true,    % Possibility 2
    % clip=false,                % Possibility 3 
    ymin=1e-5
    ]
    \addplot[blue, mark=x] table [x index=0,y index=1]
      {PSF_blue_0_prof.dat};
    \addplot[green,mark=x, error bars/.cd,y explicit,y dir=both]
      table [x index=0,y index=1,y error index=2]
      {PSF_blue_1.0_prof.dat};
  \end{semilogyaxis}
\end{tikzpicture}

\end{document}
4
  • Thanks a lot, I have used clip marker paths because I want to clip the lower part of the plot.
    – gypaetus
    Commented Aug 28, 2013 at 0:17
  • 1
    @MigueldeVal-Borro I've updated my answer.
    – Philipp
    Commented Aug 28, 2013 at 0:31
  • 1
    @MigueldeVal-Borro I've found a third possibility if you want your plot to overflow: clip=false. I've updated my answer a final time to show this too.
    – Philipp
    Commented Aug 28, 2013 at 0:55
  • Thank you for the great answer! it is good to know about the clip options.
    – gypaetus
    Commented Aug 28, 2013 at 1:01

You must log in to answer this question.

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