当使用不同的 xscale 和 yscale 时,如何保持 TiKZ 图中标记的纵横比?

当使用不同的 xscale 和 yscale 时,如何保持 TiKZ 图中标记的纵横比?

我想使用不同的 X 轴和 Y 轴比例来缩放我的 TiKZ 图。我遇到的问题是绘图标记大小受比例影响并且不保持纵横比。如何保持绘图标记的纵横比?保持节点的纵横比没有问题。提前谢谢您。

示例图片

这是我的代码:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{plotmarks,positioning,shapes,arrows,backgrounds}

\begin{document}

\begin{tikzpicture}[xscale=0.080,yscale=0.160]
\draw[step=20cm,gray!20,very thin] (0,0) grid (100,80);

\tikzstyle{neuron}=[circle,fill=black,minimum size=5pt,inner sep=0pt]
\tikzstyle{data}=[diamond,fill=red,minimum size=8pt,inner sep=0pt]
\tikzstyle{edge}=[dashed,thick,color=black!50]
\node[neuron] (n0) at (20.77, 61.16) {}; \node[neuron] (n1) at (70.78, 31.07) {}; 
\node[data] (d0) at (42.77, 21.16) {}; \node[data] (d1) at (52.78, 11.07) {}; 
\draw[edge] (n0) -- (n1);
\draw plot[only marks,mark=x,mark size=60pt,mark options={color=red,scale=1.0}] coordinates{
(62.46,25.59) (39.97,33.29) (60.67,39.50)  
};
\draw plot[only marks,mark=*,mark size=60pt,mark options={color=black}] coordinates{
(59.56,62.57) (71.05,65.27) 
};

\draw[->] (0,0) -- coordinate (x axis mid) (100,0);
\draw[->] (0,0) -- coordinate (y axis mid) (0,80);
\foreach \x in {0,20,...,100}
\draw (\x cm,1pt) -- (\x cm,-3pt) node[anchor=north,font=\footnotesize] {$\x$};
\foreach \y in {0,20,...,80}
\draw (1pt,\y cm) -- (-3pt,\y cm) node[anchor=east,font=\footnotesize] {$\y$};
\end{tikzpicture}

\end{document}

答案1

您可以更改xy单位,而不是使用xscaleyscale。这样,只会缩放坐标,而不会缩放标记:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{plotmarks,positioning,shapes,arrows,backgrounds}

\begin{document}

\begin{tikzpicture}[x=0.080cm,y=0.160cm]
\draw[step=20,gray!20,very thin] (0,0) grid (100,80);

\tikzstyle{neuron}=[circle,fill=black,minimum size=5pt,inner sep=0pt]
\tikzstyle{data}=[diamond,fill=red,minimum size=8pt,inner sep=0pt]
\tikzstyle{edge}=[dashed,thick,color=black!50]
\node[neuron] (n0) at (20.77, 61.16) {}; \node[neuron] (n1) at (70.78, 31.07) {}; 
\node[data] (d0) at (42.77, 21.16) {}; \node[data] (d1) at (52.78, 11.07) {}; 
\draw[edge] (n0) -- (n1);
\draw plot[only marks,mark=x,mark size=5pt,mark options={color=red,scale=1.0}] coordinates{
(62.46,25.59) (39.97,33.29) (60.67,39.50)  
};
\draw plot[only marks,mark=*,mark size=5pt,mark options={color=black}] coordinates{
(59.56,62.57) (71.05,65.27) 
};

\draw[->] (0,0) -- coordinate (x axis mid) (100,0);
\draw[->] (0,0) -- coordinate (y axis mid) (0,80);
\foreach \x in {0,20,...,100}
\draw (\x,1pt) -- (\x,-3pt) node[anchor=north,font=\footnotesize] {$\x$};
\foreach \y in {0,20,...,80}
\draw (1pt,\y) -- (-3pt,\y) node[anchor=east,font=\footnotesize] {$\y$};
\end{tikzpicture}

\end{document}

请注意,我添加了cm“缩放”因子,但在网格和两个尾随\foreach循环中将其删除。

结果

答案2

Martin Scharrer 提出的解决方案效果很好。
但在我的代码中,最好坚持使用xscale=yscale=。因此,我设置了一个非常简单的宏 :

\newcommand{\pnt}[3][black]{%
\begin{scope}[shift={#2}];
\fill[color=#1,shift only] (0,0) circle(#3);
\end{scope}}

与以下项一起使用:

\pnt[red]{(3,4)}{1pt}

放置位置 (3,4) 处半径为 1pt 的红点。

相关内容