Annotating a TIKZ Diagram
up vote
5
down vote
favorite
I have the following diagram and I'd like to annotate and add some arrows but getting a little rotate-confused with the lines and text. I've attached the tikz code I'm working with below and an image with the lines and labels drawn in ..
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
tikz-pgf
New contributor
add a comment |
up vote
5
down vote
favorite
I have the following diagram and I'd like to annotate and add some arrows but getting a little rotate-confused with the lines and text. I've attached the tikz code I'm working with below and an image with the lines and labels drawn in ..
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
tikz-pgf
New contributor
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I have the following diagram and I'd like to annotate and add some arrows but getting a little rotate-confused with the lines and text. I've attached the tikz code I'm working with below and an image with the lines and labels drawn in ..
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
tikz-pgf
New contributor
I have the following diagram and I'd like to annotate and add some arrows but getting a little rotate-confused with the lines and text. I've attached the tikz code I'm working with below and an image with the lines and labels drawn in ..
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
tikz-pgf
tikz-pgf
New contributor
New contributor
New contributor
asked Nov 21 at 10:31
user175199
262
262
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
4
down vote
You can add the lines inside axis
and use these coordinates. I've also added clips=false
to avoid problems with tip arrow draw below the axis.
documentclass[tikz,border=4mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm, clip=false]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
draw[->, red] (-0.5,-5)--(0,-5) node[above,midway]{A};
draw[->,red] (0,-1) node[left]{B}--({1+gauss(-1,1,0)},-1)node[below right]{C};
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
add a comment |
up vote
1
down vote
You have the parametrizations of the Gaussians, so it is easy to define the points B
and C
as a function of some input parameter, which I call xp
here. And then you already export coordinates out of the axis, you could also do this for the arrow labelled A
: just draw it outside of the axis. Then there is no need to switch off clip
. (In the present setting, you could switch off clip
, as demonstrated by Ignasi, but if you are to add more ingredients to your plot, this might not be the optimal way because often enough it is good to have pgfplots clip away auxiliary stuff.)
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
pgfmathsetmacro{xp}{-1}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3)
(-0.5,-5) coordinate (h1) (0,-5) coordinate (h2);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
coordinate (start) at (0,xp);
coordinate (end) at ({1+gauss(xp,1,0)},xp);
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
draw[red,-latex] (start) node[left]{B}
-- (end) node[below right]{C};
draw[red,-latex] (h1) -- (h2) node[midway,above]{A};
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
this is awesome thank you .. just one quick question if i want to add a second arrow/label below A that starts at the same position but ends at t2 how would i go about doing it? i keep getting an error when i try to duplicate A ..
– user175199
Nov 22 at 4:34
nevermind got it has to add the coordinates as well - thanks again marmot and Ignasi !
– user175199
Nov 22 at 4:44
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
You can add the lines inside axis
and use these coordinates. I've also added clips=false
to avoid problems with tip arrow draw below the axis.
documentclass[tikz,border=4mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm, clip=false]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
draw[->, red] (-0.5,-5)--(0,-5) node[above,midway]{A};
draw[->,red] (0,-1) node[left]{B}--({1+gauss(-1,1,0)},-1)node[below right]{C};
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
add a comment |
up vote
4
down vote
You can add the lines inside axis
and use these coordinates. I've also added clips=false
to avoid problems with tip arrow draw below the axis.
documentclass[tikz,border=4mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm, clip=false]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
draw[->, red] (-0.5,-5)--(0,-5) node[above,midway]{A};
draw[->,red] (0,-1) node[left]{B}--({1+gauss(-1,1,0)},-1)node[below right]{C};
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
add a comment |
up vote
4
down vote
up vote
4
down vote
You can add the lines inside axis
and use these coordinates. I've also added clips=false
to avoid problems with tip arrow draw below the axis.
documentclass[tikz,border=4mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm, clip=false]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
draw[->, red] (-0.5,-5)--(0,-5) node[above,midway]{A};
draw[->,red] (0,-1) node[left]{B}--({1+gauss(-1,1,0)},-1)node[below right]{C};
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
You can add the lines inside axis
and use these coordinates. I've also added clips=false
to avoid problems with tip arrow draw below the axis.
documentclass[tikz,border=4mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm, clip=false]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
draw[->, red] (-0.5,-5)--(0,-5) node[above,midway]{A};
draw[->,red] (0,-1) node[left]{B}--({1+gauss(-1,1,0)},-1)node[below right]{C};
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
answered Nov 21 at 11:31
Ignasi
90.3k4163302
90.3k4163302
add a comment |
add a comment |
up vote
1
down vote
You have the parametrizations of the Gaussians, so it is easy to define the points B
and C
as a function of some input parameter, which I call xp
here. And then you already export coordinates out of the axis, you could also do this for the arrow labelled A
: just draw it outside of the axis. Then there is no need to switch off clip
. (In the present setting, you could switch off clip
, as demonstrated by Ignasi, but if you are to add more ingredients to your plot, this might not be the optimal way because often enough it is good to have pgfplots clip away auxiliary stuff.)
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
pgfmathsetmacro{xp}{-1}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3)
(-0.5,-5) coordinate (h1) (0,-5) coordinate (h2);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
coordinate (start) at (0,xp);
coordinate (end) at ({1+gauss(xp,1,0)},xp);
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
draw[red,-latex] (start) node[left]{B}
-- (end) node[below right]{C};
draw[red,-latex] (h1) -- (h2) node[midway,above]{A};
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
this is awesome thank you .. just one quick question if i want to add a second arrow/label below A that starts at the same position but ends at t2 how would i go about doing it? i keep getting an error when i try to duplicate A ..
– user175199
Nov 22 at 4:34
nevermind got it has to add the coordinates as well - thanks again marmot and Ignasi !
– user175199
Nov 22 at 4:44
add a comment |
up vote
1
down vote
You have the parametrizations of the Gaussians, so it is easy to define the points B
and C
as a function of some input parameter, which I call xp
here. And then you already export coordinates out of the axis, you could also do this for the arrow labelled A
: just draw it outside of the axis. Then there is no need to switch off clip
. (In the present setting, you could switch off clip
, as demonstrated by Ignasi, but if you are to add more ingredients to your plot, this might not be the optimal way because often enough it is good to have pgfplots clip away auxiliary stuff.)
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
pgfmathsetmacro{xp}{-1}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3)
(-0.5,-5) coordinate (h1) (0,-5) coordinate (h2);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
coordinate (start) at (0,xp);
coordinate (end) at ({1+gauss(xp,1,0)},xp);
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
draw[red,-latex] (start) node[left]{B}
-- (end) node[below right]{C};
draw[red,-latex] (h1) -- (h2) node[midway,above]{A};
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
this is awesome thank you .. just one quick question if i want to add a second arrow/label below A that starts at the same position but ends at t2 how would i go about doing it? i keep getting an error when i try to duplicate A ..
– user175199
Nov 22 at 4:34
nevermind got it has to add the coordinates as well - thanks again marmot and Ignasi !
– user175199
Nov 22 at 4:44
add a comment |
up vote
1
down vote
up vote
1
down vote
You have the parametrizations of the Gaussians, so it is easy to define the points B
and C
as a function of some input parameter, which I call xp
here. And then you already export coordinates out of the axis, you could also do this for the arrow labelled A
: just draw it outside of the axis. Then there is no need to switch off clip
. (In the present setting, you could switch off clip
, as demonstrated by Ignasi, but if you are to add more ingredients to your plot, this might not be the optimal way because often enough it is good to have pgfplots clip away auxiliary stuff.)
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
pgfmathsetmacro{xp}{-1}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3)
(-0.5,-5) coordinate (h1) (0,-5) coordinate (h2);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
coordinate (start) at (0,xp);
coordinate (end) at ({1+gauss(xp,1,0)},xp);
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
draw[red,-latex] (start) node[left]{B}
-- (end) node[below right]{C};
draw[red,-latex] (h1) -- (h2) node[midway,above]{A};
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
You have the parametrizations of the Gaussians, so it is easy to define the points B
and C
as a function of some input parameter, which I call xp
here. And then you already export coordinates out of the axis, you could also do this for the arrow labelled A
: just draw it outside of the axis. Then there is no need to switch off clip
. (In the present setting, you could switch off clip
, as demonstrated by Ignasi, but if you are to add more ingredients to your plot, this might not be the optimal way because often enough it is good to have pgfplots clip away auxiliary stuff.)
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.14}
begin{document}
pgfmathsetmacro{offset}{0.05}
pgfmathsetmacro{xp}{-1}
begin{tikzpicture}[font=sffamilysmall,
declare function={gauss(x,y,z)=offset+1.2/(y*sqrt(2*pi))*exp(-((x- z)^2)/(2*y^2));}]
begin{axis}[samples=101,smooth,hide axis,width=20cm,height=8cm]
addplot [domain=-3:3] ({gauss(x,1,0)},x);
addplot [domain=-3:3] ({1+gauss(x,1,0)},x);
draw[-latex] (0,-3) -- (0,3) coordinate[pos=0.35](x1) coordinate[pos=0.5] (y1) node[below right,rotate=-90]{$X_k$};
draw[-latex] (1,-3) -- (1,3) coordinate[pos=0.60](x2) coordinate[pos=0.5](y2) node[below right,rotate=-90]{$X_1$};
addplot[-latex] coordinates{(-0.5,-4) (2,-4)};
path (0,-4) coordinate (z1) (1,-4) coordinate (z2) (2,-4) coordinate (z3)
(-0.5,-5) coordinate (h1) (0,-5) coordinate (h2);
coordinate (t0) at (-0.45,-4.1);
coordinate (t) at (2,-4.1);
coordinate (xi) at (-0.5,4);
addplot[-latex] coordinates{(-0.5,-4.2) (-0.5,4)}; % yaxis
coordinate (start) at (0,xp);
coordinate (end) at ({1+gauss(xp,1,0)},xp);
end{axis}
foreach X in {1,2}
{
draw ([xshift=-1mm]yX) -- ([xshift=1mm]yX);
draw ([yshift=1mm]zX) -- ([yshift=-1mm]zX) node[below] {$t_X$};
}
draw[red,-latex] (start) node[left]{B}
-- (end) node[below right]{C};
draw[red,-latex] (h1) -- (h2) node[midway,above]{A};
node[anchor=north east] at (t) {time};
node[anchor=north east] at (xi) {$X$};
end{tikzpicture}
end{document}
answered Nov 21 at 15:28
marmot
78.4k487166
78.4k487166
this is awesome thank you .. just one quick question if i want to add a second arrow/label below A that starts at the same position but ends at t2 how would i go about doing it? i keep getting an error when i try to duplicate A ..
– user175199
Nov 22 at 4:34
nevermind got it has to add the coordinates as well - thanks again marmot and Ignasi !
– user175199
Nov 22 at 4:44
add a comment |
this is awesome thank you .. just one quick question if i want to add a second arrow/label below A that starts at the same position but ends at t2 how would i go about doing it? i keep getting an error when i try to duplicate A ..
– user175199
Nov 22 at 4:34
nevermind got it has to add the coordinates as well - thanks again marmot and Ignasi !
– user175199
Nov 22 at 4:44
this is awesome thank you .. just one quick question if i want to add a second arrow/label below A that starts at the same position but ends at t2 how would i go about doing it? i keep getting an error when i try to duplicate A ..
– user175199
Nov 22 at 4:34
this is awesome thank you .. just one quick question if i want to add a second arrow/label below A that starts at the same position but ends at t2 how would i go about doing it? i keep getting an error when i try to duplicate A ..
– user175199
Nov 22 at 4:34
nevermind got it has to add the coordinates as well - thanks again marmot and Ignasi !
– user175199
Nov 22 at 4:44
nevermind got it has to add the coordinates as well - thanks again marmot and Ignasi !
– user175199
Nov 22 at 4:44
add a comment |
user175199 is a new contributor. Be nice, and check out our Code of Conduct.
user175199 is a new contributor. Be nice, and check out our Code of Conduct.
user175199 is a new contributor. Be nice, and check out our Code of Conduct.
user175199 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461087%2fannotating-a-tikz-diagram%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown