下一个代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\begin{document}
\begin{tikzpicture} [yscale=2]
\draw [very thin, lightgray] (0,0) grid (4,4);
\draw [cyan] plot [only marks, mark=square*,mark size=2.5pt] coordinates {(1,1) (2,3) (2.5,2)};
\end{tikzpicture}
\end{document}
给出
如何避免标记失真?
答案1
这是一种样式scale plot marks
,如果设置为false
,将修补\pgfuseplotmark
命令以重置所有不影响位置的变换(包括缩放)。更改保持本地状态。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\makeatletter
\tikzset{
scale plot marks/.is choice,
scale plot marks/false/.code={
\def\pgfuseplotmark##1{\pgftransformresetnontranslations\csname pgf@plot@mark@##1\endcsname}
},
scale plot marks/true/.style={},
scale plot marks/.default=true
}
\makeatother
\begin{document}
\begin{tikzpicture} [yscale=2]
\node [align=center, anchor=north] at (2,4) {\verb|scale plot marks=true|\\(default)};
\draw [very thin, lightgray] (0,0) grid (4,4);
\draw [cyan] plot [only marks, mark=square*,mark size=2.5pt] coordinates {(1,1) (2,3) (2.5,2)};
\end{tikzpicture}
\begin{tikzpicture} [yscale=2]
\node [align=center, anchor=north] at (2,4) {\verb|scale plot marks=false|};
\draw [very thin, lightgray] (0,0) grid (4,4);
\draw [cyan] plot [only marks, mark=square*,mark size=2.5pt,scale plot marks=false] coordinates {(1,1) (2,3) (2.5,2)};
\end{tikzpicture}
\end{document}