5

How to color with green color the domain bounded by a circle of radius 1.5 and the circle of radius 3.5 ?

How to color with yellow color the domain bounded by a circle of radius 3.5 and the circle of radius 5 ?

\RequirePackage{ifluatex}
\documentclass{standalone}
\ifluatex
\usepackage{fontspec}
\setmainfont{TeX Gyre Pagella}
\else
\usepackage{tgpagella}
\usepackage{pst-plot,pst-all,,pst-sigsys}
\definecolor{CyanTikz40}{cmyk}{.4,0,0,0}
 \fi
 \usepackage{auto-pst-pdf}
 \begin{document}
 \begin{postscript}
 \psset{unit=1cm,arrowscale=1.3,algebraic=true,labelFontSize=\scriptstyle} 
 \begin{pspicture}(-6,-6)(9,9)
 \psgrid[subgriddiv=0,gridlabels=0,gridcolor=gray](-6,-6)(9,9)
 \psaxes[labels=none,linewidth=1pt,Dx=1,Dy=1,ticksize=0pt 0pt]{->}(0,0)(-6,-6)(9,9)
 \pscircle[](0,0){5}
 \pscircle[](0,0){3.5}
 \pscircle[fillstyle=solid,fillcolor=blue,opacity=0.5](0,0){1.5}
 \psframe[fillstyle=solid,fillcolor=blue,opacity=0.5](6,1)(7,2)
 \psframe[fillstyle=solid,fillcolor=green,opacity=0.5](6,3)(7,4)
 \psframe[fillstyle=solid,fillcolor=yellow,opacity=0.5](6,5)(7,6)
 \uput[dl](0,0){\textcolor{black}{O}}
 \uput[d](0.9,0){\textcolor{black}{I}}
 \uput[l](0,1){\textcolor{black}{J}}
 \uput[r](7,5.5){\textcolor{black}{5 points}}
 \uput[r](7,3.5){\textcolor{black}{10 points}}
 \uput[r](7,1.5){\textcolor{black}{20 points}}
 \psTick{90}(1,0)
 \psTick{0}(0,1)
 \end{pspicture}
 \end{postscript}
 \end{document}
1
  • 1
    It is much better if you also provide us with the screenshot of your output so we don't need to compile your code in our mind. Sep 4, 2014 at 18:56

3 Answers 3

6
\documentclass{standalone}
\usepackage{pst-all}
\usepackage{auto-pst-pdf}

\begin{document} 
 \begin{pspicture}(-6,-6)(9,9)
 \psaxes[arrowscale=1.3,labels=none,linewidth=1.5pt,ticksize=-6 9,
         tickcolor=black!30]{->}(0,0)(-6,-6)(9,9)
 \psset{fillstyle=solid,opacity=0.5}
 \pscircle[fillcolor=blue]{1.5}
 \psRing[fillcolor=green]{1.5}{3.5}
 \psRing[fillcolor=yellow]{3.5}{5}
 \pgfforeach \col/\ru/\rv/\rw in {blue/1/2/20,green/3/4/10,yellow/5/6/5}{%
   \psframe[fillcolor=\col](6,\ru)(7,\rv)\uput[0]{0.5}(!7 0.5 \ru\space add){\rw{} points}}
 \uput[225](0,0){O} \psxTick(1){I}  \psyTick(1){J}
 \end{pspicture}
\end{document}

enter image description here

4
  • Sorry. The center at origin (0,0) can be omitted for \pscircle, \psellipse, \pswedge, \psellipticwedge, \psellipticarc, \psellipticarcn and \psRing but not for \psarc and \psarcn. I don't know why. It looks like a bug for \psarc and \psarcn. Sep 4, 2014 at 19:41
  • \psarc{-}{3}{0}{90}
    – user2478
    Sep 4, 2014 at 20:17
  • @Herbert Cyanide-based food Sorry for the late reply. I learn with you, thank you.
    – Fabrice
    Sep 5, 2014 at 16:44
  • Why doesn't\psRing{!1 2 add}{!2 3 add} produce correct result? Jan 3, 2018 at 22:47
7

I am trying to make your code much simpler but still beautiful.

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-plot} 
\psset
{
    arrowscale=1.3,
    ticks=none,
    labels=none,
} 
\begin{document}
\begin{pspicture}(-6,-6)(9,7)
    \psgrid[subgriddiv=1,gridlabels=0,gridcolor=lightgray!50](-6,-6)(9,7)
    \psaxes[linewidth=1pt]{->}(0,0)(-6,-6)(9,7)
    \psset{fillstyle=solid,opacity=0.5}
    \psRing[fillcolor=green]{3.5}{5}
    \psRing[fillcolor=yellow]{1.5}{3.5}
    \pscircle[fillcolor=blue]{1.5}
    \psframe[fillcolor=blue](6,1)(7,2)
    \psframe[fillcolor=green](6,3)(7,4)
    \psframe[fillcolor=yellow](6,5)(7,6)
    \uput[r](7,5.5){5 points}
    \uput[r](7,3.5){10 points}
    \uput[r](7,1.5){20 points}
    \uput[-135](0,0){$O$}
    \psxTick(1){I}
    \psyTick(1){J}
\end{pspicture}
\end{document}

enter image description here

Bonus

If you don't like the simpleness of \psRing to increase the number of used keystrokes, you can make use of \pscustom[fillstyle=eofill]{...} instead as follows.

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-plot} 
\psset
{
    arrowscale=1.3,
    algebraic=true,
    ticks=none,
    labels=none,
} 
\begin{document}
\begin{pspicture}(-6,-6)(9,7)
    \psgrid[subgriddiv=1,gridlabels=0,gridcolor=lightgray!50](-6,-6)(9,7)
    \psaxes[linewidth=1pt]{->}(0,0)(-6,-6)(9,7)
    \psset{fillstyle=solid,opacity=0.5}
    \pscustom[fillcolor=green,fillstyle=eofill]{\pscircle{3.5}\pscircle{5}}
    \pscustom[fillcolor=yellow,fillstyle=eofill]{\pscircle{1.5}\pscircle{3.5}}
    \pscircle[fillcolor=blue]{1.5}
    \psframe[fillcolor=blue](6,1)(7,2)
    \psframe[fillcolor=green](6,3)(7,4)
    \psframe[fillcolor=yellow](6,5)(7,6)
    \uput[r](7,5.5){5 points}
    \uput[r](7,3.5){10 points}
    \uput[r](7,1.5){20 points}
    \uput[-135](0,0){$O$}
    \psxTick(1){I}
    \psyTick(1){J}
\end{pspicture}
\end{document}
2
  • 1
    How do you feel about keystrokes? :)
    – cmhughes
    Sep 4, 2014 at 21:22
  • @cmhughes: I don't like verbosity in TikZ. :-) Sep 5, 2014 at 2:18
6

This one is for @cyanide-based food (A tikz answer for pstricks question ;-)...)

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

\begin{document}
 \begin{tikzpicture}
   \foreach \col/\x/\y in {blue/0/1.5,green/1.5/3.5,yellow/3.5/5}{
   \draw[fill=\col,fill opacity=0.5,even odd rule] (0,0) circle (\x cm) circle (\y cm);
   }
   \draw[help lines] (-6,-6) grid (9,7);
   \draw[thick,->] (-6,0) -- (9,0);
   \draw[thick,->] (0,-6) --  (0,7);
   \draw (0.2,1) -- (-0.2,1)node[anchor=east]{$J$};
   \draw (1,0.2) -- (1,-0.2)node[anchor=north]{$I$};
   \node[anchor=north east] at (0,0) {$O$};
   \foreach \col/\x/\y\p in {blue/6.5/1.5/20,green/6.5/3.5/10,yellow/6.5/5.5/5}{
   \node[draw,minimum size=1cm,fill=\col,fill opacity=0.5,label=right: \p\ points] at (\x,\y)
    {};
   }

 \end{tikzpicture}
\end{document}

enter image description here

4
  • I prefer PSTricks, but the simplicity of your code makes me want to learn as TikZ, but without abandoning PSTricks.
    – Fabrice
    Sep 6, 2014 at 10:09
  • @Fabrice tikz is more user friendly IMO. But some times pstricks is more powerful. And this answer is just for fun. :-)
    – user11232
    Sep 6, 2014 at 10:11
  • What is the meaning of "IMO" (I'm French)?
    – Fabrice
    Sep 7, 2014 at 10:25
  • @fabrice In My Opinion!
    – user11232
    Sep 7, 2014 at 11:12

You must log in to answer this question.

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