\usepackage{pgfplots} %引用包
\pgfplotsset{compat=newest}
% compat 指定 pgfplots 的版本, 这里用最新。也可以直接用版本号,如1.13
%如果不指定新版本, y与z可能会重合。
\begin{figure}[!h] %插入图片
\centering %图片居中\begin{tikzpicture} %tikz图片
\begin{axis}[
axis y line*=left,%y轴居左
xlabel=x, %横坐标名
ylabel=y, %纵坐标名
tick align=outside, %刻度在外显式
]%第一条线,mark是折线标示形状
\addplot[smooth,mark=*,blue] plot coordinates {
(20,1)
(40,2)
(60,3)
(80,4)
(100,5)
};%图例里名字
\label{plot_one}%第二条线,mark是折线标示形状
\addplot[smooth,mark=triangle,cyan] plot coordinates {
(20,1.3)
(40,2.3)
(60,3.3)
(80,4.3)
(100,5.3)
};
\label{plot_two}\end{axis}
%第三条线, 用另一个y轴
\begin{axis}[
axis y line*=right,%y轴居右
axis x line=none,%不画x, 避免线重画
xlabel=x, %横坐标名
ylabel=z, %纵坐标名
tick align=outside, %刻度在外显式
legend style={at={(0.5,-0.3)},anchor=north} %图例在图下方显示
]%第一条线,mark是折线标示形状
\addplot[smooth,mark=o,blue] plot coordinates {
(20,6)
(40,8)
(60,9)
(80,0)
(100,5)
};%添加图例
\addlegendimage{/pgfplots/refstyle=plot_one}\addlegendentry{case 1}
\addlegendimage{/pgfplots/refstyle=plot_two}\addlegendentry{case 2}\addlegendentry{case 3}
\end{axis}
\end{tikzpicture}
\caption{figure name}
\label{fig:name}
\end{figure}

LaTex画双y轴折线图_折线