# Generating Samples at Points used in pgfplots

For one of my academic courses, i need to generate sample lattices and was wondering if there was any way to generalize the hard-coded points I am using. Instead of repeating -5.19,-3.46,-1.73,0,1.73,3.46,5.19 all the time, is there a way to define a macro or equivalent.

    \documentclass{standalone}

\usepackage{tikz}

\usepackage{pgfplots}
\pgfplotsset{width=5.5in,compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=middle,
xmin=-6, xmax=6,
ymin=-6,ymax=6,
xlabel = $x$,
ylabel = $y$]
coordinates { (0,0) (sqrt(3),1)} node[above right,pos=1] {$v_1$};
coordinates { (0,0) (0,2)} node[above right,pos=1] {$v_2$};

0.5 1
-0.5 1
-1 0
-0.5 -1
0.5 -1
1 0
0.5 1
};

\addplot[only marks, mark=o, samples at={-5.19,-3.46,-1.73,0,1.73,3.46,5.19}]{-0.55*x + 2};

\end{axis}
\end{tikzpicture}
\end{document}


• Sure, with \pgfplotsinvokeforeach ... – user121799 Mar 12 '19 at 3:05

You could use a loop. (Of course there are even simpler ways to create such lattices.)

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\pgfplotsset{width=5.5in,compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=middle,
xmin=-6, xmax=6,
ymin=-6,ymax=6,
xlabel = $x$,
ylabel = $y$]
coordinates { (0,0) (sqrt(3),1)} node[above right,pos=1] {$v_1$};
coordinates { (0,0) (0,2)} node[above right,pos=1] {$v_2$};

0.5 1
-0.5 1
-1 0
-0.5 -1
0.5 -1
1 0
0.5 1
};
\pgfplotsinvokeforeach{-6,-4,...,6}{