TeX - LaTeX Asked by hermes on April 29, 2021
I want to draw several plots in the same tikzpicture
(I am not sure if there is other ways to do it) using plot function in tikz
. The code is:
documentclass[preview,border=2pt,2pt]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,backgrounds}
usetikzlibrary{calc}
usetikzlibrary{decorations.shapes}
usetikzlibrary{arrows.meta}
tikzset{decorate sep/.style 2 args=
{decorate,decoration={shape backgrounds,shape=circle,shape size=#1,shape sep=#2}}}
tikzset{>={Latex[width=1mm,length=3mm]}}
begin{document}
begin{tikzpicture}
tikzstyle{line} = [arrows=<->,line width=0.6pt]
tikzstyle{line1} = [line width=.1pt]
defr{0.5pt} %define the radius of spot
defax{3.3} %define the length of x-axis
defay{4} %define the length of y-axis
defy{3} %define the height of T=1
defu{4} %define the origin of the second plot
defv{8} %define the origin of the third plot
tikzset{
declare function={
normpdf(x,m,s,r)=r*exp(-((x-m)/s)^4);
}
}
draw[line] (0,ay) coordinate node [below left] {$T$} -- (0,0) coordinate node[below] {$0$} -- (ax, 0) coordinate node [below left] {$x$};
draw[scale=1, domain=0:2, smooth, variable=x] plot ({x}, {normpdf(x,0,1.3,y)});
node[left] at (0,y) {$1$};
node[above] at (ax/2,y) {(i) $ I_t=[0,alpha(t)]$};
draw[line1] (0, 2.1) -- (1,2.1) -- (1,0);
node[below] at (1,0) {$alpha(t)$};
draw[line] (u,ay) coordinate node [below left] {$T$} -- (u,0) coordinate node[below] {$0$} -- (ax+u, 0) coordinate node [below left] {$x$};
draw[scale=1, domain=-2:0, smooth, variable=x] plot ({x}, {normpdf(x,0,1.3,y)});
node[left] at (u,y) {$1$};
node[above] at (ax/2+u,y) {(ii) $ I_t=[alpha(t),c]$};
draw[line1] (u, 2.1) -- (u+1,2.1) -- (u+1,0);
node[below] at (u+1,0) {$alpha(t)$};
end{tikzpicture}
end{document}
The problem is how to shift the plot by the second draw to another origin specified by u ( "draw[scale=1, domain=-2:0, smooth, variable=x] plot ({x}, {normpdf(x,0,1.3,y)})")
. Thanks.
You can design the second plot with the same coordinates as the first one and shift it by the vector (x,y)
using
begin{shift}[shift={(x,y)}]
...
end{shift}
This allows you to reuse identical parts like shown below.
documentclass[border=2pt]{standalone}
usepackage{tikz}
usetikzlibrary{arrows.meta}
begin{document}
begin{tikzpicture}[
line/.style={arrows=<->,line width=0.6pt},
line1/.style={line width=.1pt},
declare function={normpdf(x,m,s,r)=r*exp(-((x-m)/s)^4);},
>={Latex[width=1mm,length=3mm]}
]
defr{0.5pt} %define the radius of spot
defax{3.3} %define the length of x-axis
defay{4} %define the length of y-axis
defy{3} %define the height of T=1
defu{4} %define the origin of the second plot
defv{8} %define the origin of the third plot
newcommandmyplot[1]{%
draw[line] (0,ay) node [below left] {$T$} -- (0,0) node[below] {$0$} -- (ax, 0) node [below left] {$x$};
draw[scale=1, domain=0:2, smooth, variable=x] plot ({x}, {normpdf(x,0,1.3,y)});
draw[line1] (0, 2.1) -| (1,0) node[below] {$alpha(t)$};
node[left] at (0,y) {$1$};
node[above] at (ax/2,y) {#1};
}
myplot{(i) $I_t=[0,alpha(t)]$}
begin{scope}[shift={(u,0)}]
myplot{(ii) $I_t=[alpha(t),c]$}
end{scope}
end{tikzpicture}
end{document}
Correct answer by gernot on April 29, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP