我有这个代码并且对我有用
\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}
我需要类似的东西,我制作了下面的代码,但在我看来,我无法达到规模......以及如何删除标签和数字周围的框?
代码:
\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}
答案1
首先,我感到自己有责任,因为我创建了第一个代码。虽然它可以工作,但可以使用以下方法简化很多:这个很酷的答案。然后我在情节开始之前解开了足球场所需的样式。
\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}
但是,你可以使用@samcarter 的 tikzducks 和@CarLaTeX 的建议来极大地改善结果,即添加\usepackage{tikzducks}
到序言并取消注释
% 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]}};
}
编辑:这是给玩家的代码。
\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}