I want to display a dual axis as pictured in Fig.1. But When i write the file .Tex I obtained a different presentation. I want also to display all the numbers between 1-12 in the x-axis. Any help please?
\documentclass{article}
% UNITS
\usepackage{siunitx}
\sisetup{per=slash, load=abbr}
% GRAPHICS
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.3}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{
%scale only axis,
%scaled x ticks=base 10:1,
xmin=0, xmax=12
}
\begin{axis}[
axis y line*=left,
ymin=0, ymax=1,
xlabel=x-axis,
ylabel=y-axis 1,
]
\addplot[smooth,mark=x,red]
coordinates{
(12, 0.75)
(11, 0.749)
(10, 0.749)
(9, 0.748)
(8, 0.748)
(7, 0.746)
(6, 0.739)
(5, 0.733)
(4, 0.697)
(3, 0.674)
(2, 0.668)
}; \label{plot_one}
\addlegendentry{plot 1}
\end{axis}
\begin{axis}[
axis y line*=right,
axis x line=none,
ymin=0, ymax=1,
ylabel=y-axis 2
]
\addplot[smooth,mark=*,blue]
coordinates{
(12, 0.725)
(11, 0.726)
(10, 0.73)
(9, 0.732)
(8, 0.746)
(7,0.754)
(6, 0.832)
(5, 0.828)
(4, 0.912)
(3, 0.96)
(2, 0.992)
}; \addlegendentry{plot 3}
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
This is one possibility. Here
grid=both
is added, ymin/ymax are set to differnt values andy tick label styes
are added and set differently to meet the requirements.For legend in one row, use
legend columns=-1
.For two plots in one legend, use
\addlegendimage{/pgfplots/refstyle=plot_one} addlegendentry{y axis 1}
Code