3

I am currently trying to create a plot with pgfplots and can't seem to properly position the y axis like I want to. Here's my MWE:

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{ticks=minor,grid style={dotted,gray},compat=newest,extra tick style={grid=major}}

\pgfdeclareplotmark{ball}{%
    \shade[draw=none,ball color=red] (0,0) circle (\pgfplotmarksize);
  }

\usetikzlibrary{decorations.markings}
\tikzset{
    set arrow inside/.code={\pgfqkeys{/tikz/arrow inside}{#1}},
    set arrow inside={end/.initial=>, opt/.initial=},
    /pgf/decoration/Mark/.style={
        mark/.expanded=at position #1 with
        {
            \noexpand\arrow[\pgfkeysvalueof{/tikz/arrow inside/opt}]{\pgfkeysvalueof{/tikz/arrow inside/end}}
        }
    },
    arrow inside/.style 2 args={
        set arrow inside={#1},
        postaction={
            decorate,decoration={
                markings,Mark/.list={#2}
            }
        }
    },
}

\begin{document}

\def\length{sqrt(4*x^2+(x-y)^2)}

\begin{tikzpicture}

\begin{axis}[%
axis lines=left,
grid=minor,
height=8cm,
width=15cm,
domain=-1:1,
view={30}{70},
xlabel={$s$},
ylabel={$\overline{s}$},
zlabel={$e$},
xmin=-1,
xmax=1,
yticklabels={\empty},
zticklabels={\empty},
extra x ticks={-1,0,1},
extra y ticks={-1,0,1},
extra z ticks={0.05,0.1},
ymin=-1,
ymax=1,
zmin=0,
zmax=0.1,
restrict x to domain = -1:1,
restrict y to domain = -1:1,
axis line style = {-latex},
every axis x label/.style={
    at={(ticklabel* cs:1)},
    anchor=north
},
every axis y label/.style={
    at={(ticklabel* cs:1)},
    anchor=south,
},
every axis z label/.style={
    at={(ticklabel* cs:1)},
    anchor=south,
}
]

\addplot3[area legend,solid,fill=black,fill opacity=0.05,draw opacity=0,forget plot]
table[row sep=crcr] {%
x   y   z\\
0   0   0\\
1   0   0\\
1   1   0\\
0   1   0\\
}--cycle;

\addplot3[red, quiver={u={-2*x/(\length)}, v={(x-y)/(\length)}, scale arrows=0.075}, -stealth,samples=20] {0};

\draw[blue,arrow inside={end=stealth,opt={scale=1}}{0.2,0.4,0.6,0.8}] (axis cs:-1,1,0) -- (axis cs:0,0,0);
\draw[blue,arrow inside={end=stealth,opt={scale=1}}{0.2,0.4,0.6,0.8}] (axis cs:1,-1,0) -- (axis cs:0,0,0);
\draw[blue,arrow inside={end=stealth,opt={scale=1}}{0.2,0.4,0.6,0.8}] (axis cs:0,1,0) -- (axis cs:0,0,0);
\draw[blue,arrow inside={end=stealth,opt={scale=1}}{0.2,0.4,0.6,0.8}] (axis cs:0,-1,0) -- (axis cs:0,0,0);

\addplot3[color = blue, mark = *,fill=blue, mark size=2pt] coordinates {(0,0,0)};\\

\end{axis}
\end{tikzpicture}

\end{document}

This gives me the following output.

enter image description here

My problem now is now that the y axis is on the right instead of left. What I would like (and seem to be unable to achieve) is for all three axis to intersect in the same point. Could somebody help?

PS: Just now I noticed that the grey dots of the grid overlay the x and y axis... How do I get rid of that?

Edit:

Stefan Pinnow: No, the intersection point shouldn't be the origin, but rather where the x and z axis already intersect (which is (-1,-1,0)).

I replaced axis lines=left with axis x line=left, axis y line=right, axis z line=left, which produces the following.

enter image description here

This is almost what I want, only I'd like to have the y axis on the bottom. Is it possible to a apply a zshift to the y axis? If so, how?

  • If "the same point" is the origin, just replace axis lines=left with axis lines=center. – Stefan Pinnow Jan 17 '16 at 8:34
  • Did my answer help you to solve the problem? Otherwise please be more precise in your question. – Stefan Pinnow Feb 19 '17 at 21:18
  • @StefanPinnow The OP replied to your comment in an answer that was deleted, I edited the question to include that info. – Torbjørn T. Feb 24 '17 at 17:26
1

Ugly workaround, but you could draw that axis manually. Set axis y line=none, and add

\draw [-latex]
   (\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymin},\pgfkeysvalueof{/pgfplots/zmin}) --
   (\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymax},\pgfkeysvalueof{/pgfplots/zmin})
   node[above]{$\overline{s}$};

in the axis environment.

enter image description here

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}
\pgfplotsset{ticks=minor,grid style={dotted,gray},compat=newest,extra tick style={grid=major}}

\pgfdeclareplotmark{ball}{%
    \shade[draw=none,ball color=red] (0,0) circle (\pgfplotmarksize);
  }

\usetikzlibrary{decorations.markings}
\tikzset{
    set arrow inside/.code={\pgfqkeys{/tikz/arrow inside}{#1}},
    set arrow inside={end/.initial=>, opt/.initial=},
    /pgf/decoration/Mark/.style={
        mark/.expanded=at position #1 with
        {
            \noexpand\arrow[\pgfkeysvalueof{/tikz/arrow inside/opt}]{\pgfkeysvalueof{/tikz/arrow inside/end}}
        }
    },
    arrow inside/.style 2 args={
        set arrow inside={#1},
        postaction={
            decorate,decoration={
                markings,Mark/.list={#2}
            }
        }
    },
}

\begin{document}

\def\length{sqrt(4*x^2+(x-y)^2)}

\begin{tikzpicture}

\begin{axis}[%
axis x line=left, axis y line=none, axis z line=left,
grid=minor,
height=8cm,
width=15cm,
domain=-1:1,
view={30}{70},
xlabel={$s$},
ylabel={$\overline{s}$},
zlabel={$e$},
xmin=-1,
xmax=1,
yticklabels={\empty},
zticklabels={\empty},
extra x ticks={-1,0,1},
extra y ticks={-1,0,1},
extra z ticks={0.05,0.1},
ymin=-1,
ymax=1,
zmin=0,
zmax=0.1,
restrict x to domain = -1:1,
restrict y to domain = -1:1,
axis line style = {-latex},
every axis x label/.style={
    at={(ticklabel* cs:1)},
    anchor=north
},
every axis y label/.style={
    at={(ticklabel* cs:1)},
    anchor=south,
},
every axis z label/.style={
    at={(ticklabel* cs:1)},
    anchor=south,
}
]

\draw [-latex]
(\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymin},\pgfkeysvalueof{/pgfplots/zmin}) --
(\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymax},\pgfkeysvalueof{/pgfplots/zmin})
node[above]{$\overline{s}$};

\addplot3[area legend,solid,fill=black,fill opacity=0.05,draw opacity=0,forget plot]
table[row sep=crcr] {%
x   y   z\\
0   0   0\\
1   0   0\\
1   1   0\\
0   1   0\\
}--cycle;

\addplot3[red, quiver={u={-2*x/(\length)}, v={(x-y)/(\length)}, scale arrows=0.075}, -stealth,samples=10] {0};

\draw[blue,arrow inside={end=stealth,opt={scale=1}}{0.2,0.4,0.6,0.8}] (axis cs:-1,1,0) -- (axis cs:0,0,0);
\draw[blue,arrow inside={end=stealth,opt={scale=1}}{0.2,0.4,0.6,0.8}] (axis cs:1,-1,0) -- (axis cs:0,0,0);
\draw[blue,arrow inside={end=stealth,opt={scale=1}}{0.2,0.4,0.6,0.8}] (axis cs:0,1,0) -- (axis cs:0,0,0);
\draw[blue,arrow inside={end=stealth,opt={scale=1}}{0.2,0.4,0.6,0.8}] (axis cs:0,-1,0) -- (axis cs:0,0,0);

\addplot3[color = blue, mark = *,fill=blue, mark size=2pt] coordinates {(0,0,0)};\\

\end{axis}
\end{tikzpicture}

\end{document}
| improve this answer | |

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.