5

I basically want to duplicate a curve and draw the exact same curve, with markers, at another location. I figured I could do this with the shift command, but it doesn't turn out the way I thought. When I use shift, the curve and the markers no longer overlap (see pic). Neither the curve nor the markers seem to be in the correct place. (The markers are almost correct, but are shifted down slightly for some reason.)

Any ideas?

code:

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}

\begin{filecontents}{branches-bpcu.dat}
L c1
1 0.0106891 
2 0.058871
3 0.0993073
4 0.126898
5 0.147865
6 0.162113
7 0.174859
8 0.184307
9 0.191817
10 0.198146
11 0.204505
12 0.210035
13 0.215313
14 0.218655
15 0.222387
16 0.225159
17 0.227173
18 0.230822
19 0.232982
20 0.234931
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}[]
\def\myplot{\addplot[mark=o,solid] table[x=L,y=c1] {branches-bpcu.dat};}
\myplot
\begin{scope}[
%           xshift=5,
            shift={(axis cs:5,0)},
            ]
    \myplot
\end{scope}
\end{axis}
\end{tikzpicture}%
\end{document}

enter image description here

1 Answers1

6

You could plot the same thing twice, but instead of x=L, use x expr=\thisrow{L}+5 for the second plot.

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}

\begin{filecontents}{branches-bpcu.dat}
L c1
1 0.0106891 
2 0.058871
3 0.0993073
4 0.126898
5 0.147865
6 0.162113
7 0.174859
8 0.184307
9 0.191817
10 0.198146
11 0.204505
12 0.210035
13 0.215313
14 0.218655
15 0.222387
16 0.225159
17 0.227173
18 0.230822
19 0.232982
20 0.234931
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}[]
\addplot[mark=o,solid] table[x=L,y=c1] {branches-bpcu.dat};
\addplot[mark=o,solid] table[x expr=\thisrow{L}+5,y=c1] {branches-bpcu.dat};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Torbjørn T.
  • 206,688
  • Yes, I think this will work for me. If anyone is wondering why I'd want to do this, I'm trying to do similar things to http://tex.stackexchange.com/questions/116637/rectangular-spy-in-pgfplots-without-scaling and http://tex.stackexchange.com/questions/59036/using-tikzlibrary-spy-without-magnifying-line-width-and-or-mark-size . But the techniques in those posts didn't work out when I used markers. (I still think it is weird that shift doesn't shift markers and curves the same. But maybe I'm just not getting exactly what shift is supposed to do) – Vanligvodka Feb 26 '17 at 09:24
  • @Vanligvodka I don't think you've misunderstood shift, but it probably doesn't work properly in an axis environment because of the scaling (or something) done by pgfplots. – Torbjørn T. Feb 26 '17 at 09:27