我想在乳胶中创建这个精确的图片,但我找不到这样做的代码......这是我的尝试:
\begin{tikzpicture}
\begin{axis}\[
axis lines=middle,
axis line style={-Latex, thick},
xlabel={$x$},
ylabel={$y$},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west},
xmin=-4, xmax=4,
ymin=-4, ymax=4,
xtick={-3,-2,...,3},
ytick={-3,-2,...,3},
grid=both,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!50},
minor tick num=1, % number of minor ticks between major ticks
ticklabel style={font=\small,fill=white},
legend style={draw=none, at={(0.5,-0.1)},anchor=north},
legend cell align={left}
\]
\addplot \[
domain=-3:3,
samples=100,
color=red,
thick
\]
{1/x};
\addlegendentry{$y = \frac{1}{x}$}
% Add points
\node\[label={180:{(1,1)}},circle,fill,inner sep=2pt\] at (axis cs:1,1) {};
\node\[label={180:{(2,0.5)}},circle,fill,inner sep=2pt\] at (axis cs:2,0.5) {};
\node\[label={180:{(3,0.333)}},circle,fill,inner sep=2pt\] at (axis cs:3,0.333) {};
\end{axis}
\end{tikzpicture}]
答案1
像这样:
代码 (tikz
):
\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[font=\sffamily\small]
%
\draw[gray!20,step=0.2] (-4,-4) grid (4,4);
\draw[gray!40] (-4,-4) grid (4,4);
%
\draw[->,thick] (-4,0) -- (4.5,0) node[anchor=west]{$x$};
\draw[->,thick] (0,-4) -- (0,4.5) node[anchor=south]{$y$};
%
\foreach \x in {-4,...,-1,1,2,3,4} \draw [thick](\x cm,-2pt) -- (\x cm,2pt) node[below] {\x};
\foreach \y in {-4,...,-1,1,2,3,4} \draw [thick](-2pt,\y) -- (2pt,\y) node[left]{\y};
\node at (-.2,-.2) () {$O$};
%
\clip (-4,-4) rectangle (4,4);
\draw[red,line width=2pt,step=.01] plot[domain=-4:-.1,smooth,samples=50] (\x,{1/\x});
\draw[red,line width=2pt,step=.01] plot[domain=.1:4,smooth,samples=50] (\x,{1/\x});
\fill (1,1) circle(2pt) node[above right] () {\bfseries $y=1$};
\fill (2,.5) circle(2pt) node[above right] () {\bfseries $y=\frac12$};
\fill (3,.33) circle(2pt) node[above right] () {\bfseries $y=\frac13$};
\end{tikzpicture}
\end{center}
\end{document}
Note
:我将域分成两部分以跳过 x=0 中的奇点。