0

I have the following figure: enter image description here

The place where I added captions like red, blue or green I want those areas of the plan filled with the color of the captions. How do I do it.

In case you need the code for what I have done so far is here:

\documentclass{article} % say
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{changes}
\usepackage{amsmath}
\begin{document}
    \begin{figure}
        \centering
        \begin{tikzpicture}
        \definecolor{colorforline}{RGB}{49,4,71};
        \definecolor{shade}{RGB}{156, 166, 176};
        \draw [very thick, color=colorforline] (-5,0) -- (5,0) node[] {};
        \draw [very thick, color=colorforline] (-5,0) -- (-5,6) node[] {};
        \draw [very thick,color=colorforline] plot [smooth] coordinates { (-5,0) (-3,1) (0,5) (3,1) (5,0) };
        \end{tikzpicture}
        \caption{Partition of sample space $S$ associated with a discrete random variable.}
    \end{figure}
\end{document}

Here is what I really want: enter image description here

Saad
  • 323

1 Answers1

3
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
  \begin{axis}[
        xmin=-4,xmax=4,
        ymin=0,ymax=0.5,
        axis on top,
        axis y line*=left,
        axis x line*=bottom,
        xlabel = {Total Points},
        xtick={4},
        xticklabels={Maximum Possible},
        ytick={0},
        yticklabels={},
        ylabel = {Relative Frequency}]
    \addplot[color=black,domain=-4:4,samples=100] {1/sqrt(2*pi)*exp(-x^2/2)};
    \addplot+[mark=none,
      domain=-4:-2,
      samples=100,
      fill=red,
      draw=black,
      area legend]{1/sqrt(2*pi)*exp(-x^2/2)} \closedcycle; 
    \addplot+[mark=none,
      domain=-2:1,
      samples=100,
      fill=yellow,
      draw=black,
      area legend]{1/sqrt(2*pi)*exp(-x^2/2)} \closedcycle; 
    \addplot+[mark=none,
      domain=1:2,
      samples=100,
      fill=cyan,
      draw=black,
      area legend]{1/sqrt(2*pi)*exp(-x^2/2)} \closedcycle; 
    \addplot+[mark=none,
      domain=2:4,
      samples=100,
      fill=green,
      draw=black,
      area legend]{1/sqrt(2*pi)*exp(-x^2/2)} \closedcycle; 
    \node[above] at (axis cs:-3,0.05) {D or F}; 
    \node[above] at (axis cs:-0.5,0.05) {C}; 
    \node[above] at (axis cs:1.5,0.05) {B}; 
    \node[above] at (axis cs:3,0.05) {A}; 
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Mike Renfro
  • 20,550