有人能帮我画一张 sin^2y 和 cos^2y 的图吗?我试着为它编写代码,但遇到了困难,因为我不知道如何根据域的 y 定义函数。谢谢!
答案1
像这样:
代码:
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc}
\tikzset{>={Latex[width=3mm,length=2mm]}}
\begin{document}
\begin{tikzpicture}
\filldraw[fill=olive!10,draw=white] (-3,-6.5) rectangle (3,7);% bkd color
\draw[white](-3,-6.5) grid (3,7); % grid
%scale on the axis
\foreach \x in {-3,-2,...,3}
\draw (\x,.1)--(\x,-.1) node[below]() {\footnotesize $\x$};
\foreach \x in {-6,-5,...,6}
\draw (.1,\x)--(-.1,\x) node[left]() {\footnotesize $\x$};
% x & y axis
\draw[->,line width=.5pt] (-3,0)-- (3.5,0) node[below]() {$x$};
\draw[->,line width=.5pt] (0,-6.5)-- (0,7) node[left]() {$y$};
% change data for function(s) to plot in the next lines
\draw[rotate=-90,smooth,magenta,mark=none,domain=-6.5:6.5,line width=1pt] plot (\x,{sin(\x r)*sin(\x r)});
\draw[rotate=-90,smooth,green,mark=none,domain=-6.5:6.5,line width=1pt] plot (\x,{cos(\x r)*cos(\x r)});
\end{tikzpicture}
\end{document}