如何在 LaTeX 中绘制以 \pi 为坐标的余割、正割和余切图beamer
?
答案1
如果需要 TikZ 解决方案,
从 TikZ 手册第 1047 页的示例开始(texdoc pgfmanual
),
起点可能是这样的:
请注意,这只是 15 分钟的尝试和查阅手册的结果(今天太冷,不适合进一步探索)。显然,可以绘制出更复杂的图。但即便如此,各种功能之间的内在相互关系已经非常明显。
平均能量损失
\documentclass[12pt]{article}
\usepackage{tikz}
%=====================================
\begin{document}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (3,2);
\draw [blue, thick, x=0.0085cm, y=1cm,
declare function={
sines(\t,\a,\b)=1 + 0.5*(sin(\t)+sin(\t*\a)+sin(\t*\b));
}]
plot [domain=0:360, samples=144, smooth] (\x,{sines(\x,3,5)});
\end{tikzpicture}
\begin{tikzpicture}
\draw [help lines] (0,-2) grid (3,2);
\draw [blue, thick, x=0.0085cm, y=1cm] plot [domain=0:360, samples=144, smooth] (\x,{sin(\x)}) node[above] {$sin$};
\draw [red, thick, x=0.0085cm, y=1cm] plot [domain=0:360, samples=144, smooth] (\x,{cos(\x)}) node[above] {$cos$};
\draw [green, thick, x=0.0085cm, y=1cm] plot [domain=0:70, samples=144, smooth] (\x,{tan(\x)}) node[above] {$tan$};
\draw [brown, dotted, thick, x=0.0085cm, y=1cm] plot [domain=0:70, samples=144, smooth] (\x,{sec(\x)}) node[above] {$sec$};
\draw [blue, dashed, thick, x=0.0085cm, y=1cm] plot [domain=30:150, samples=144, smooth] (\x,{cosec(\x)}) node[above] {$cosec$};
\draw [black, dashed, thin, x=0.0085cm, y=1cm, pin=90:$cot$] plot [domain=15:155, samples=144, smooth] (\x,{cot(\x)}) node[above] {$cot$};
\end{tikzpicture}
\end{document}
附录
事实上,该手册的第 81.5 节(第 857 页)正好切中要点,不需要重新发明轮子。
手册的这一部分涉及应用样式,并使用\datavisualization
sin/cos/tan 上的命令。有了该代码作为模板,添加更多函数就变得轻而易举了。
以供参考:
\usetikzlibrary {datavisualization.formats.functions}
\begin{tikzpicture}[baseline]
\datavisualization [ scientific axes=clean,
y axis=grid,
visualize as smooth line/.list={sin,cos,tan},
style sheet=strong colors,
style sheet=vary dashing,
sin={label in legend={text=$\sin x$}},
cos={label in legend={text=$\cos x$}},
tan={label in legend={text=$\tan x$}},
data/format=function ]
data [set=sin] {
var x : interval [-0.5*pi:4];
func y = sin(\value x r);
}
data [set=cos] {
var x : interval [-0.5*pi:4];
func y = cos(\value x r);
}
data [set=tan] {
var x : interval [-0.3*pi:.3*pi];
func y = tan(\value x r);
};
\end{tikzpicture}
附录2:
在我们等待 MWE 的同时,进一步阅读手册——并将计算值保持在 32k 界限内作为第一次近似值——得出了以下结论:
一下子把所有事情都看完,确实有点‘忙’。
分层呈现、每次展示部分内容是一种有用的教学方法。
并且考虑到排版引擎为实现此目的所需的手工编码量(主要是为了避免无穷大的边缘),这种类型的大容量、多输出图形集可能更适合由专用的图形应用程序生成,然后导入到乳胶中。
平均能量损失
\documentclass[12pt]{article}
\usepackage{xcolor}
\pagecolor{red!3}
\usepackage{unicode-math}
\setmainfont{Noto Serif}
\setmathfont{XITS Math}
\usepackage{tikz}
\usetikzlibrary {datavisualization.formats.functions}
%=====================================
\begin{document}
\begin{tikzpicture}[baseline]
\datavisualization [ scientific axes=clean,
y axis = {ticks=few,grid},
x axis = {ticks=few,ticks and grid ={ major at={%
(-2*pi) as $-2\pi$,
(-3*pi/2) as $\frac{-3\pi}{2}$,
(-pi) as $-\pi$,
(-pi/2) as $\frac{-\pi}{2}$,
(0) as $0$,
(pi/2) as $\frac{\pi}{2}$,
(pi) as $\pi$,
(3*pi/2) as $\frac{3\pi}{2}$,
(2*pi) as $2\pi$,
}}},
visualize as smooth line/.list={sin,cos,tan,tan2,tan3,sec,sec2,sec3,cosec,cosec2,cosec3,cosec4,cot,cot2,cot3,cot4},
style sheet=strong colors,
%style sheet=vary dashing,
sin={label in legend={text=$\sin x$}},
cos={label in legend={text=$\cos x$}},
tan={label in legend={text=$\tan x$},style={visualizer color=blue!50, densely dotted, thick}},
tan2={style={visualizer color=blue!50, densely dotted, thick}},
tan3={style={visualizer color=blue!50, densely dotted, thick}},
sec={label in legend={text=$\sec x$},style={visualizer color=brown, dash dot, thick}},
sec2={style={visualizer color=brown, dash dot, thick}},
sec3={style={visualizer color=brown, dash dot, thick}},
cosec={label in legend={text=$\csc x$},style={visualizer color=green!50!black, dash dot dot, thick}},
cosec2={style={visualizer color=green!50!black, dash dot dot, thick}},
cosec3={style={visualizer color=green!50!black, dash dot dot, thick}},
cosec4={style={visualizer color=green!50!black, dash dot dot, thick}},
cot={label in legend={text=$\cot x$},style={visualizer color=red!50, densely dashed, thick}},
cot2={style={visualizer color=red!50, densely dashed, thick}},
cot3={style={visualizer color=red!50, densely dashed, thick}},
cot4={style={visualizer color=red!50, densely dashed, thick}},
data/format=function ]
data [set=sin] {
var x : interval [-2*pi:2*pi];
func y = sin(\value x r);
}
data [set=cos] {
var x : interval [-2*pi:2*pi];
func y = cos(\value x r);
}
data [set=tan] {
var x : interval [-0.3*pi:.35*pi];
func y = tan(\value x r);
}
data [set=tan2] {
var x : interval [(pi/2)+0.45:3*pi/2-0.45];
func y = tan(\value x r);
}
data [set=tan3] {
var x : interval [(-3*pi/2)+0.45:-pi/2-0.45];
func y = tan(\value x r);
}
data [set=sec] {
var x : interval [(-pi/2)+0.45:pi/2-0.45];
func y = sec(\value x r);
}
data [set=sec2] {
var x : interval [(pi/2)+0.45:3*pi/2-0.45];
func y = sec(\value x r);
}
data [set=sec3] {
var x : interval [(-3*pi/2)+0.45:-pi/2-0.45];
func y = sec(\value x r);
}
data [set=cosec] {
var x : interval [(0)+0.45:pi-0.45];
func y = cosec(\value x r);
}
data [set=cosec2] {
var x : interval [(-pi)+0.45:0-0.45];
func y = cosec(\value x r);
}
data [set=cosec3] {
var x : interval [(pi)+0.45:2*pi-0.45];
func y = cosec(\value x r);
}
data [set=cosec4] {
var x : interval [(-2*pi)+0.45:-pi-0.45];
func y = cosec(\value x r);
}
data [set=cot] {
var x : interval [0+0.55:pi-0.55];
func y = cot(\value x r);
}
data [set=cot2] {
var x : interval [(pi)+0.55:2*pi-0.55];
func y = cot(\value x r);
}
data [set=cot3] {
var x : interval [(-pi)+0.55:0-0.55];
func y = cot(\value x r);
}
data [set=cot4] {
var x : interval [(-2*pi)+0.55:-pi-0.55];
func y = cot(\value x r);
}
;
\end{tikzpicture}
\end{document}