# How to keep aspect ratio of marks in TiKZ plot when using different xscale and yscale?

I would like to scale my TiKZ plots using different scale for X axis and Y axis. The problem I had is the plot markers size are affected by the scale and do not maintain the aspect ratio. How do I maintain aspect ratio of the plot markers? There is no problem with maintaining aspect ratio of nodes. Thank you in advance.

Here is my code:

\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}

-
Welcome to TeX.sx! As new user without image posting privileges simply include the image as normal (e.g. CTRL+G) and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again. –  Martin Scharrer Apr 9 '12 at 19:13
perhaps use pgfplots instead to do the plotting? Then you can add the scaling as an option to the axis environment. –  Roelof Spijker Apr 9 '12 at 19:14
Hi Roelof, previously I had problem adding node into axis environment. I could not figure the solution for weeks. Just now, I found that I just need to use the axis coordinate system, e.g., \node[neuron] (n0) at (axis cs:78.82, 133.17) {}; –  Denny Apr 9 '12 at 20:58

You can change the x and y units instead of using xscale and yscale. This way only coordinates are scaled, not the markers:

\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}


Note that I added cm to the "scaling" factors, but removed it for the grid and in the two trailing \foreach loops.

-
Thank you so much Martin! –  Denny Apr 9 '12 at 20:45

The solution proposed by Martin Scharrer works well.
But in my code it is highly desirable to stick with xscale= and yscale=. Therefore I have set up a very simple macro :

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


which is used with :

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


to place a circular red point of 1pt radius at location (3,4).

-