我如何绘制 x 轴和 y 轴以便 Latex 在其上显示刻度数?(1 个单位)
我尝试:
\begin{center}
\begin{tikzpicture}[scale=0.5]
\draw[very thick,blue] (3,-4) ellipse ({4} and {3});
\end{tikzpicture}
\end{center}
答案1
对于大多数图表,我建议使用pgfplots
,但您也可以使用手动绘制轴和刻度\draw
:
笔记:
- 如果您希望为每个单元绘制它们,则将更改为
\foreach \x in {-1,1,...,8}
,\foreach \x in {-1,...,8}
这会将步长从 2 更改为 1。
代码:
\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{axis line style/.style={thin, gray, -stealth}}
\newcommand*{\TickSize}{2pt}%
\begin{document}
\begin{tikzpicture}[scale=0.5]
\draw[very thick,blue] (3,-4) ellipse ({4} and {3});
\draw [axis line style] (-2.5,0) -- (8.5,0);% x-axis
\draw [axis line style] (0,-8.5) -- (0,2.5);% y-axis
\foreach \x in {-1,1,...,8} {%
\draw ($(\x,0) + (0,-\TickSize)$) -- ($(\x,0) + (0,\TickSize)$)
node [above] {$\x$};
}
\foreach \y in {-7,-5,...,2} {%
\draw ($(0,\y) + (-\TickSize,0)$) -- ($(0,\y) + (\TickSize,0)$)
node [right] {$\y$};
}
\end{tikzpicture}
\end{document}