# Draw different curves with different scales on TikZ

The following code

\begin{tikzpicture}[scale=0.9]
\begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.95)}}]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487)
(7,21.34288)};
\end{axis}
\end{tikzpicture}


produces the picture:

As we can see, the curves are very different in magnitude and so the trend of red curve seems to be constant. How can I draw these two curves with different scales?

• This is what logarithmic plots are for. – marmot Dec 11 '18 at 8:39

This is not a complete answer. The following code just demonstrates how you can plot graphs in two different axes.

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.9]
\pgfplotsset{every axis legend/.style={
anchor= west,
draw=none,}
}

\begin{axis}[name=plot1, xlabel=clusters,colormap/blackwhite,
y tick label style={blue},
legend style= {at={(0.78,0.55)}},
]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
\end{axis}

\begin{axis}[name=plot2, axis y line*=right, axis x line=none,
xlabel=clusters ,colormap/blackwhite,
y tick label style={red},
legend style= {at={(0.78,0.45)}},
]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487) (7,21.34288)};
\end{axis}
\end{tikzpicture}
\end{document}


You could use a semilogyaxis.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale=0.9]
\begin{semilogyaxis}[name=plot1, xlabel=clusters,colormap/blackwhite,legend style=
{at={(0.95,0.6)}}]

• Is there a recommendation to use s semilogaxis instead of axis with ymode=log option ? Or are these two syntaxes equivalent ? – BambOo Dec 11 '18 at 9:00