0

I am trying to reproduce the same graphic as below in Latex :

enter image description here

For the moment the best result I got is the following: enter image description here

I cannot find a solution to put more space between the patterns lines and I have no idea for the other details (nodes, borders of the rectangles etc.).

Here is the code I currently use:

  \documentclass{article}
  \usepackage[dvipsnames]{xcolor}
  \usepackage{tikz}
  \usepackage{pgfplots}
  \usetikzlibrary{patterns}

\begin{document} \begin{tikzpicture} \pgfdeclarepatternformonly{north east lines }% {\pgfqpoint{-1pt}{-1pt}}% {\pgfqpoint{10pt}{10pt}}% {\pgfqpoint{9pt}{9pt}}% { \pgfsetlinewidth{1.5pt} \pgfpathmoveto{\pgfqpoint{0pt}{0pt}} \pgfpathlineto{\pgfqpoint{9.1pt}{9.1pt}} \pgfusepath{stroke} }

    \pgfdeclarepatternformonly{vertical}%
       {\pgfqpoint{-1pt}{-1pt}}%
       {\pgfqpoint{10pt}{10pt}}%
       {\pgfqpoint{9pt}{9pt}}%
       {    
         \pgfsetlinewidth{1.5pt}
         \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
         \pgfpathlineto{\pgfqpoint{0pt}{10pt}}
         \pgfusepath{stroke}
        }

     \pgfdeclarepatternformonly{horizontal}%
       {\pgfqpoint{-1pt}{-1pt}}%
       {\pgfqpoint{10pt}{10pt}}%
       {\pgfqpoint{9pt}{9pt}}%
       {    
         \pgfsetlinewidth{1.5pt}
         \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
         \pgfpathlineto{\pgfqpoint{10pt}{0pt}}
         \pgfusepath{stroke}
        }

      \pgfdeclarepatternformonly{north west line}%
       {\pgfqpoint{-1pt}{-1pt}}%
       {\pgfqpoint{10pt}{10pt}}%
       {\pgfqpoint{9pt}{9pt}}%
       {    
         \pgfsetlinewidth{1.5pt}
         \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
         \pgfpathlineto{\pgfqpoint{-10pt}{10pt}}
         \pgfusepath{stroke}
        }

        \fill[pattern=north east lines wide,pattern color=blue] (0,0) rectangle(4,4);

        \fill[pattern= horizontal, pattern color=YellowOrange] (0,0) rectangle (4,2);

        \fill[pattern=vertical, pattern color=RubineRed] (0,0) rectangle (1,4);

        \fill[pattern=north west line wide,pattern color=black] (0,0) rectangle (1,2);

        \draw[->,>=stealth, ultra thick] (-1,0) -- (6,0)node[right] {$u$};
        \draw [->,>=stealth, ultra thick] (0,-1) -- (0,6)node[above] {$v$};

\end{tikzpicture}

\end{document}

  • 2
    You can use simple and plain TikZ commands for that! PGF commands are more complicated in this case. – Black Mild Mar 26 '21 at 11:40
  • Welcome to TeX.SX! The problem with using patterns is, that they are not positioned relatively to the shape but rather absolutely on the page (see: https://tex.stackexchange.com/a/65270/47927). So it would need a lot of trial and error to make the pattern fit the shapes. It is better to draw the lines separately as Juan Castaño has done in his answer below. – Jasper Habicht Mar 26 '21 at 12:02

1 Answers1

3

I'm not sure if your patterns must cross one another at fixed points. I tried to reproduce the original drawing so that it was as similar as possible. If this is not the case, my approach is probably not the best, and the patterns library is the way to do it.

I use \foreach and clips to draw the patterns, as you can see:

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

\definecolor{myblue} {HTML}{2F59D1} \definecolor{myorange}{HTML}{FD6E06} \definecolor{mypink} {HTML}{DE0191}

\begin{document} \begin{tikzpicture}[scale=4,thick,line cap=round] \def\aone{0.225} \def\atwo{0.45} \def\bone{0.9} \def\btwo{0.9} % blue lines \draw[myblue] (0,\btwo) -| (\bone,0); \begin{scope} \draw[myblue] (\bone,\btwo) circle (0.015) node [above right] {$C(b_1,b_2$)}; \clip (0,0) rectangle (\bone,\btwo); \foreach\i in {-7,-5,...,7} {% \draw[myblue] (0.125\i\bone,0) --++ (45:2); } \end{scope} % pink lines \draw[mypink] (\aone,\btwo) circle (0.015) node [above] {$C(a_1,b_2$)}; \draw[mypink] (0,\btwo) -- (\aone,\btwo); \foreach\i in {1,2,3} {% \draw[mypink] (\i\aone/3,0) -- (\i\aone/3,\bone); } % orange lines \draw[myorange] (\bone,\atwo) circle (0.015) node [right] {$C(b_1,a_2$)}; \draw[myorange] (\bone,0) -- (\bone,\atwo); \foreach\i in {1,...,4} {% \draw[myorange] (0,0.25\i\atwo) -- (\bone,0.25\i\atwo); } % black lines \draw (0,\atwo) -| (\aone,0); \begin{scope} \draw (\aone,\atwo) circle (0.015); \clip (0,0) rectangle (\aone,\atwo); \foreach\i in {1,...,5} {% \draw (0.125\i\bone,0) --++ (135:2); } \end{scope} % axes and labels \node at (0,0) [below left] {$0$}; \draw[->] (-0.1,0) -- (1.1,0) node[below] {$u_1$}; \draw[->] (0,-0.1) -- (0,1.1) node[left] {$u_2$}; \foreach\i/\j in{\aone/$a_1$,\bone/$b_1$,1/1} {% \draw (\i,0.025) -- (\i,-0.025) node [below] {\j}; } \foreach\i/\j in{\atwo/$a_2$,\btwo/$b_2$,1/1} {% \draw (0.025,\i) -- (-0.025,\i) node [left] {\j}; } \end{tikzpicture} \end{document}

And this is my drawing: enter image description here

Juan Castaño
  • 28,426