# Origin shift in pgfplots

I want to shift the origin in such a way as the following code will cause the circle to appear with center at the point marked in red.

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{color}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[shift={(0,0)}]
\begin{axis}[
ticks=none,
axis lines = middle,
axis line style={->},
ymin=0,
xmin=-3,
xmax=3,
xlabel={$Y$},
ylabel={$\pi$}]
\node[coordinate, pin=0:{target}] at (axis cs:0.5, 3){};
\end{axis}
\end{tikzpicture}
\end{document}


# Solution 1

Suppose you already know the coordinate at which you want to put the circle, which is (axis cs:0,3). You can just draw a circle placing a node at that coordinate, i.e.

\node[draw,circle,inner sep=0,miminum size=1cm] at(axis cs:0,3){};


# Solution 2

Alternatively, you can name the node, say target, and then can draw the circle at (target) with

\draw (target) circle[radius=1];


# Solution 3

Suppose the coordinate where you want to put the circle needs to be calculated. Then you can use the intersections library to calculate that point:

• Name the line {x+3} by adding name path global=line to the \addplot command:

\addplot[black, domain=-2:2,name path global=line] {x+3};

• Name the vertical axis

\path[name path global=yaxis](axis cs:0,0)--(axis cs:0,5);

• And draw the circle using

\draw[name intersections={of=line and yaxis, by=target}](target)circle[radius=1];


# Full code

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{color}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}[shift={(0,0)}]
\begin{axis}[
ticks=none,
axis lines = middle,
axis line style={->},
ymin=0,
xmin=-3,
xmax=3,
xlabel={$Y$},
ylabel={$\pi$}]
% \path[name path global=yaxis](axis cs:0,0)--(axis cs:0,5);
\node(target)[pin=0:{target},draw,circle,inner sep=0,minimum size=1cm] at (axis cs:0,3){};
\end{axis}
% \draw[name intersections={of=line and yaxis, by=target}](target)circle[radius=1];
\end{tikzpicture}
\end{document}


# Output

What you are searching for is actually the point where you "grab" the axis.

This, in turn, is a general feature available for every tikz node: whenever you place a tikz node, you have to provide the at key to say where to place it and you have to provide an anchor where to grab the node (i.e. which position inside of the node is to be placed at the position specified by at).

The same is true for an axis (as an axis is essentially a special kind of tikz node).

By default, an axis has at={(0,0)}. We only need to adopt the anchor. To this end, you can simply assign the name "target" to your target coordinate and use anchor=target:

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{color}
\usepackage{tikz}
\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[shift={(0,0)}]
\begin{axis}[
anchor=target,
ticks=none,
axis lines = middle,
axis line style={->},
ymin=0,
xmin=-3,
xmax=3,
xlabel={$Y$},
ylabel={$\pi$}]