我正在尝试使用下面的源代码创建参数曲线。它根本不会显示在我的图表上。曲线应该看起来像这样:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzstyle{textbox}=[draw=white, fill=white, thick, rectangle]
\begin{tikzpicture}[scale=2, domain=-4:4]
\draw [<->,thick] (-4,0)--coordinate(x axis)(4,0) node[right]{$x$};
\draw [<->, thick] (0,-4)--coordinate(y axis)(0,4) node[above] {$y$};
\foreach \x/\xtext in {-3.5/-3.5, -1.5/-1.5, 1.5/1.5, 3.5/3.5}
\draw[shift={(\x,0)}] (0pt,2pt)--(0pt,-2pt);
\node [below] at (-3.5,-0.) {$-2\pi$};
\node [below] at (-1.5,-0.) {$-\pi$};
\node [below] at (1.5,-0.) {$\pi$};
\node [below] at (3.5,-0.) {$2\pi$};
\foreach\y/\ytext in {-3.5/-3.5, -1.5/-1.5, 1.5/1.5, 3.5/3.5}
\draw [shift={(0,\y)}] (2pt,0pt)--(-2pt,0pt);
\node [left] at (-0.,3.5) {$2\pi$};
\node [left] at (-0.,1.5) {$\pi$};
\node [right] at (0.,-1.5) {$-\pi$};
\node [right] at (0.,-3.5) {$-2\pi$};
\draw [color=red] plot[id=cos] function{y=t+2cos5t};
\draw [color=blue] plot[id=sin] function{x=t+2sint};
\end{tikzpicture}
\end{document}
答案1
这里有几个问题。你没有告诉 TikZ 这个图是参数化的,你没有把X和是组件合并到一行中\draw
,并且您没有以正确的形式给出公式。您可以判断出问题了,因为 Gnuplot 会发出警告
"test.cos.gnuplot", line 2: undefined variable: t
"test.sin.gnuplot", line 2: undefined variable: t
在日志中。将输入更改为
\draw [samples=1000] plot[parametric] function{t+2*sin(2*t),t+2*cos(5*t)};
给我一个情节:这是一行更改,所以我没有包含其他所有内容。要获取您的情节,我还会将域设置为-7:7
。
就我个人而言,我会使用pgfplots
,它使用了相同的基本思想,但我发现它更容易阅读。例如
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
axis lines = center ,
xtick = {-6.28318,-3.14159,...,6.3} ,
xticklabels = {$-2\pi$, $-\pi$, $0$, $\pi$, $2\pi$} ,
ytick = {-6.28318,-3.14159,...,6.3} ,
yticklabels = {$-2\pi$, $-\pi$, $0$, $\pi$, $2\pi$}
]
\addplot[domain = -7:7, parametric, samples = 1000]
gnuplot {t+2*sin(2*t),t+2*cos(5*t)};
\end{axis}
\end{tikzpicture}
\end{document}
这使
答案2
想一起去吗pgfplots
?
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[trig format plots=rad,variable=t,axis lines=middle]
\addplot[red,domain=-2*pi:2*pi,samples=200]
({t+2*sin(t)},
{t+2*cos(5*t)});
\end{axis}
\end{tikzpicture}
\end{document}