Add variable tick in axis
Consider the following code where I detect the crossing of a function to a
given threshold. I am plotting the line from the intersection to the
x-axis, and storing the intersection in \p1
I would like to add a second axis environment identical to the first one
with only an additional tick at \x1
\begin{tikzpicture}
\begin{axis}[
clip=true,
axis x line=bottom,
axis y line=left,
grid = major,
grid style={dashed},
xmin=1,
xmax=64,
samples =32,
ymax = 1.6,
ymin = -0.2,
xlabel={\emph{sample number}},
xlabel style={at={(1,-0.1)}, anchor=south},
legend cell align=left,
legend pos=outer north east,
]
\addplot[name path global=one,blue,mark=+,domain=1:64]
{exp(-log10(2)/(8^2/4)*(\x-32)^2)};
\addplot[name path global=two,red,domain=1:64] {0.5};
\path [name intersections={of=one and two, name=i}];
\path let \p1=($(i-1)$) in (\x1,\y1);
\draw[dashed] (i-1) -- ($(axis cs:0,-0.2)!(i-1)!(axis cs:64,-.2)$);
\legend{Sampled signal,Threshold}
\end{axis}
\begin{axis}[
clip=true,
axis x line=bottom,
axis y line=left,
xmin=1,
xmax=64,
samples =32,
ymax = 1.6,
ymin = -0.2,
xtick=\empty,
ytick=\empty,
extra x ticks={\x1},
extra x tick labels={$t_{step}$},
]
\end{axis}
\end{tikzpicture
}
My attempt to use \x1 directly in the axis environment is failing.
No comments:
Post a Comment