我添加了红色、蓝色或绿色等标题的地方,我希望计划的这些区域填充标题的颜色。我该怎么做。
如果你需要我迄今为止所做工作的代码,请参见这里:
\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}
答案1
\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}