如何画出不规则的对数函数图形

如何画出不规则的对数函数图形

在这个最小的工作示例中,自然对数函数的图形在 x = 0.5 和 x = 0.6 之间有一个瑕疵,不知道为什么......有人知道如何摆脱它并得到一个平滑的图形吗?

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
%
\begin{tikzpicture}
\coordinate (OR) at (0.00, 0.00);
\coordinate (LX) at (-1.00, 0.00); % left x
\coordinate (RX) at (8.00, 0.00); % right x
\coordinate (BY) at (0.00, -5.00); % bottom y
\coordinate (TY) at (0.00, 3.00); % top y
%
% axa 0x
%
\draw[->][line width=1.00pt] (LX) -- (RX);
\node[blue] at (7.8,-0.4) {\textbf{\textit{x}}};
%
% axa 0y
%
\draw[->][line width=1.00pt] (BY) -- (TY);
\node[right,blue] at (0.2, 2.8) {\textbf{\textit{ln x}}};
%
% ORIGIN
% 
\filldraw [red] (OR) circle(2pt);
\node[red] at (0.2,-0.3) {\textbf{\textit{0}}};
%
\draw[red,dotted,line width=0.75pt] (0.5, 0.0) -- (0.5, -1.0);
\draw[red,dotted,line width=0.75pt] (0.6, 0.0) -- (0.6, -1.0);
% graphic for LOGARITHM function
\draw[blue, line width=1.75pt, domain=0.005:7.00] plot[smooth](\x, {ln(\x)});
%\draw[blue, line width=1.75pt, domain=0.01:7.00] plot[smooth](\x, {ln(\x)});
%
\end{tikzpicture}
\end{document}

答案1

您可以强制它采取更多的采样点

在此处输入图片描述

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
%
\begin{tikzpicture}
\coordinate (OR) at (0.00, 0.00);
\coordinate (LX) at (-1.00, 0.00); % left x
\coordinate (RX) at (8.00, 0.00); % right x
\coordinate (BY) at (0.00, -5.00); % bottom y
\coordinate (TY) at (0.00, 3.00); % top y
%
% axa 0x
%
\draw[->][line width=1.00pt] (LX) -- (RX);
\node[blue] at (7.8,-0.4) {\textbf{\textit{x}}};
%
% axa 0y
%
\draw[->][line width=1.00pt] (BY) -- (TY);
\node[right,blue] at (0.2, 2.8) {\textbf{\textit{ln x}}};
%
% ORIGIN
% 
\filldraw [red] (OR) circle(2pt);
\node[red] at (0.2,-0.3) {\textbf{\textit{0}}};
%
\draw[red,dotted,line width=0.75pt] (0.5, 0.0) -- (0.5, -1.0);
\draw[red,dotted,line width=0.75pt] (0.6, 0.0) -- (0.6, -1.0);
% graphic for LOGARITHM function
\draw[blue, line width=1.75pt, domain=0.005:7.00,samples=500] plot[smooth](\x, {ln(\x)});
%\draw[blue, line width=1.75pt, domain=0.01:7.00] plot[smooth](\x, {ln(\x)});
%
\end{tikzpicture}
\end{document}

答案2

您已经加载pgfplots了为此设计的程序,为什么不使用它呢?您的代码将更加简单:

\documentclass[border=3pt]{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xtick=\empty,
ytick=\empty,
clip=false
]
\addplot+[no marks,blue,line width=1pt,samples=150,domain=0.1:7] {ln(x)};
\draw[red,dotted,line width=0.75pt] (axis cs:0.5, 0.0) -- (axis cs:0.5, -1.0);
\draw[red,dotted,line width=0.75pt] (axis cs:0.6, 0.0) -- (axis cs:0.6, -1.0);
\node[label={[red]-45:0},fill=red,inner sep=1.5pt,circle] at (axis cs:0.02,0) {};
\node[right,blue] at (axis cs:0.2,1.8) {\textbf{\textit{ln x}}};
\node[below,blue] at (axis cs:7,-0.2) {\textbf{\textit{x}}};
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容