Tikz/Pgfplots 选择性绘制

Tikz/Pgfplots 选择性绘制

我正在尝试将垂直开口双曲线的两个分支绘制到现有网格上。当我运行

\documentclass{article}

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}
\draw [thick,<->] (-10,0) -- (10,0) node[anchor=north west] {$x$};
\draw [thick,<->] (0,-10) -- (0,10) node[anchor=south east] {$t$};
\foreach \x in {-8,-6,-4,-2,2,4,6,8}
   \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {-8,-6,-4,-2,2,4,6,8}
    \draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
\draw plot[domain=-1:1] ({tan(\x)},{sec(\x)});
\draw plot[domain=-1:1] ({tan(\x)}, {-sec(\x)});
%\draw plot[domain=-1:1] ({cosh(\x)}, {sinh(\x)});
%\draw plot[domain=-1:1] ({-cosh(\x)}, {sinh(\x)});

\end{tikzpicture}
\end{document}

只绘制了 tx 轴。但是,当我使用相同的代码,取消注释水平开口双曲线时,会绘制水平开口双曲线。我能够在轴环境中绘制图表,但我想使用我绘制的坐标系。

答案1

经过近一年的时间......

  • 对于绘制 OP 图包pgfplots(顺便说一下,它基于tikz)比提供更好的支持tikz
  • tikz并且由这个在pgfplots也存在存在函数trig format通过它是可能的在三角函数确定其参数的单位考虑:弧度或者. 默认为度。
  • 为了比较三角函数双曲线的首先必须决定三角函数应采用哪些单位。

梅威瑟:

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[width=100mm,
 axis lines = center,
     xlabel = $x$,
     ylabel = $f(x)$,
     label style = {anchor=north east},
tick label style = {font=\scriptsize, minimum height=3ex, inner sep=0pt},
      xtick = {-2*pi,-1.5*pi,-pi,-0.5*pi,0.5*pi,pi,1.5*pi,2*pi},
xticklabels = {$-2\pi$,$-\frac32\pi$,$-\pi$,$-\frac12\pi$,
               $\frac12\pi$,  $\pi$, $\frac32\pi$, $2\pi$},
trig format = rad,            % <-------
    samples = 1001, 
     domain = -2*pi:2*pi,
       xmin = -7.5, xmax=7.5,
restrict y to domain=-9:9,
   no marks,
legend style = {legend pos=outer north east, anchor=north,
                legend cell align=left,
                font=\scriptsize},
every axis plot post/.append style={thick}
             ]
% trigonometric
\addplot    {tan(\x)};
% hyperbolic
\addplot    {cosh(\x)};
\addplot    {-cosh(\x)};
\addplot    {sinh(\x)} ;

\legend{$\tan(x)$, $\cosh(x)$, $-\cosh(x)$, $\sinh(x)$}
\end{axis}
    \end{tikzpicture}
\end{document}

結果為trig format = rad

在此处输入图片描述

并且当trig format = deg轴前导为时:

\begin{axis}[width=100mm,
 axis lines = center,
     xlabel = $x$,
     ylabel = $f(x)$,
     label style = {anchor=north east},
tick label style = {font=\scriptsize, minimum height=3ex, inner sep=0pt},
trig format = deg,            % <-------
    samples = 1001, 
     domain = -2*pi:2*pi,
       xmin = -7.5, xmax=7.5,
restrict y to domain=-9:9,
   no marks,
legend style = {legend pos=outer north east, anchor=north,
                legend cell align=left,
                font=\scriptsize},
every axis plot post/.append style={thick}
             ]

在此处输入图片描述

答案2

我尝试单独绘制数据。

v01

\documentclass[border=5pt]{standalone}

\usepackage{tikz}

\begin{document}
    
    \begin{tikzpicture}
        \draw [thick,latex-latex] (-10,0) -- (10,0) node[anchor=north west] {$x$};
        \draw [thick,latex-latex] (0,-10) -- (0,10) node[anchor=south east] {$t$};
        \foreach \x/\y in {-8,-6,-4,-2,2,4,6,8} {
            \draw (\x cm,3pt) -- (\x cm,-3pt) node[anchor=north] {$\x$};
            \draw (3pt,\y cm) -- (-3pt,\y cm) node[anchor=east] {$\y$};
        }
    
        \draw plot[domain=-1:1] (\x,{tan(deg(\x))});
        \draw plot[domain=-1:1] (\x,{sec(deg(\x))});
                
%       \draw plot[domain=-1:1] (\x,{tan(deg(\x))});
        \draw plot[domain=-1:1] (\x,{-sec(deg(\x))});

        \draw plot[domain=-1:1] (\x,{cosh(\x)});
        \draw plot[domain=-1:1] (\x,{sinh(\x)});
        
        \draw plot[domain=-1:1] (\x,{-cosh(\x)});
        \draw plot[domain=-1:1] (\x,{sinh(\x)});
        
    \end{tikzpicture}
\end{document}

也许您可以添加一些颜色(在\draw环境中)以获得更好的可视化和区分。

相关内容