在 TikZ 中绘制以 b 为底的对数

在 TikZ 中绘制以 b 为底的对数
\begin{tikzpicture}[line cap=round,,x=1.3cm,y=0.4cm]
\clip(-1,-3) rectangle (12,13);
\draw [domain=0.1:10 ,smooth,very thick] plot(\x, \Log{2}{3*\x}); 
\draw[->,color=black,line width = 0.8pt] (0,0.) -- (11,0.);
\draw[->,color=black,line width = 0.8pt] (0,0.) -- (-1,0.);
\draw[->,color=black,line width = 0.8pt] (0.,0) -- (0,13);
\draw[->,color=black,line width = 0.8pt] (0.,0) -- (0,-2);
\end{tikzpicture}

答案1

欢迎来到 TeX.SE!抱歉,我不懂西班牙语,但如果您想知道您的代码是否编译:\Log{2}{3*\x}不是要绘制的有效函数。除了您不应该\...在这里之外,这很适合印刷(而不是绘图)函数,默认情况下tikz不理解\log_2

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
    \begin{tikzpicture}[line cap=round,,x=1.3cm,y=0.4cm]
    \clip(-1,-3) rectangle (12,13);
    \draw [domain=0.1:10 ,smooth,very thick,samples=50] plot(\x, {ln(3*\x)/ln(2)}); 
    \draw[->,color=black,line width = 0.8pt] (0,0.) -- (11,0.);
    \draw[->,color=black,line width = 0.8pt] (0,0.) -- (-1,0.);
    \draw[->,color=black,line width = 0.8pt] (0.,0) -- (0,13);
    \draw[->,color=black,line width = 0.8pt] (0.,0) -- (0,-2);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

当然,你可以Log自己定义一个函数。(拼写错误已修复,非常感谢 Henri Menke!)

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
    \begin{tikzpicture}[line cap=round,,x=1.3cm,y=0.4cm,
    declare function={Log(\b,\x)=ln(\x)/ln(\b);}]
    \clip(-1,-3) rectangle (12,13);
    \draw [domain=0.1:10 ,smooth,very thick,samples=50] plot(\x, {Log(2,3*\x)}); 
    \draw[->,color=black,line width = 0.8pt] (0,0.) -- (11,0.);
    \draw[->,color=black,line width = 0.8pt] (0,0.) -- (-1,0.);
    \draw[->,color=black,line width = 0.8pt] (0.,0) -- (0,13);
    \draw[->,color=black,line width = 0.8pt] (0.,0) -- (0,-2);
    \end{tikzpicture}
\end{document}

相关内容