初学者:使用 Tikz 绘图

初学者:使用 Tikz 绘图

TikZ 生成的图形给我留下了深刻的印象,我想尝试使用 TikZ 生成一些图形(请参阅使用外部 WYSWYG 程序绘制的附图)。当我尝试使用 TikZ 自己重现这些图形时,我发现很难将形状控制在所需的位置。使用 TikZ 绘制这些图形的最简单方法是什么?

在此处输入图片描述

答案1

使用下面的代码,您可以获得第一个例子。阅读TiKZ文档 (pgfmanual) 中的第一个教程后,可以轻松完成所有其他操作。

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw [->] (-1.5,0)--(3,0);
\draw [->] (0,-1.5)--(0,3);
\draw[dashed] (-1,0)--(0,1)--(1,0)--(0,-1)--cycle;
\node[below left] at (0,0) {$x$};
\draw[shorten <=-1cm, shorten >=-3mm] (0,1)--(2,0) node [midway, above] {$A$};
\node[above right] at (0,1) {$\hat{x}$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

从 TikZ(374 个字符)直接翻译到 PSTricks(362 个字符)。

\documentclass[pstricks,border=3mm]{standalone}
\usepackage{pst-node}

\begin{document}
\begin{pspicture}(-1.5,-1.5)(3,3)
    \psline{->}(-1.5,0)(3,0)
    \psline{->}(0,-1.5)(0,3)
    \pspolygon[linestyle=dashed](-1,0)(0,1)(1,0)(0,-1)
    \uput[-135](0,0){$x$}
    \pcline[nodesepA=-1,nodesepB=-3mm](0,1)(2,0)\naput{$A$}
    \uput[45](0,1){$\hat{x}$}
\end{pspicture}
\end{document}

在此处输入图片描述

相关内容