Simplifying repetitive drawings
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
How to use foreach
to simplify the following code.
I intentionally used tikzpictures without spaces between end and begin commands to display the graphs beside each other.
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitle
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi>0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to left node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*5) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*6) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*7) -- +(-90:.0);
endtikzpicture
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi=0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Symmetric node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endtikzpicture
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi<0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to right node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*7) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*6) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*5) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endtikzpicture
endframe
enddocument
tikz-pgf
add a comment |Â
up vote
3
down vote
favorite
How to use foreach
to simplify the following code.
I intentionally used tikzpictures without spaces between end and begin commands to display the graphs beside each other.
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitle
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi>0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to left node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*5) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*6) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*7) -- +(-90:.0);
endtikzpicture
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi=0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Symmetric node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endtikzpicture
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi<0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to right node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*7) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*6) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*5) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endtikzpicture
endframe
enddocument
tikz-pgf
foreach x in 1,...,7 draw [linecolor] (x*incrmnt,0) +(90:x*incrmnt) -- +(-90:0);
â Sigur
1 hour ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
How to use foreach
to simplify the following code.
I intentionally used tikzpictures without spaces between end and begin commands to display the graphs beside each other.
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitle
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi>0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to left node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*5) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*6) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*7) -- +(-90:.0);
endtikzpicture
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi=0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Symmetric node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endtikzpicture
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi<0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to right node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*7) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*6) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*5) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endtikzpicture
endframe
enddocument
tikz-pgf
How to use foreach
to simplify the following code.
I intentionally used tikzpictures without spaces between end and begin commands to display the graphs beside each other.
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitle
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi>0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to left node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*5) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*6) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*7) -- +(-90:.0);
endtikzpicture
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi=0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Symmetric node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endtikzpicture
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi<0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to right node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*7) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*6) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*5) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endtikzpicture
endframe
enddocument
tikz-pgf
tikz-pgf
asked 1 hour ago
Hany
955314
955314
foreach x in 1,...,7 draw [linecolor] (x*incrmnt,0) +(90:x*incrmnt) -- +(-90:0);
â Sigur
1 hour ago
add a comment |Â
foreach x in 1,...,7 draw [linecolor] (x*incrmnt,0) +(90:x*incrmnt) -- +(-90:0);
â Sigur
1 hour ago
foreach x in 1,...,7 draw [linecolor] (x*incrmnt,0) +(90:x*incrmnt) -- +(-90:0);
â Sigur
1 hour ago
foreach x in 1,...,7 draw [linecolor] (x*incrmnt,0) +(90:x*incrmnt) -- +(-90:0);
â Sigur
1 hour ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
The first and third graphs can use a foreach loop. As for the second, it is possible but not very useful. Personally, I find it too small to be really profitable.
Update:
Instead of placing 3 tikzpicture
environments side by side without space, it is easier to fully use the power of TikZ and place the last two graphs in a scope
environment and move it to the right.
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitle
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi>0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to left node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
foreach y in 1,...,7
draw [linecolor] (incrmnt*y,0) +(90:incrmnt*y) -- +(-90:0);
beginscope[xshift=4cm]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi=0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Symmetric node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endscope
beginscope[xshift=8cm]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi<0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to right node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
foreach y [evaluate=y as yy using int(8-y)] in 1,...,7
draw [linecolor] (incrmnt*y,0) +(90:incrmnt*yy) -- +(-90:0);
endscope
endtikzpicture
endframe
enddocument
@Hany I improved the code by using only onetikzpicture
environment and twoscope
environments.
â AndréC
1 hour ago
add a comment |Â
up vote
1
down vote
An alternative to AndréC's nice answer, inspired by pgfplots loading behavior. ;-) It has not a single visible loop, but is nonetheless shorter. ;-)
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=1.16
usepgfplotslibrarygroupplots
begindocument
beginframe[t]
frametitleemphNow I know why you're always loading textttpgfplots ;-)
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
begingroupplot[group style=group size=3 by
2, x descriptions at=edge bottom,,xmin=-0.5,xmax=7.5,ymax=8,height=4cm,width=5cm,
axis lines=left,title style=font=small,anchor=north]
nextgroupplot[xtick=,ytick=empty,
xlabel=$pi>0.5$,title=Skewed to the left]
addplot [samples at=0,...,7,ycomb,no marks,linecolor] x;
nextgroupplot[xtick=empty,ytick=empty,
xlabel=$pi=0.5$,title=Symmetric]
addplot [samples at=0,...,7,ycomb,no marks,linecolor]
x+ifthenelse(x>3,7-2*x,0);
nextgroupplot[xtick=empty,ytick=empty,
xlabel=$pi<0.5$,title=Skewed to the right]
addplot [samples at=0,...,7,ycomb,no marks,linecolor] 7-x;
endgroupplot
endtikzpicture
endframe
enddocument
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
The first and third graphs can use a foreach loop. As for the second, it is possible but not very useful. Personally, I find it too small to be really profitable.
Update:
Instead of placing 3 tikzpicture
environments side by side without space, it is easier to fully use the power of TikZ and place the last two graphs in a scope
environment and move it to the right.
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitle
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi>0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to left node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
foreach y in 1,...,7
draw [linecolor] (incrmnt*y,0) +(90:incrmnt*y) -- +(-90:0);
beginscope[xshift=4cm]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi=0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Symmetric node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endscope
beginscope[xshift=8cm]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi<0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to right node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
foreach y [evaluate=y as yy using int(8-y)] in 1,...,7
draw [linecolor] (incrmnt*y,0) +(90:incrmnt*yy) -- +(-90:0);
endscope
endtikzpicture
endframe
enddocument
@Hany I improved the code by using only onetikzpicture
environment and twoscope
environments.
â AndréC
1 hour ago
add a comment |Â
up vote
3
down vote
The first and third graphs can use a foreach loop. As for the second, it is possible but not very useful. Personally, I find it too small to be really profitable.
Update:
Instead of placing 3 tikzpicture
environments side by side without space, it is easier to fully use the power of TikZ and place the last two graphs in a scope
environment and move it to the right.
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitle
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi>0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to left node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
foreach y in 1,...,7
draw [linecolor] (incrmnt*y,0) +(90:incrmnt*y) -- +(-90:0);
beginscope[xshift=4cm]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi=0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Symmetric node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endscope
beginscope[xshift=8cm]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi<0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to right node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
foreach y [evaluate=y as yy using int(8-y)] in 1,...,7
draw [linecolor] (incrmnt*y,0) +(90:incrmnt*yy) -- +(-90:0);
endscope
endtikzpicture
endframe
enddocument
@Hany I improved the code by using only onetikzpicture
environment and twoscope
environments.
â AndréC
1 hour ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
The first and third graphs can use a foreach loop. As for the second, it is possible but not very useful. Personally, I find it too small to be really profitable.
Update:
Instead of placing 3 tikzpicture
environments side by side without space, it is easier to fully use the power of TikZ and place the last two graphs in a scope
environment and move it to the right.
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitle
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi>0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to left node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
foreach y in 1,...,7
draw [linecolor] (incrmnt*y,0) +(90:incrmnt*y) -- +(-90:0);
beginscope[xshift=4cm]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi=0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Symmetric node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endscope
beginscope[xshift=8cm]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi<0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to right node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
foreach y [evaluate=y as yy using int(8-y)] in 1,...,7
draw [linecolor] (incrmnt*y,0) +(90:incrmnt*yy) -- +(-90:0);
endscope
endtikzpicture
endframe
enddocument
The first and third graphs can use a foreach loop. As for the second, it is possible but not very useful. Personally, I find it too small to be really profitable.
Update:
Instead of placing 3 tikzpicture
environments side by side without space, it is easier to fully use the power of TikZ and place the last two graphs in a scope
environment and move it to the right.
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
begindocument
beginframe[t]
frametitle
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi>0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to left node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
foreach y in 1,...,7
draw [linecolor] (incrmnt*y,0) +(90:incrmnt*y) -- +(-90:0);
beginscope[xshift=4cm]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi=0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Symmetric node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
draw [linecolor] (incrmnt*1,0) +(90:incrmnt*1) -- +(-90:0);
draw [linecolor] (incrmnt*2,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*3,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*4,0) +(90:incrmnt*4) -- +(-90:.0);
draw [linecolor] (incrmnt*5,0) +(90:incrmnt*3) -- +(-90:.0);
draw [linecolor] (incrmnt*6,0) +(90:incrmnt*2) -- +(-90:.0);
draw [linecolor] (incrmnt*7,0) +(90:incrmnt*1) -- +(-90:.0);
endscope
beginscope[xshift=8cm]
pgfmathsetmacroincrmnt.4
draw [thick,-latex](0,0) -- (3.5,0) node [pos=.5, black, xshift=0cm, yshift=-.5cm] $pi<0.5$ node [pos=.5, black, xshift=0cm, yshift=3.4cm] Skewed to right node [xshift=.2cm, yshift=0cm] ;
draw [thick,-latex](0,0) -- (0,4);
foreach y [evaluate=y as yy using int(8-y)] in 1,...,7
draw [linecolor] (incrmnt*y,0) +(90:incrmnt*yy) -- +(-90:0);
endscope
endtikzpicture
endframe
enddocument
edited 1 hour ago
answered 1 hour ago
AndréC
5,0221836
5,0221836
@Hany I improved the code by using only onetikzpicture
environment and twoscope
environments.
â AndréC
1 hour ago
add a comment |Â
@Hany I improved the code by using only onetikzpicture
environment and twoscope
environments.
â AndréC
1 hour ago
@Hany I improved the code by using only one
tikzpicture
environment and two scope
environments.â AndréC
1 hour ago
@Hany I improved the code by using only one
tikzpicture
environment and two scope
environments.â AndréC
1 hour ago
add a comment |Â
up vote
1
down vote
An alternative to AndréC's nice answer, inspired by pgfplots loading behavior. ;-) It has not a single visible loop, but is nonetheless shorter. ;-)
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=1.16
usepgfplotslibrarygroupplots
begindocument
beginframe[t]
frametitleemphNow I know why you're always loading textttpgfplots ;-)
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
begingroupplot[group style=group size=3 by
2, x descriptions at=edge bottom,,xmin=-0.5,xmax=7.5,ymax=8,height=4cm,width=5cm,
axis lines=left,title style=font=small,anchor=north]
nextgroupplot[xtick=,ytick=empty,
xlabel=$pi>0.5$,title=Skewed to the left]
addplot [samples at=0,...,7,ycomb,no marks,linecolor] x;
nextgroupplot[xtick=empty,ytick=empty,
xlabel=$pi=0.5$,title=Symmetric]
addplot [samples at=0,...,7,ycomb,no marks,linecolor]
x+ifthenelse(x>3,7-2*x,0);
nextgroupplot[xtick=empty,ytick=empty,
xlabel=$pi<0.5$,title=Skewed to the right]
addplot [samples at=0,...,7,ycomb,no marks,linecolor] 7-x;
endgroupplot
endtikzpicture
endframe
enddocument
add a comment |Â
up vote
1
down vote
An alternative to AndréC's nice answer, inspired by pgfplots loading behavior. ;-) It has not a single visible loop, but is nonetheless shorter. ;-)
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=1.16
usepgfplotslibrarygroupplots
begindocument
beginframe[t]
frametitleemphNow I know why you're always loading textttpgfplots ;-)
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
begingroupplot[group style=group size=3 by
2, x descriptions at=edge bottom,,xmin=-0.5,xmax=7.5,ymax=8,height=4cm,width=5cm,
axis lines=left,title style=font=small,anchor=north]
nextgroupplot[xtick=,ytick=empty,
xlabel=$pi>0.5$,title=Skewed to the left]
addplot [samples at=0,...,7,ycomb,no marks,linecolor] x;
nextgroupplot[xtick=empty,ytick=empty,
xlabel=$pi=0.5$,title=Symmetric]
addplot [samples at=0,...,7,ycomb,no marks,linecolor]
x+ifthenelse(x>3,7-2*x,0);
nextgroupplot[xtick=empty,ytick=empty,
xlabel=$pi<0.5$,title=Skewed to the right]
addplot [samples at=0,...,7,ycomb,no marks,linecolor] 7-x;
endgroupplot
endtikzpicture
endframe
enddocument
add a comment |Â
up vote
1
down vote
up vote
1
down vote
An alternative to AndréC's nice answer, inspired by pgfplots loading behavior. ;-) It has not a single visible loop, but is nonetheless shorter. ;-)
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=1.16
usepgfplotslibrarygroupplots
begindocument
beginframe[t]
frametitleemphNow I know why you're always loading textttpgfplots ;-)
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
begingroupplot[group style=group size=3 by
2, x descriptions at=edge bottom,,xmin=-0.5,xmax=7.5,ymax=8,height=4cm,width=5cm,
axis lines=left,title style=font=small,anchor=north]
nextgroupplot[xtick=,ytick=empty,
xlabel=$pi>0.5$,title=Skewed to the left]
addplot [samples at=0,...,7,ycomb,no marks,linecolor] x;
nextgroupplot[xtick=empty,ytick=empty,
xlabel=$pi=0.5$,title=Symmetric]
addplot [samples at=0,...,7,ycomb,no marks,linecolor]
x+ifthenelse(x>3,7-2*x,0);
nextgroupplot[xtick=empty,ytick=empty,
xlabel=$pi<0.5$,title=Skewed to the right]
addplot [samples at=0,...,7,ycomb,no marks,linecolor] 7-x;
endgroupplot
endtikzpicture
endframe
enddocument
An alternative to AndréC's nice answer, inspired by pgfplots loading behavior. ;-) It has not a single visible loop, but is nonetheless shorter. ;-)
documentclassbeamer
beamertemplatenavigationsymbolsempty
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=1.16
usepgfplotslibrarygroupplots
begindocument
beginframe[t]
frametitleemphNow I know why you're always loading textttpgfplots ;-)
begintikzpicture[scale=.9, transform shape,linecolor/.style=ultra thick, green!40!black]
begingroupplot[group style=group size=3 by
2, x descriptions at=edge bottom,,xmin=-0.5,xmax=7.5,ymax=8,height=4cm,width=5cm,
axis lines=left,title style=font=small,anchor=north]
nextgroupplot[xtick=,ytick=empty,
xlabel=$pi>0.5$,title=Skewed to the left]
addplot [samples at=0,...,7,ycomb,no marks,linecolor] x;
nextgroupplot[xtick=empty,ytick=empty,
xlabel=$pi=0.5$,title=Symmetric]
addplot [samples at=0,...,7,ycomb,no marks,linecolor]
x+ifthenelse(x>3,7-2*x,0);
nextgroupplot[xtick=empty,ytick=empty,
xlabel=$pi<0.5$,title=Skewed to the right]
addplot [samples at=0,...,7,ycomb,no marks,linecolor] 7-x;
endgroupplot
endtikzpicture
endframe
enddocument
answered 21 mins ago
marmot
70.9k476151
70.9k476151
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f458057%2fsimplifying-repetitive-drawings%23new-answer', 'question_page');
);
Post as a guest
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
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
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
foreach x in 1,...,7 draw [linecolor] (x*incrmnt,0) +(90:x*incrmnt) -- +(-90:0);
â Sigur
1 hour ago