在这种情况下,我想x^2 - x - 6
使用foreach
(MWE 中的坐标)从图中绘制一些点。不幸的是,当我插入循环时foreach
,错误显示
Undefined control sequence. \end{axis}
并且,我已经提前使用了这些参考资料来帮助解决我的情况,但却没有找到解决方案:
(实际上还有更多,但我忘记了链接)。
这是我的代码,希望有人能够帮助它。
\documentclass{article}
\usepackage{amsmath, amsthm, amsfonts, amssymb}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{mathrsfs}
\pgfplotsset{compat=newest}
\mdfdefinestyle{mdgreenbox}{
skipabove = 8pt,
skipbelow = 8pt,
linewidth = 2pt,
rightline = false,
leftline = true,
topline = false,
bottomline = false,
linecolor = green,
backgroundcolor = green!5,
}
\begin{mdframed}[style=mdgreenbox]
Lorem ipsum...
{\centering
\begin{tikzpicture}[]
\begin{axis}[
x = .7cm, y = .7cm,
axis lines = middle,
xlabel = $x$, ylabel=$y$,
xtick = {-5, 0, 5, 10},
ytick = {-15, -10, ..., 5},
minor tick num = 4,
xmin = -3.3, xmax = 4.3,
ymin = -7.3, ymax = 5.3,
font = \tiny
]
\draw[black, thin, smooth, domain = -7 : 12] plot (\x, {(\x)^2 - 1 * (\x) - 6});
% Here...
\foreach \x/\y in {-3/4, -2/0, -1/-4, 0/-6, 1/-6, 2/-4, 3/0, 4/6}{
\node at (\x, \y) {\textbullet};
}
\end{axis}
\end{tikzpicture}\par}
\end{mdframed}
PS 另外,有没有办法,对于每个图表,我都可以使用一个确定的foreach
代码来绘制我的观点?