不規則性のない対数関数グラフの描き方

不規則性のない対数関数グラフの描き方

この最小限の動作例では、自然対数関数のグラフに 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}

ここに画像の説明を入力してください

関連情報