
在這個最小的工作範例中,自然對數函數的圖形在 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
為此設計的 whcih,為什麼不使用它呢?你的程式碼會更簡單:
\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}