In this case, I would like to plot some points from the graph of x^2 - x - 6 using foreach (coordinate in the MWE). Unfortunately, when I plug the foreach loop, the error stated
Undefined control sequence. \end{axis}
And, I've used these reference in advance to help with my case, yet doesn't yield anywhere to the solution :
(Actually, there're more but I forgot the link, though).
Here's my code, hopefully someone be able to help it.
\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}
P.S. Also, is there anyway, so for each graph, I could use a definite foreach code to plot my points?
Before, I used to use that code structure to design my graph though.
– Wilory Lu Sep 17 '23 at 13:07\node foreach \x/\y in {-3/4, -2/0, -1/-4, 0/-6, 1/-6, 2/-4, 3/0, 4/6} [circle, fill, inner sep=+0pt, minimum size=+2.5pt] at (\x, \y) {};or\fill[radius=1.25pt] foreach \x/\y in {-3/4, -2/0, -1/-4, 0/-6, 1/-6, 2/-4, 3/0, 4/6} {(\x, \y) circle[]};The problem, yet again, was a (grouped) loop inside theaxisenvironment. This makes trouble oftentimes. – Qrrbrbirlbel Sep 17 '23 at 13:24declare function={f(\x)=(\x)^2 - 1 * (\x) - 6;}as an option to thetikzpictureenvironment, you can replace(\x, {(\x)^2 …})by(\x, {f(\x)})and the points can then be placed a bit easier, too:\fill[radius=1.25pt] foreach \x in {-3, -2, ..., 4} {(\x, {f(\x)}) circle[]};. — By the way, is there a reason you use theaxisenvironment from the PGFPlots package but not its\addplotcommand? – Qrrbrbirlbel Sep 17 '23 at 13:31keyfrom either\fillor\node, is it? – Wilory Lu Sep 17 '23 at 13:32