我有一个阴谋,分数我想要自动计算分数(即,给定 x 坐标,我希望使用方程自动添加标记)。
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width = 7cm, compat = newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [no marks] {x^2};
% Need to automate the following y-coordinate calculations
\addplot [only marks] coordinates {(-2, {(-2)^2}) (0, {0^2}) (3, {3^2})};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
使用samples at = {...}
密钥:
\documentclass[border=3.141592mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width = 7cm, compat = 1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [no marks] {x^2};
\addplot [only marks, samples at={-2,0,3}] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}