5

The following code

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

produces the picture:

enter image description here

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?

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

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)}},
]
\addplot[smooth,mark=*,blue]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
\addlegendentry{a}
\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)}},
]
\addplot[smooth,mark=square*,red]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487) (7,21.34288)};
\addlegendentry{b}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

5

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)}}]
\addlegendimage{empty legend}
\addlegendentry{Metrics}
\addplot+[smooth]
coordinates{(2,21794) (3,11876) (4,7336) (5,5108) (6,3882) (7,2990)};
\addlegendentry{a}
\addplot+[smooth]
coordinates{(2,7.065608) (3,9.884279) (4,12.97898) (5,15.89754) (6,18.82487) 
(7,21.34288)};
\addlegendentry{b}
\end{semilogyaxis}
\end{tikzpicture}
\end{document}

enter image description here

  • 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
  • @BambOo They are equivalent, see p. 41 of the pgfplots manual. – marmot Dec 11 '18 at 9:01

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.