5

I have this code and works for me

\documentclass[varwidth]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{inimigo.dat}
x   y   label
520 100 a0
30  410 a1
510 520 a2
220 620 a3
360 320 a4
\end{filecontents*}
\begin{filecontents*}{pontofixo.dat}
x y label
1150 450 Gol
\end{filecontents*}
\begin{filecontents*}{inicial.dat}
x   y   label
340 0   g0
340.789 421.1   g1
340.904 374.027 g2
394.844 448.825 g3
404.386 327.304 g4
\end{filecontents*}

\usepackage{caption}
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{geometry}
\geometry{
 paperwidth=25cm,
 left=1in,right=1in,top=1in,bottom=1in
}

\begin{document}
\begin{figure}[h]
\centering
 \begin{tikzpicture}
 \begin{axis}[xmin=0,xmax=1200,ymin=0,ymax=900, xstep=1,ystep=1,nodes     near coords,enlargelimits=0.0]

\xdef\DoLater{}

 \addplot +[only marks,mark=*,nodes near
 coords={\makebox[0pt]{\coordinate(\labelz) at (\myx,\myy);}\labelz}, 
 visualization depends on={value \thisrowno{2}\as\labelz},
 visualization depends on={value \thisrow{x}\as\myx},
 visualization depends on={value \thisrow{y}\as\myy}] 
           table{pontofixo.dat}; % this defines the coordinate (Goal)
           % if I do not define it, the next sequence will throw an error
\addplot +[scatter/position=relative,only marks,mark=*,
nodes near coords={\labelz\makebox[0pt]{\coordinate(\labelz) at
(\myx,\myy);
\xdef\DoLater{\DoLater,\labelz}
}}, visualization depends on={value \thisrowno{2}\as\labelz},
 visualization depends on={value \thisrow{x}\as\myx},
 visualization depends on={value \thisrow{y}\as\myy}] 
            table{inimigo.dat};

\addplot +[scatter/position=relative,only marks,mark=*,
nodes near coords={\labelz\makebox[0pt]{\coordinate(\labelz) at
(\myx,\myy);
%\xdef\DoLater{\DoLater,\labelz}
}}, visualization depends on={value \thisrowno{2}\as\labelz},
 visualization depends on={value \thisrow{x}\as\myx},
 visualization depends on={value \thisrow{y}\as\myy}] 
            table{inicial.dat};

 \end{axis}
 \foreach \Point in \DoLater{
\ifx\Point\empty%
\relax
\else
\draw (\Point) -- (Gol);
\fi
}
\end{tikzpicture}
\end{figure}
\end{document}

This code generate this figure: enter image description here

I need something similar to this, I made the code below but it seems to me that I can not hit the scales ... and how do I remove the box around the labels and numbers?

enter image description here

code:

\documentclass[margin=10pt]{standalone}
  \usepackage{tikz}
 \usetikzlibrary{arrows.meta, calc}
 \usepackage{pgfplots}
 \pgfplotsset{compat=newest}
 \usepackage{geometry}

 \usepackage{filecontents}
 \begin{filecontents*}{inimigo.dat}
x   y   label
520 100 a0
30  410 a1
510 520 a2
220 620 a3
360 320 a4
\end{filecontents*}
\begin{filecontents*}{pontofixo.dat}
x y label
1150 450 Gol
\end{filecontents*}
\begin{filecontents*}{inicial.dat}
x   y   label
340 0   g0
340.789 421.1   g1
340.904 374.027 g2
394.844 448.825 g3
404.386 327.304 g4
\end{filecontents*}


\definecolor{field}{RGB}{0,156,0}

\tikzset{
   every node/.style={draw=white, very thick, inner sep=0, outer sep=0},
   every path/.style={draw=white, very thick},
}

\newcommand\area[2]{%
\begin{scope}[shift={(#1)}, transform shape, rotate=#2]
 \node[minimum width=.55cm,minimum height=1.832cm, anchor=west] (small#2) at (0,0) {};
 \node[minimum width=1.65cm,minimum height=4.032cm, anchor=west] (big#2) at (0,0) {};
 \node[minimum width=.244cm, minimum height=.732cm, anchor=east] (goal#2) at (0,0) {};
 \node[inner sep=.3mm, circle, fill=white] (penalty#2) at (1.1,0) {};
 \begin{scope}
    \tikzset{every path/.style={}}
    \clip (big#2.south east) rectangle ++ (1,5); 
    \draw[white, very thick] (penalty#2) circle (0.915cm);
    \end{scope}
 \end{scope}
 }

\begin{document}
\begin{tikzpicture}
\fill[field] (-1,-1) rectangle (13,10);
\node[minimum width=12cm, minimum height=9cm] (contour) at (6,4.5) {};

% Center
\draw (contour.north) -- (contour.south);
\draw (contour.center) circle (0.915cm);
\fill[white] (contour.center) circle (.5mm);

% Areas
\area{contour.west}{0}
\area{contour.east}{180}

% Corners
\foreach \corner [count=\xi starting from 0] in {south west, south east, north east, north west}{
    \begin{scope}[rotate around={90*\xi:(contour.\corner)}]
        \draw ([xshift=1mm]contour.\corner) arc (0:90:1mm);
    \end{scope}
}

\begin{axis}[x=.01cm, y=.01cm, xmin=0,  ymin=0, xmax=1200,ymax=900, nodes near coords,enlargelimits=0.0] %, xmin=0,xmax=1200,ymin=0,ymax=900, xstep=2,ystep=2, nodes near coords,enlargelimits=0.0]
\xdef\DoLater{}

 \addplot +[only marks,mark=*,nodes near coords={\makebox[0pt]{\coordinate(\labelz) at (\myx,\myy);}\labelz}, 
 visualization depends on={value \thisrowno{2}\as\labelz},
 visualization depends on={value \thisrow{x}\as\myx},
 visualization depends on={value \thisrow{y}\as\myy}] 
           table{pontofixo.dat}; % this defines the coordinate (Goal)
           % if I do not define it, the next sequence will throw an error
\addplot +[scatter/position=relative,only marks,mark=*,
nodes near coords={\labelz\makebox[0pt]{\coordinate(\labelz) at
(\myx,\myy);
\xdef\DoLater{\DoLater,\labelz}
}}, visualization depends on={value \thisrowno{2}\as\labelz},
 visualization depends on={value \thisrow{x}\as\myx},
 visualization depends on={value \thisrow{y}\as\myy}] 
            table{inimigo.dat};

\addplot +[scatter/position=relative,only marks,mark=*,
nodes near coords={\labelz\makebox[0pt]{\coordinate(\labelz) at
(\myx,\myy);
}}, visualization depends on={value \thisrowno{2}\as\labelz},
 visualization depends on={value \thisrow{x}\as\myx},
 visualization depends on={value \thisrow{y}\as\myy}] 
            table{inicial.dat};

 \end{axis}
 \foreach \Point in \DoLater{
  \ifx\Point\empty%
  \relax
  \else
  \draw[black,thick,dashed] (\Point) -- (Gol);
  \fi
 }

\end{tikzpicture}
\end{document}

enter image description here enter image description here

Marcos Laureano
  • 341
  • 1
  • 6

1 Answers1

7

First of all, I feel responsible because I created the first code. Even though it works, it can be simplified quite a bit using this cool answer. And then I undid the styles needed for the soccer field just before the plots start.

\documentclass[margin=10pt]{standalone}
 \usepackage{tikzducks}
 \usetikzlibrary{arrows.meta, calc}
 \usepackage{pgfplots}
 \pgfplotsset{compat=newest}
 \usepackage{geometry}
\pgfplotsset{% https://tex.stackexchange.com/a/75811/121799
    name nodes near coords/.style={
        every node near coord/.append style={
            name=#1-\coordindex,
            alias=#1-last,
        },
    },
    name nodes near coords/.default=coordnode
}

 \usepackage{filecontents}
 \begin{filecontents*}{inimigo.dat}
x   y   label
520 100 a0
30  410 a1
510 520 a2
220 620 a3
360 320 a4
\end{filecontents*}
\begin{filecontents*}{pontofixo.dat}
x y label
1150 450 Gol
\end{filecontents*}
\begin{filecontents*}{inicial.dat}
x   y   label
340 0   g0
340.789 421.1   g1
340.904 374.027 g2
394.844 448.825 g3
404.386 327.304 g4
\end{filecontents*}


\definecolor{field}{RGB}{0,156,0}

\tikzset{
   every node/.style={very thick, inner sep=0, outer sep=0,draw=white}, 
   every path/.style={draw=white, very thick},
}

\newcommand\area[2]{
\begin{scope}[shift={(#1)},transform shape, rotate=#2]
 \node[minimum width=.55cm,minimum height=1.832cm, anchor=west] (small#2) at (0,0) {};
 \node[minimum width=1.65cm,minimum height=4.032cm, anchor=west] (big#2) at (0,0) {};
 \node[minimum width=.244cm, minimum height=.732cm, anchor=east] (goal#2) at (0,0) {};
 \node[inner sep=.3mm, circle, fill=white] (penalty#2) at (1.1,0) {};
 \begin{scope}
    \tikzset{every path/.style={}}
    \clip (big#2.south east) rectangle ++ (1,5); 
    \draw[white, very thick] (penalty#2) circle (0.915cm);
    \end{scope}
 \end{scope}
 }

\begin{document}
\begin{tikzpicture}
\fill[field] (-1,-1) rectangle (13,10);
\node[minimum width=12cm, minimum height=9cm] (contour) at (6,4.5) {};

% Center
\draw (contour.north) -- (contour.south);
\draw (contour.center) circle (0.915cm);
\fill[white] (contour.center) circle (.5mm);

% Areas
\area{contour.west}{0}
\area{contour.east}{180}

% Corners
\foreach \corner [count=\xi starting from 0] in {south west, south east, north east, north west}{
    \begin{scope}[rotate around={90*\xi:(contour.\corner)}]
        \draw ([xshift=1mm]contour.\corner) arc (0:90:1mm);
    \end{scope}
}
\tikzset{ % <- undo the settings needed for the soccer field
   every node/.style={}, 
   every path/.style={},
}

\begin{axis}[x=.01cm, y=.01cm, xmin=0,  ymin=0, xmax=1200,ymax=900, 
nodes near coords,enlargelimits=0.0] %, xmin=0,xmax=1200,ymin=0,ymax=900, xstep=2,ystep=2, nodes near coords,enlargelimits=0.0]

 \addplot +[only marks,name nodes near coords=Gol,
 mark=*,nodes near coords={\labelz}, 
 visualization depends on={value \thisrowno{2}\as\labelz},
 ] 
           table{pontofixo.dat}; % this defines the coordinate (Goal)
           % if I do not define it, the next sequence will throw an error
\addplot +[scatter/position=relative,only marks,mark=*,
name nodes near coords=a,
nodes near coords={\labelz}, 
visualization depends on={value \thisrowno{2}\as\labelz}] 
            table{inimigo.dat};

\addplot +[scatter/position=relative,only marks,mark=*,
name nodes near coords=g,
nodes near coords={\labelz}, 
visualization depends on={value \thisrowno{2}\as\labelz}] 
            table{inicial.dat};

 \end{axis}
 \foreach \n in {0,...,4}
 {
 \draw[black,thick,dashed] (a-\n.south) -- (Gol-0.south);
 \draw[black,thick,dashed] (g-\n.south) -- (Gol-0.south);
 }

%  % activate this for the ducks
%  \definecolor{blueinter}{RGB}{0,102,170}%
%  \foreach \n in {0,...,4}
%  {
%  \node at (a-\n.north){\tikz[xscale=-1,scale=0.4]{\duck[signpost={\scriptsize \color{black} \rotatebox{40}{\n}}, signback=white,
%  tshirt=black,stripes={\stripes[color=white]},football]}};
%  \node at (g-\n.north){\tikz[xscale=-1,scale=0.4]{\duck[signpost={\scriptsize \rotatebox{40}{\n}}, signback=blueinter,
%  tshirt=black,stripes={\stripes[color=blueinter]},football]}};
%  }
\draw[very thick,white] (contour.north west) rectangle (contour.south east);

\end{tikzpicture}
\end{document}

enter image description here

But you may improve the result tremendously by using @samcarter's tikzducks and @CarLaTeX's advice, i.e. add \usepackage{tikzducks} to the preamble and uncomment

  % activate this for the ducks
  \definecolor{blueinter}{RGB}{0,102,170}%
  \foreach \n in {0,...,4}
  {
  \node at (a-\n.north){\tikz[xscale=-1,scale=0.4]{\duck[signpost={\scriptsize \color{black} \rotatebox{40}{\n}}, signback=white,
  tshirt=black,stripes={\stripes[color=white]},football]}};
  \node at (g-\n.north){\tikz[xscale=-1,scale=0.4]{\duck[signpost={\scriptsize \rotatebox{40}{\n}}, signback=blueinter,
  tshirt=black,stripes={\stripes[color=blueinter]},football]}};
  }

to the very end: enter image description here

EDIT: And here comes a code for the players.

\documentclass[margin=10pt]{standalone}
 \usepackage{tikzducks}
 \usetikzlibrary{arrows.meta, calc,backgrounds}
 \usepackage{pgfplots}
 \pgfplotsset{compat=newest}
 \usepackage{geometry}
\pgfplotsset{% https://tex.stackexchange.com/a/75811/121799
    name nodes near coords/.style={
        every node near coord/.append style={
            name=#1-\coordindex,
            alias=#1-last,
        },
    },
    name nodes near coords/.default=coordnode
}

 \usepackage{filecontents}
 \begin{filecontents*}{inimigo.dat}
x   y   label
520 100 a0
30  410 a1
510 520 a2
220 620 a3
360 320 a4
\end{filecontents*}
\begin{filecontents*}{pontofixo.dat}
x y label
1150 450 Gol
\end{filecontents*}
\begin{filecontents*}{inicial.dat}
x   y   label
340 0   g0
340.789 421.1   g1
340.904 374.027 g2
394.844 448.825 g3
404.386 327.304 g4
\end{filecontents*}


\definecolor{field}{RGB}{0,156,0}

\tikzset{
   every node/.style={very thick, inner sep=0, outer sep=0,draw=white}, 
   every path/.style={draw=white, very thick},
}

\newcommand\area[2]{
\begin{scope}[shift={(#1)},transform shape, rotate=#2]
 \node[minimum width=.55cm,minimum height=1.832cm, anchor=west] (small#2) at (0,0) {};
 \node[minimum width=1.65cm,minimum height=4.032cm, anchor=west] (big#2) at (0,0) {};
 \node[minimum width=.244cm, minimum height=.732cm, anchor=east] (goal#2) at (0,0) {};
 \node[inner sep=.3mm, circle, fill=white] (penalty#2) at (1.1,0) {};
 \begin{scope}
    \tikzset{every path/.style={}}
    \clip (big#2.south east) rectangle ++ (1,5); 
    \draw[white, very thick] (penalty#2) circle (0.915cm);
    \end{scope}
 \end{scope}
 }


\newcommand{\Player}[1]{
\ifcase#1
\xdef\ColorList{pink,green,pink,pink} %0
\or
\xdef\ColorList{green,green,pink,pink} %1
\or
\xdef\ColorList{green,green,pink,green} %2
\or
\xdef\ColorList{pink,green,pink,green} %3
\or
\xdef\ColorList{green,pink,green,pink} %4
\or
\xdef\ColorList{green,pink,green,green} %5
\or
\xdef\ColorList{pink,pink,green,green} %6
\or
\xdef\ColorList{pink,pink,green,green} %7
\or
\xdef\ColorList{green,green,green,green} %8
\or
\xdef\ColorList{pink,pink,pink,pink} %9
\or
\xdef\ColorList{pink,green,green,pink} %10
\or
\xdef\ColorList{green,pink,pink,green} %11
\fi
\begin{tikzpicture}[scale=0.2]
\clip (-2,-2) rectangle (2,1.2);
\draw[fill=black] (0,0) circle (2);
\draw[fill=blue] (0,0) circle (0.5);
\foreach \Color [count=\n] in \ColorList
{
\pgfmathsetmacro{\Angle}{70+80*\n}
\draw[fill=\Color] (\Angle:1.1) circle (0.4);
}
\end{tikzpicture}
}

\begin{document}
\begin{tikzpicture}
\begin{scope}[on background layer]
\fill[field] (-1,-1) rectangle (13,10);
\node[minimum width=12cm, minimum height=9cm] (contour) at (6,4.5) {};

% Center
\draw (contour.north) -- (contour.south);
\draw (contour.center) circle (0.915cm);
\fill[white] (contour.center) circle (.5mm);

% Areas
\area{contour.west}{0}
\area{contour.east}{180}

% Corners
\foreach \corner [count=\xi starting from 0] in {south west, south east, north east, north west}{
    \begin{scope}[rotate around={90*\xi:(contour.\corner)}]
        \draw ([xshift=1mm]contour.\corner) arc (0:90:1mm);
    \end{scope}
}
\end{scope}
\tikzset{ % <- undo the settings needed for the soccer field
   every node/.style={}, 
   every path/.style={},
}

\begin{axis}[x=.01cm, y=.01cm, xmin=0,  ymin=0, xmax=1200,ymax=900, 
nodes near coords,enlargelimits=0.0] %, xmin=0,xmax=1200,ymin=0,ymax=900, xstep=2,ystep=2, nodes near coords,enlargelimits=0.0]

 \addplot +[only marks,name nodes near coords=Gol,nodes near coords={}] 
           table{pontofixo.dat}; % this defines the coordinate (Goal)
           % if I do not define it, the next sequence will throw an error
\addplot +[scatter/position=relative,only marks,mark=*,
name nodes near coords=a,nodes near coords={}] 
            table{inimigo.dat};

\addplot +[scatter/position=relative,only marks,mark=*,
name nodes near coords=g,nodes near coords={}] 
            table{inicial.dat};

 \end{axis}
 \foreach \n in {0,...,4}
 {
 \draw[black,thick,dashed] (a-\n.south) -- (Gol-0.south);
 \draw[black,thick,dashed] (g-\n.south) -- (Gol-0.south);
 }

\draw[very thick,white] (contour.north west) rectangle (contour.south east);

 \foreach \n in {0,...,4}
 {
 \node at (a-\n.south){\Player{\n}};
 \node at (g-\n.south){\Player{\n}};
 }


\end{tikzpicture}
\end{document}

enter image description here

  • @CarLaTeX You were too fast, but you could tell me which trikots they should wear ;-) –  Mar 10 '18 at 05:57
  • LOL, wonderful! If you want to represent the derby egreg vs CarLaTeX, you should do Juventus vs Inter :) – CarLaTeX Mar 10 '18 at 05:59
  • @marmot and @CarlasTex! Many thanks for the response and for the fun.

    But only one doubt: did I hit the scale? I'm not quite sure ... comparing the two figures ..

    – Marcos Laureano Mar 10 '18 at 13:40
  • @samcarter, no one is winning, I am researching mechanisms for blocking plays in soccer games, but the search is at the beginning yet. Figure is just a way to represent players and positions. – Marcos Laureano Mar 10 '18 at 13:44
  • @MarcosLaureano Sounds like a really interesting topic! – samcarter_is_at_topanswers.xyz Mar 10 '18 at 14:08
  • @marmot FYI: The problem with the rotation of text for left facing ducks should now be fixed in the development version https://github.com/samcarter8/tikzducks/blob/master/tikzducks.sty – samcarter_is_at_topanswers.xyz Mar 10 '18 at 14:11
  • @MarcosLaureano What do you mean by "did I hit the scale"? Could you please try to describe the problem a bit more? –  Mar 10 '18 at 14:31
  • @marmot, this lengh field is 12cm x 9cm, my matriz is 1200x900 and I use 0.1cm for scale in axis... Did I calculate that right? will the points in my array (enemy.dat for example) be correctly represented? – Marcos Laureano Mar 10 '18 at 14:52
  • @MarcosLaureano Ahh, now I seem to start to understand what you mean. But to me it looks good, the coordinates are where they should be, and you put for instance the Gol node at (1150,450), which should be just a bit left of the Milano goal, and it is. Or do you have an example of something that doesn't seem right? –  Mar 10 '18 at 14:58
  • @marmot No ... it was just a doubt, a little lack of confidence ...;) I tikz I'm very newbie! Another question, in the place of the ducks is it possible to use another figure to represent the points, such as this one that I will upload? each figure represents a player (by number). – Marcos Laureano Mar 10 '18 at 15:02
  • @MarcosLaureano Sure, one can replace the ducks by anything. Just to make sure I understand you correctly (Google's translation to marmot language is still very poor ;-)): the number (between 0 and 4) sets the number of small circles in the bigger contour? –  Mar 10 '18 at 15:10
  • @marmot, Yes twelve possible combinations ... change only central blue circle for a yellow circle (see figure). – Marcos Laureano Mar 10 '18 at 15:21
  • @marmot, You are my hero!!! ;) – Marcos Laureano Mar 10 '18 at 16:04
  • @marmot but is possible the figure show exactly in coord position? Because the labels (a0..an, g0..gn) would no longer be necessary and the figure would replace the point. – Marcos Laureano Mar 10 '18 at 16:13
  • @MarcosLaureano I updated my answer. –  Mar 10 '18 at 17:15