# How to specify Latex graph scale

I have had this issue for long and no solution yet despite my numerous research. I wish to know if it is possible to specify the axis scale in Latex graph as we normally do in Maths.

For Example I wish to specify "2 cm for 1 unit on the x-axis and 4 cm for 1 unit on the y-axis". I have the current code as shown below

    \begin{tikzpicture}[scale=2,dot/.style 2 args={circle,inner
sep=1pt,fill,label={#2:#1},name=#1}, extended line/.style={shorten >=-
#1,shorten <=-#1,draw=Cerulean}, extended line/.default=1cm]
\begin{axis}[
width=20cm,
height=20cm,
xmax=10,xmin=-10,
ymin=-10,ymax=10,
xlabel=$x$,ylabel=$y$,
xtick={-10,...,10},
ytick={-10,...,10},
%domain=-7.5:10.5,
axis lines=center, % default is to make a box around the axis
x label style={at={(axis description cs:1,0.15)},anchor=west},
y label style={at={(axis description cs:0.5,1.05)},anchor=north},
width=10cm,
height=11cm,
grid=both,
grid style={line width=.3pt, draw=gray!50},
major grid style={line width=.5pt,draw=gray!90},
minor tick num=4,
enlargelimits={abs=0.5}
]
\end{axis}
\end{tikzpicture}


As you can notice, when compiled the axis numbering are so close to each other. I want to skip some. Thank you

• Welcome! Since the question is tagged tikz-pgf the answer is as simple as adding x=2cm,y=4cm to the options of the tikzpicture (or axis).
– user194703
Commented Apr 27, 2020 at 20:04
• @Schrödinger'scat I tried that and it did not provide the desired result. Kindly check my edits above. Regards Commented Apr 28, 2020 at 7:06
• You are setting the ticks explicitly with xtick={-10,...,10}, If you want less, use e.g. xtick={-10,-8,...,10}, (and the same for y), or do not specify the ticks explicitly and use xtick distance=2 or so.
– user194703
Commented Apr 28, 2020 at 7:17
• Welcome to TeX - LaTeX! Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Commented Apr 28, 2020 at 7:17

The original question can be answered by set e.g. x=2cm. However, the last part of the question is a bit different. If you want to keep xmax=10,xmin=-10, and set the width (you specify it twice, once width=20cm and once width=10cm, the last key "wins"), then one can infer the unit length on the plot from this data. Your last question, however, sounds as the request to have the ticks less crowded. They are crowded because you set

  xtick={-10,...,10},


To have them less crowded you can either set

  xtick={-10,-8,...,10},


say, or do not specify them and set xtick distance=2, say. The analogous statements apply to y (and z in 3d plots).

\documentclass[dvipsnames,tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}%<- use a smaller version if you have an older installation

\begin{document}
\begin{tikzpicture}[scale=2,dot/.style 2 args={circle,inner
sep=1pt,fill,label={#2:#1},name=#1}, extended line/.style={shorten >=-
#1,shorten <=-#1,draw=Cerulean}, extended line/.default=1cm]
\begin{axis}[
%width=20cm,
%height=20cm,
xmax=10,xmin=-10,
ymin=-10,ymax=10,
xlabel=$x$,ylabel=$y$,
%xtick={-10,-8,...,10},
%ytick={-10,-8,...,10},
%domain=-7.5:10.5,
axis lines=center, % default is to make a box around the axis
x label style={at={(axis description cs:1,0.15)},anchor=west},
y label style={at={(axis description cs:0.5,1.05)},anchor=north},
width=10cm,
height=11cm,
grid=both,
grid style={line width=.3pt, draw=gray!50},
major grid style={line width=.5pt,draw=gray!90},
minor tick num=4,
enlargelimits={abs=0.5},
xtick distance=2,ytick distance=2,
]
\end{axis}
\end{tikzpicture}
\end{document}


I am posting this also to inform you about the way we exchange codes here. As stated by Alessandro Cuttin, you are supposed to post a complete example. The above code is such an example.

• Thank you @Schrodinger's Cat This is a workable solution and the correction about code posting is well noted. Is it however possible to commit part of the scale values? For example, in the code you sent, in the y-axis, can I say omit 2, 6, and 10? and also in the negative axis? That is, I wash to jump one square write a number (4), jump one square, write a number (8), and so on and I want to do this for both axes. Is it possible in Latex? Thank you. Commented Apr 28, 2020 at 7:53
• @FemenchaAzomboFabrice Please have a look at the pgfplots manual, more specifically section 4.15 Tick options to see how to customize axis settings Commented Apr 28, 2020 at 10:23