# Fill area between vectors with color

I have the following simple code:

\begin{tikzpicture}[scale=0.40]
\coordinate (Origin)   at (0,0);
\coordinate (XAxisMin) at (-1,0);
\coordinate (XAxisMax) at (1,0);
\coordinate (YAxisMin) at (0,0);
\coordinate (YAxisMax) at (0,0);

\draw[thick,->] (0,0)--(0,4.5) node[anchor=south east] {};
\draw[thick,->] (0,0)--(4.2,0) node[anchor=north west] {};
\draw[thin ,->] (0,0)--(2,3) node[anchor=east ] {\tiny $v_1$};
\draw[thin ,->] (0,0)--(4,1) node[anchor=north ] {\tiny $v_2$};
\end{tikzpicture}

which gives me the following picture:

How can I fill with some color the area between the two vectors? I am not really familiar with how clipping - fill works.

• Have you tried the very obvious \fill[red] (0,0) -- (0,4.5) -- (4.2,0) -- cyclic; (put it before the draw commands)? What do you want to clip against/with? (cyclic or cycle, not sure. It isn't even necessary, TikZ will automatically close the path for \fill commands) – Huang_d May 24 '18 at 14:18
• I am not sure what the cyclic part does. I will try it though. – Marion May 24 '18 at 14:18
• Also, if would like that it is a transparent color, in the sense that if I draw a 3rd vector in between it will be on top of the color. – Marion May 24 '18 at 14:20
• cyclic is wrong, use cycle instead. – user121799 May 24 '18 at 14:21
• I think I can use it without cyclic or cycle. But it still wont respect other structure: e.g. if I put a lattice on this graph then the red color will go over it. How can I make it such that I can still see lattice points or lines etc? I got it! Opacity is the key! – Marion May 24 '18 at 14:25

Here is a proposal using the background layer. And you are right, cycle is not necessary here, but perhaps a good habit.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[scale=0.40]
\coordinate (Origin)   at (0,0);
\coordinate (XAxisMin) at (-1,0);
\coordinate (XAxisMax) at (1,0);
\coordinate (YAxisMin) at (0,0);
\coordinate (YAxisMax) at (0,0);

\draw[thick,->] (0,0)--(0,4.5) node[anchor=south east] {};
\draw[thick,->] (0,0)--(4.2,0) node[anchor=north west] {};
\draw[thin ,->] (0,0)--(2,3) node[anchor=east,font=\tiny] {$v_1$};
\draw[thin ,->] (0,0)--(4,1) node[anchor=north,font=\tiny] {$v_2$};
\begin{scope}[on background layer]
\fill[blue!20] (0,0) -- (4,1) -- (2,3) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}

An alternative code adding \filldraw[fill=red, opacity=0.1, draw=none] (0,0) -- (4,1) -- (2,3); instead of \fill[blue!20] (0,0) -- (4,1) -- (2,3) -- cycle; into Marmot's answer:

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}[scale=0.40]
\coordinate (Origin)   at (0,0);
\coordinate (XAxisMin) at (-1,0);
\coordinate (XAxisMax) at (1,0);
\coordinate (YAxisMin) at (0,0);
\coordinate (YAxisMax) at (0,0);

\draw[thick,->] (0,0)--(0,4.5) node[anchor=south east] {};
\draw[thick,->] (0,0)--(4.2,0) node[anchor=north west] {};
\draw[thin ,->] (0,0)--(2,3) node[anchor=east] {\tiny $v_1$};
\draw[thin ,->] (0,0)--(4,1) node[anchor=north] {\tiny $v_2$};
\filldraw[fill=red, opacity=0.1, draw=none] (0,0) -- (4,1) -- (2,3);
\end{tikzpicture}
\end{document}
• Thanks! Good answer, although I figured it out! – Marion May 25 '18 at 8:21
• @Marion Thank you very muchhhhhh :-) – Sebastiano May 25 '18 at 10:57