Re: Riempimento figure con Tiks

#79303
Up
0
Down
::


Ciao Andrea, hai ragione, ho dimenticato di inserire le premesse nella fretta. Lo faccio subito

`\usepackage{tikz}
\usetikzlibrary{calc,backgrounds,positioning}
% Declarations
\pgfmathtruncatemacro\scale{1}
\pgfmathtruncatemacro\minycoord{-5}
\pgfmathtruncatemacro\step{1}
\pgfmathtruncatemacro\maxycoord{5}
\pgfmathtruncatemacro\minxcoord{-5}
\pgfmathtruncatemacro\maxxcoord{5}

% Settings
\newcommand{\setscale}[1]{\pgfmathtruncatemacro\scale{#1}}
\newcommand{\setminycoord}[1]{\pgfmathtruncatemacro\minycoord{#1/\scale}}
\newcommand{\setmaxycoord}[1]{\pgfmathtruncatemacro\maxycoord{#1/\scale}}
\newcommand{\setmaxxcoord}[1]{\pgfmathtruncatemacro\maxxcoord{#1/\scale}}
\newcommand{\setminxcoord}[1]{\pgfmathtruncatemacro\minxcoord{#1/\scale}}

\newcommand{\drawaxes}{
\ifnum\minycoord=0
\draw[-stealth,semithick,shorten >=-1cm](0,\minycoord)–(0,\maxycoord);
\else
\draw[stealth-stealth,semithick,shorten <=-1cm,shorten >=-1cm](0,\minycoord)–(0,\maxycoord);
\fi
\ifnum\minycoord=0
\draw[-stealth,semithick,shorten >=-1cm](\minxcoord,0)–(\maxxcoord,0);
\else
\draw[stealth-stealth,semithick,shorten <=-1cm,shorten >=-1cm](\minxcoord,0)–(\maxxcoord,0);
\fi
}

\newcommand{\setlabelaxes}[1][0.1]{
% Y-axis
\pgfmathtruncatemacro\startingy\minycoord
\pgfmathparse{add(\startingy,\step)}\pgfmathresult
\pgfmathtruncatemacro\secondy\pgfmathresult
\pgfmathtruncatemacro\lasty\maxycoord
\foreach \y [evaluate=\y as \scaledy using \y*\scale] in {\startingy,\secondy,…,\lasty}{
\pgfmathtruncatemacro\labely\scaledy
\pgfmathparse{notequal(\labely,0)}\pgfmathresult
\ifnum\pgfmathresult=1
\draw[semithick] (#1,\y)–(-#1,\y) node

{\labely};
\fi
}
% X-axis
\pgfmathtruncatemacro\startingx\minxcoord
\pgfmathparse{add(\startingx,\step)}\pgfmathresult
\pgfmathtruncatemacro\secondx\pgfmathresult
\pgfmathtruncatemacro\lastx\maxxcoord
\foreach \x [evaluate=\x as \scaledx using \x*\scale] in {\startingx,\secondx,…,\lastx}{
\pgfmathtruncatemacro\labelx\scaledx
\pgfmathparse{notequal(\labelx,0)}\pgfmathresult
\ifnum\pgfmathresult=1
\draw[semithick] (\x,#1)–(\x,-#1) node[below] {\labelx};
\fi
}
}

\newcommand{\settickaxes}[1][0.1]{
% Y-axis
\pgfmathtruncatemacro\startingy\minycoord
\pgfmathparse{add(\startingy,\step)}\pgfmathresult
\pgfmathtruncatemacro\secondy\pgfmathresult
\pgfmathtruncatemacro\lasty\maxycoord
\foreach \y[evaluate=\y as \scaledy using \y*\scale] in {\startingy,\secondy,…,\lasty}{
\pgfmathtruncatemacro\labely\scaledy
\pgfmathparse{notequal(\labely,0)}\pgfmathresult
\ifnum\pgfmathresult=1
\draw[semithick] (#1,\y)–(-#1,\y);
\fi
}
% X-axis
\pgfmathtruncatemacro\startingx\minxcoord
\pgfmathparse{add(\startingx,\step)}\pgfmathresult
\pgfmathtruncatemacro\secondx\pgfmathresult
\pgfmathtruncatemacro\lastx\maxxcoord
\foreach \x [evaluate=\x as \scaledx using \x*\scale] in {\startingx,\secondx,…,\lastx}{
\pgfmathtruncatemacro\labelx\scaledx
\pgfmathparse{notequal(\labelx,0)}\pgfmathresult
\ifnum\pgfmathresult=1
\draw[thick] (\x,#1)–(\x,-#1);
\fi
}
}

\newcommand{\drawpoints}[2][0.1]{
\foreach \place/\name/\color in {#2}
\draw[draw=none,fill= \color] \place circle[radius=#1] node(\name) {};
}

\newcommand{\drawpins}[2][cyan]{
\foreach \place/\name/\position in {#2}
\draw[draw=#1, shorten <=0.45cm] \place -- (\name.\position); } Comunque ho provato a fare come tu mi hai scritto e ho già risolto il problema per cui grazie mille, il grafico è perfetto. Riporto di nuovo i comandi che ho utilizzo giusto perchè magari potrebbe essere utile a qualcun'altro che è ancora alle prime armi come me. \begin{tikzpicture} \setscale{1} \setminycoord{0} \setmaxycoord{5} \setminxcoord{0} \setmaxxcoord{5} % Axes \drawaxes \settickaxes[0.025] \path [fill=red!40] (1,6) -- (1,3) -- (3,3) -- (3,1) -- (6,1) -- (6,6) -- (1,6); \draw [very thick, red] (1,5.9) -- (1,3) -- (5.9,3); \draw [very thick, red] (3,3) -- (3,2) -- (5.9,2); \draw [very thick, red] (3,2) -- (3,1) -- (5.9,1); \draw [very thick, blue] (0,0) -- (0,5.9); \draw [very thick, blue] (1,0) -- (5.9,0); \drawpoints[0.1]{{(3,2)/a/red},{(1,3)/b/red},{(3,1)/c/red},{(0,0)/d/blue},{(1,0)/e/blue},{(1,1)/f/blue},{(2,1)/g/blue},{(2,2)/h/blue},{(1,2)/i/blue}} \end{tikzpicture}` Grazie ancora. Gaia

Go to top