如何使用tikz
包在 LaTeX 中创建一个带有线性线的简单坐标系?它应该看起来像这样。每个轴上都有迭代数字。
答案1
使用tkz-euclide
用于简单输出的包。
\documentclass[tikz]{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{figure}[h]
\begin{tikzpicture}
\tkzInit[xmax=6,ymax=6,xmin=-6,ymin=-6]
\tkzGrid
\tkzAxeXY
\draw[ thick,latex-latex] (-1,4) -- (4,-6) node[anchor=south west] {$a$}; % two points for drawing 2x+y=2
\tkzText[above](0,6.75){Desired Output}
\end{tikzpicture}
\end{figure}
\end{document}
输出:
答案2
什么,没有pgfplots
例子?
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
axis line style={Stealth-Stealth,very thick},
xmin=-5.5,xmax=5.5,ymin=-5.5,ymax=5.5,
xtick distance=1,
ytick distance=1,
xlabel=$x$,
ylabel=$y$,
title={Wonderful plot},
grid=major,
grid style={thin,densely dotted,black!20}]
\addplot [Latex-Latex,domain=-5:3,samples=2] {x*2/3} node[right]{$a$};
\end{axis}
\end{tikzpicture}
\end{document}
答案3
这是一个可能的解决方案。这里同时给出了欧几里得坐标和极坐标。此外,给出两个点,通过延伸端点绘制一条线
extended line/.style={shorten >=-#1,shorten <=-#1}
添加了根据两个点绘制线的宏。
\newcommand{\drawaline}[4]{
\draw [extended line=1cm,stealth-stealth] (#1,#2)--(#3,#4);
}
代码
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc}
\newcommand{\drawaline}[4]{
\draw [extended line=1cm,stealth-stealth] (#1,#2)--(#3,#4);
}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.5,extended line/.style={shorten >=-#1,shorten <=-#1},]
\draw [help lines] (-3,-3) grid (3,3);
% Euclidean
\draw [->](0,-2.2)--(0,2.2) node[right]{$y$};
\draw [->](-2.2,0)--(2.2,0) node[right]{$x$};
% polar coordinate
\draw (0,0)--(2,2)node[anchor=south west]{$x+jy=r\angle \theta$};
\draw [thin,dashed] (2,2)--(2,0);
\draw (0.8,1)node[anchor=west,rotate=45]{$r=\sqrt{x^2+y^2}$};
\draw [fill=green](0,0) -- (0.75,0) arc (0:45:0.75cm);
\draw (1,0.3) node[rotate=10]{$\theta=\tan^{-1} \frac{y}{x}$};
\fill [red](2,2) circle(2pt);
% draw ticks and its labels
\foreach \x/\xtext in {-2/-2, -1.5/-\frac{3}{2}, -1/-1, -0.5/-\frac{1}{2}, 0.5/\frac{1}{2}, 1/1, 1.5/\frac{3}{2}, 2/2}
{\draw (\x cm,1pt ) -- (\x cm,-1pt ) node[anchor=north] {$\xtext$};}
\foreach \y/\ytext in {-2/-2, -1.5/-\frac{3}{2}, -1/-1, -0.5/-\frac{1}{2},0.5/\frac{1}{2}, 1/1, 1.5/\frac{3}{2}, 2/2}
{\draw (1pt,\y cm) -- (-1pt ,\y cm) node[anchor=east] {$\ytext$};}
% draw lines
\draw [extended line=1cm,stealth-stealth] (-2,-1)--(1,2) node[above]{a}; % method 1
\drawaline{0}{-2}{-2}{0} % method 2
\end{tikzpicture}
\end{center}
\end{document}
答案4
这只是 PSTricks 的另一种乐趣。
\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-plot}
\psset{algebraic,arrows=<->}
\def\f{x/3+1}
\begin{document}
\begin{pspicture}(-6,-3)(6.5,4.5)
\psaxes[linewidth=.4pt,linecolor=gray](0,0)(-6,-3)(6,4)[$x$,0][$y$,90]
\psplot[linecolor=blue]{-5}{5}{\f}
\rput(*5.2 {\f}){$a$}
\end{pspicture}
\end{document}