我正在尝试创建时域和频域中的数量图,如下所示。显示的图是已经讨论过的修改后的图这里。
但是,我需要使用(可能,但不一定)绘制文件中的数据,\addplot
或者\addplot3
代替使用 \draw 绘制分析函数(如下面的代码所示)。此外,我还需要在轴上添加刻度和数字(刻度)。我希望axis
在这种情况下应该使用环境。
因此,我尝试添加axis
环境,但没有成功。您知道如何实现吗?
谢谢您的任何建议!
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x={(0.7cm,1cm)},z={(0cm,1cm)},y={(1cm,0cm)}]
\draw[->] (0,-pi,0) --++ (6,0,0) node[above right] {Frequency};
\draw[->] (0,-pi,0) --++ (0,6.5,0) node[right] {Time};
\draw[->] (0,-pi,0) --++ (0,0,1.5) node[above] {Magnitude};
\foreach \y in {1,2,...,5}{
\draw[blue] plot[domain = -pi:+pi, samples = 300]
(\y,\x,{0.2*cos(10*\y/2*(\x) r)});
\draw[blue] (\y,-pi-0.15,0) node [left]{$f_{\y}$};
}
\draw[red, thick] plot[domain = -pi:+pi, samples = 2000]
(0,\x,{0.02*sin(50*(\x) r)/(\x))});
\end{tikzpicture}
\end{document}
答案1
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={20}{80}, domain=0:10*pi, samples=1000, samples y=0, thick,
xmin=0, xmax=10*pi, xtick=\empty, xticklabel=\empty, xlabel=Time, axis line style={->}, axis x line=center, xlabel style={anchor=north},
ymin=1, ymax=7, ytick={1,2,...,6}, yticklabels={{}, $f_1$, $f_2$, $f_3$, $f_4$, $f_5$}, ylabel=Frequency, axis line style={->}, axis y line=center, ylabel style={anchor=west}, yticklabel style={anchor=south east, blue},
zmin=-1, zmax=2, ztick=\empty, zticklabel=\empty, zlabel=Magnitude, axis line style={->}, axis z line=center, zlabel style={anchor=east}
]
\addplot3[red] ({x}, {1}, {2*sin(deg(10*(x-5*pi)))/(10*(x-5*pi))});
\addplot3[blue] ({x}, {2}, {-cos(deg(x))});
\addplot3[blue] ({x}, {3}, {cos(deg(2*x))});
\addplot3[blue] ({x}, {4}, {-cos(deg(3*x))});
\addplot3[blue] ({x}, {5}, {cos(deg(4*x))});
\addplot3[blue] ({x}, {6}, {-cos(deg(5*x))});
\end{axis}
\end{tikzpicture}
\end{document}
对于视图而言,我真诚地除了设置之外从未做过任何其他事情view={<azimuth>}{<elevation>}
;您可以查看 4.10.1 美元的pgfplots 手册修订版 1.13。