3

I am trying to draw a colored diagram in Latex/Tikz and need some help. I would like the to draw the usual x-y-plane with axes marked in black and the four quadrants marked in four different colors. How can I do this?`

\documentclass[tikz,border=2mm]{standalone}

\begin{document}
\begin{tikzpicture}
%\draw[help lines, color=gray!30] (-4.9,-4.9) grid ;
\draw[->,thick] (-1.5,0)--(1.5,0) node[right]{$X$};
\draw[->, thick] (0,-1.5)--(0,1.5) node[above]{$Y$};
\end{tikzpicture}
\end{document}

As you can see, at the moment there is just a basic x-y-axis. I would like to add colors, but I have no idea how to do so.

5
  • Welcome to TeX.SE! Could you edit your code to begin with your \documentclass and end with \end{document}, a Minimal Working Example (MWE) please. It makes copy and pasting easier when the code can be compiled and also we do not need to guess what commands or packages you are using nor exactly what you are looking for
    – JamesT
    Commented Feb 16, 2023 at 10:59
  • 2
    @JamesT Thanks for letting me know about the conventions of the site. I have entered the working basic draft. Is this sufficient? Commented Feb 16, 2023 at 11:06
  • Yes that is sufficient, as long as the code can compile so it can be copy and pasted and shows effort then it is fine :)
    – JamesT
    Commented Feb 16, 2023 at 11:07
  • 1
    @JamesT Ok, great! Commented Feb 16, 2023 at 11:08
  • Welcome to TeX.SE!!! Commented Feb 16, 2023 at 11:23

4 Answers 4

4

Here is one way using \filldraw:

enter image description here

I am certain others will have better solutions to this but still. \yMax is a value so that you can change how far the rectangle colours go out (\yMax at a value of 1.4 comes up just to the arrow points).

\documentclass[tikz,border=2mm]{standalone}

\begin{document}

\newcommand\yMax{1.5}

\begin{tikzpicture}
%\draw[help lines, color=gray!30] (-4.9,-4.9) grid ;
\filldraw[red] (0.02,0.02) rectangle (\yMax,\yMax);
\filldraw[yellow] (-0.02,-0.02) rectangle (-\yMax,-\yMax);
\filldraw[blue] (-0.02,0.02) rectangle (-\yMax,\yMax);
\filldraw[green] (0.02,-0.02) rectangle (\yMax,-\yMax);

\draw[->,thick] (-1.5,0)--(1.5,0) node[right]{$X$};
\draw[->, thick] (0,-1.5)--(0,1.5) node[above]{$Y$};
\end{tikzpicture}
\end{document}

If you want to change the positions of the X and Y labels then use the yshift, xshift arguments to node:

enter image description here

\documentclass[tikz,border=2mm]{standalone}

\begin{document}

\newcommand\yMax{1.5}

\begin{tikzpicture}
%\draw[help lines, color=gray!30] (-4.9,-4.9) grid ;
\filldraw[red] (0.02,0.02) rectangle (\yMax,\yMax);
\filldraw[yellow] (-0.02,-0.02) rectangle (-\yMax,-\yMax);
\filldraw[blue] (-0.02,0.02) rectangle (-\yMax,\yMax);
\filldraw[green] (0.02,-0.02) rectangle (\yMax,-\yMax);

\draw[->,thick] (-1.5,0)--(1.5,0) node[above,xshift=-0.2cm]{$X$};
\draw[->, thick] (0,-1.5)--(0,1.5) node[right,yshift=-0.2cm]{$Y$};
\end{tikzpicture}
\end{document}
3
  • 1
    Thanks a lot for the diagram. Is it possible to change the placing of the labels X and Y so that are above/below the arrow instead of at the tip? Commented Feb 16, 2023 at 11:31
  • @JakeWetlock I have updated my answer, use xshift and yshift :)
    – JamesT
    Commented Feb 16, 2023 at 11:34
  • 1
    Great, thanks a lot! Commented Feb 16, 2023 at 11:43
6

Something to get started.

\documentclass[tikz,border=2mm]{standalone}

\begin{document}
    \begin{tikzpicture}
        %\draw[help lines, color=gray!30] (-4.9,-4.9) grid ;
        \draw[->,thick] (-1.5,0)--(1.5,0) node[right]{$X$};
        \draw[->, thick] (0,-1.5)--(0,1.5) node[above]{$Y$};
        
        \begin{scope}[x=1.5 cm, y=1.5 cm, opacity=0.5]
            \fill[violet] (0,0) rectangle (1,1);
            \fill[blue] (0,0) rectangle (-1,1);
            \fill[green] (0,0) rectangle (-1,-1);
            \fill[orange] (0,0) rectangle (1,-1);
        \end{scope}
    \end{tikzpicture}
\end{document}

enter image description here

6

Another one, adding all the quadrants in a \foreach loop:

\documentclass[tikz,border=2mm]{standalone}

\begin{document}
\begin{tikzpicture}
\foreach[count=\ii from 0]\i in {blue,red,green,yellow}
  \fill[\i!20,rotate=90*\ii] (0,0) rectangle (1.5,1.5);
\draw[->,thick] (-1.5,0) -- (1.5,0) node[right]{$X$};
\draw[->,thick] (0,-1.5) -- (0,1.5) node[above]{$Y$};
\end{tikzpicture}
\end{document}

enter image description here

3

Like this:

enter image description here

Minimal simple code:

\documentclass{article}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
        \fill[green] (-2,-2) rectangle (0,0);
        \fill[yellow] (0,-2) rectangle (2,0);
        \fill[red] (0,0) rectangle (2,2);
        \fill[cyan] (-2,0) rectangle (0,2);
        \draw[-latex] (-2,0)--(2.2,0) node[right] () {$x$};
        \draw[-latex] (0,-2)--(0,2.2) node[right] () {$y$};
    \end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .