在乳膠中繪製 cot(x)

在乳膠中繪製 cot(x)
\begin{document}

\begin{tikzpicture}
    \begin{axis}
        \addplot{cot(deg(x))};
    \end{axis}
\end{tikzpicture}

\end{document}

我嘗試使用上面的程式碼繪製 cot(x) 但它向我顯示了這樣的圖表 在此輸入影像描述

什麼地方出錯?

答案1

根本沒有足夠的採樣點:

\documentclass[tikz]{standalone}
    \usepackage{pgfplots}
    \begin{document}
    \begin{tikzpicture}
        \begin{axis}
            \addplot[domain=0:360,samples=361]{cot(x)};
        \end{axis}
    \end{tikzpicture}
\end{document}

沒有錯誤

編輯:我注意到您的範例中 y 軸上的比例給出為 $n\cdot10^4$,問題的更完整描述是預設取樣選擇了一個非常接近 $0$ 的點,因此該值此時的$ \cot(x)$ 非常大,使得所有其他點都非常靠近x 軸。這裡也出現類似的效果:

\documentclass[tikz]{standalone}
    \usepackage{pgfplots}
    \begin{document}
    \begin{tikzpicture}
        \begin{axis}
            \addplot[domain=-5:5,samples=1024]{cot(x)};
        \end{axis}
    \end{tikzpicture}
\end{document}

與 Q 相同的錯誤

為了避免將來出現此類問題,請考慮是否有任何意外情況,系統會在函數的極值附近進行取樣。

相關內容