Simplifying repetitive drawings

The name of the pictureThe name of the pictureThe name of the pictureClash 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


enter image description here










share|improve this question





















  • foreach x in 1,...,7 draw [linecolor] (x*incrmnt,0) +(90:x*incrmnt) -- +(-90:0);
    – Sigur
    1 hour ago














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


enter image description here










share|improve this question





















  • foreach x in 1,...,7 draw [linecolor] (x*incrmnt,0) +(90:x*incrmnt) -- +(-90:0);
    – Sigur
    1 hour ago












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


enter image description here










share|improve this question













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


enter image description here







tikz-pgf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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










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


graphes






share|improve this answer






















  • @Hany I improved the code by using only one tikzpicture environment and two scope environments.
    – AndréC
    1 hour ago


















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


enter image description here






share|improve this answer




















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "85"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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


    graphes






    share|improve this answer






















    • @Hany I improved the code by using only one tikzpicture environment and two scope environments.
      – AndréC
      1 hour ago















    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


    graphes






    share|improve this answer






















    • @Hany I improved the code by using only one tikzpicture environment and two scope environments.
      – AndréC
      1 hour ago













    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


    graphes






    share|improve this answer














    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


    graphes







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 1 hour ago

























    answered 1 hour ago









    AndréC

    5,0221836




    5,0221836











    • @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
















    @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











    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


    enter image description here






    share|improve this answer
























      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


      enter image description here






      share|improve this answer






















        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


        enter image description here






        share|improve this answer












        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


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 21 mins ago









        marmot

        70.9k476151




        70.9k476151



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery