绘制三角函数

绘制三角函数

我试图绘制正弦函数图。我找到了 PSTricks 并尝试使用它,但我不知道是否有更标准/更合适的软件包可以做到这一点。

这是我做的(很悲惨):

\psset{unit=1cm}
\begin{center}
\begin{pspicture}(-3.5,-2)(6.5,2)
    \psaxes[dx=\pstPI4,trigLabelBase=2,trigLabels]{->}(0,0)(-3.2,-1.25)(6.5,1.25)
    \psplot[xunit=0.5cm,linecolor=red,linewidth=1.5pt,plotpoints = 100]{-\psPiTwo}{\psPiFour}{x RadToDeg sin}
\end{pspicture}
\end{center}

你们有人能给我一些建议,如何让它变得更好吗?我其实不太明白为什么我需要把它放在{-\psPiTwo}{\psPiFour}那里,但我试着把它改成其他的东西,但效果似乎不太好。

谢谢!

答案1

这是一些可以让你动起来的东西。

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
grid=both,
domain=-2*pi:2*pi,
samples=200,
no marks,
xticklabels={-2$\pi$,-1.5$\pi$,...$\pi$,2$\pi$},
xtick={-6.2832,-4.7124,...,6.2832},
x post scale=1.5
]
\addplot {2*sin(deg(x))+0.8*sin(pi*deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

用户定义常量的说明:

在此处输入图片描述

注意:上面的描述图使用常量来提供足够的注释空间。下面的示例使用了不同的常量。不要混淆!

用户定义常量:

\def\f(#1){sin(#1)}% function to plot
\def\g(#1){1.5*cos(2*#1)}% function to plot

\const{Width}{10}% total width in cm
\const{Height}{4}% total height in cm 

\const{POL}{-0.20}% pspicture left offset in cm
\const{POR}{ 0.50}% pspicture right offset in cm
\const{POB}{-0.20}% pspicture bottom offset in cm
\const{POT}{ 0.50}% pspicture top offset in cm

\const{AOL}{-0.20}% axis left offset in cm
\const{AOR}{ 0.30}% axis right offset in cm
\const{AOB}{-0.20}% axis bottom offset in cm
\const{AOT}{ 0.30}% axis top offset in cm

\const{DomL}{-2*pi}% domain left  
\const{DomR}{2*pi}% domain right  
\const{DomB}{-2}% domain bottom  
\const{DomT}{ 2}% domain top 

\const[0]{TrigLabelBase}{2}% denominator for a fraction of pi

输出和完整代码:

在此处输入图片描述

\documentclass[border=0pt,pstricks]{standalone}
\usepackage{pst-eucl,pstricks-add}
\usepackage[nomessages]{fp}
\newcommand\const[3][3]{\expandafter\FPeval\csname#2\endcsname{round(#3:#1)}}


% User defined data:
\def\f(#1){sin(#1)}% function to plot
\def\g(#1){1.5*cos(2*#1)}% function to plot

\const{Width}{10}% total width in cm
\const{Height}{4}% total height in cm 

\const{POL}{-0.20}% pspicture left offset in cm
\const{POR}{ 0.50}% pspicture right offset in cm
\const{POB}{-0.20}% pspicture bottom offset in cm
\const{POT}{ 0.50}% pspicture top offset in cm

\const{AOL}{-0.20}% axis left offset in cm
\const{AOR}{ 0.30}% axis right offset in cm
\const{AOB}{-0.20}% axis bottom offset in cm
\const{AOT}{ 0.30}% axis top offset in cm

\const{DomL}{-2*pi}% domain left  
\const{DomR}{2*pi}% domain right  
\const{DomB}{-2}% domain bottom  
\const{DomT}{ 2}% domain top 

\const[0]{TrigLabelBase}{2}% denominator for a fraction of pi

% Internal used constants:
\const{XUnit}{(Width-POR+POL-AOR+AOL)/(DomR-DomL)}
\const{YUnit}{(Height-POT+POB-AOT+AOB)/(DomT-DomB)}

\const{PicL}{(POL+AOL)/XUnit+DomL}
\const{PicR}{(POR+AOR)/XUnit+DomR}
\const{PicB}{(POB+AOB)/YUnit+DomB}
\const{PicT}{(POT+AOT)/YUnit+DomT}

\const{AxiL}{AOL/XUnit+DomL}
\const{AxiR}{AOR/XUnit+DomR}
\const{AxiB}{AOB/YUnit+DomB}
\const{AxiT}{AOT/YUnit+DomT}

\const{DeltaX}{pi/TrigLabelBase}

\psset{xunit=\XUnit,yunit=\YUnit,algebraic,plotpoints=500}

\begin{document}


\begin{pspicture}[showgrid=false](\PicL,\PicB)(\PicR,\PicT)
    \psplot[linecolor=red]{\DomL}{\DomR}{\f(x)}
    \psplot[linecolor=blue]{\DomL}{\DomR}{\g(x)}
    \psaxes
    [
        trigLabels=true,
        labelFontSize=\scriptscriptstyle,
        tickcolor=gray,
        ticksize=-1.5pt 1.5pt,
        xlabelsep=3pt,
        arrowscale=1,
        trigLabelBase=\TrigLabelBase,
        dx=\DeltaX,% must come before xunit to avoid getting a strange output!  
    ]{->}(0,0)(\AxiL,\AxiB)(\AxiR,\AxiT)[$x$,0][$y$,90]
\end{pspicture}


\end{document}

相关内容